Skip to content

Commit

Permalink
Packages App
Browse files Browse the repository at this point in the history
  • Loading branch information
zarakkhan209 committed Jan 11, 2024
1 parent 8892654 commit 58d11cc
Show file tree
Hide file tree
Showing 9 changed files with 1,233 additions and 18 deletions.
9 changes: 5 additions & 4 deletions baseTemplate/templates/baseTemplate/newBase.html
Original file line number Diff line number Diff line change
Expand Up @@ -476,22 +476,22 @@
</div>
<ul id="dropdown-example-4" class="hidden py-2 space-y-2">
<li>
<a href="#"
<a href="{% url 'createPackageV2' %}"
class="flex items-center w-full text-base font-normal text-white transition duration-75 rounded-lg group hover:bg-cyan-400 dark:text-white dark:hover:bg-gray-700 pl-11">
Create Package</a>
</li>
<li>
<a href="#"
<a href="{% url 'listPackagesV2' %}"
class="flex items-center w-full text-base font-normal text-white transition duration-75 rounded-lg group hover:bg-cyan-400 dark:text-white dark:hover:bg-gray-700 pl-11">
List Packages</a>
</li>
<li>
<a href="#"
<a href="{% url 'deletePackageV2' %}"
class="flex items-center w-full text-base font-normal text-white transition duration-75 rounded-lg group hover:bg-cyan-400 dark:text-white dark:hover:bg-gray-700 pl-11">
Delete Package</a>
</li>
<li>
<a href="#"
<a href="{% url 'modifyPackageV2' %}"
class="flex items-center w-full text-base font-normal text-white transition duration-75 rounded-lg group hover:bg-cyan-400 dark:text-white dark:hover:bg-gray-700 pl-11">
Modify Package</a>
</li>
Expand Down Expand Up @@ -1669,6 +1669,7 @@
<script src="{% static 'baseTemplate/newBase.js' %}"></script>
<script src="{% static 'websiteFunctions/websiteFunctionsV2.js' %}"></script>
<script src="{% static 'userManagment/userManagementV2.js' %}"></script>
<script src="{% static 'packages/packagesV2.js' %}"></script>
</body>

</html>
52 changes: 42 additions & 10 deletions packages/packagesManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import django
from plogical.httpProc import httpProc

sys.path.append('/usr/local/CyberCP')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
django.setup()
Expand All @@ -14,9 +15,10 @@
from .models import Package
from plogical.acl import ACLManager


class PackagesManager:
def __init__(self, request = None):
self.request = request
def __init__(self, request=None):
self.request = request

def packagesHome(self):
proc = httpProc(self.request, 'packages/index.html',
Expand All @@ -30,6 +32,13 @@ def createPacakge(self):
{"adminNamePackage": admin.userName}, 'createPackage')
return proc.render()

def createPacakgeV2(self):
userID = self.request.session['userID']
admin = Administrator.objects.get(pk=userID)
proc = httpProc(self.request, 'packages/createPackageV2.html',
{"adminNamePackage": admin.userName}, 'createPackage')
return proc.render()

def deletePacakge(self):
userID = self.request.session['userID']
currentACL = ACLManager.loadedACL(userID)
Expand All @@ -38,6 +47,14 @@ def deletePacakge(self):
{"packageList": packageList}, 'deletePackage')
return proc.render()

def deletePacakgeV2(self):
userID = self.request.session['userID']
currentACL = ACLManager.loadedACL(userID)
packageList = ACLManager.loadPackages(userID, currentACL)
proc = httpProc(self.request, 'packages/deletePackageV2.html',
{"packageList": packageList}, 'deletePackage')
return proc.render()

def submitPackage(self):
try:

Expand Down Expand Up @@ -71,7 +88,6 @@ def submitPackage(self):
except:
enforceDiskLimits = 0


if packageSpace < 0 or packageBandwidth < 0 or packageDatabases < 0 or ftpAccounts < 0 or emails < 0 or allowedDomains < 0:
data_ret = {'saveStatus': 0, 'error_message': "All values should be positive or 0."}
json_data = json.dumps(data_ret)
Expand All @@ -84,7 +100,8 @@ def submitPackage(self):

package = Package(admin=admin, packageName=packageName, diskSpace=packageSpace,
bandwidth=packageBandwidth, ftpAccounts=ftpAccounts, dataBases=packageDatabases,
emailAccounts=emails, allowedDomains=allowedDomains, allowFullDomain=allowFullDomain, enforceDiskLimits=enforceDiskLimits)
emailAccounts=emails, allowedDomains=allowedDomains, allowFullDomain=allowFullDomain,
enforceDiskLimits=enforceDiskLimits)

package.save()

Expand Down Expand Up @@ -135,6 +152,14 @@ def modifyPackage(self):
{"packList": packageList}, 'modifyPackage')
return proc.render()

def modifyPackageV2(self):
userID = self.request.session['userID']
currentACL = ACLManager.loadedACL(userID)
packageList = ACLManager.loadPackages(userID, currentACL)
proc = httpProc(self.request, 'packages/modifyPackageV2.html',
{"packList": packageList}, 'modifyPackage')
return proc.render()

def submitModify(self):
try:
userID = self.request.session['userID']
Expand All @@ -159,10 +184,11 @@ def submitModify(self):
dataBases = modifyPack.dataBases
emails = modifyPack.emailAccounts


data_ret = {'emails': emails, 'modifyStatus': 1, 'error_message': "None",
"diskSpace": diskSpace, "bandwidth": bandwidth, "ftpAccounts": ftpAccounts,
"dataBases": dataBases, "allowedDomains": modifyPack.allowedDomains, 'allowFullDomain': modifyPack.allowFullDomain, 'enforceDiskLimits': modifyPack.enforceDiskLimits}
"dataBases": dataBases, "allowedDomains": modifyPack.allowedDomains,
'allowFullDomain': modifyPack.allowFullDomain,
'enforceDiskLimits': modifyPack.enforceDiskLimits}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)

Expand All @@ -187,7 +213,7 @@ def saveChanges(self):

if data['diskSpace'] < 0 or data['bandwidth'] < 0 or data['ftpAccounts'] < 0 or data[
'dataBases'] < 0 or \
data['emails'] < 0 or data['allowedDomains'] < 0:
data['emails'] < 0 or data['allowedDomains'] < 0:
data_ret = {'saveStatus': 0, 'error_message': "All values should be positive or 0."}
json_data = json.dumps(data_ret)
return HttpResponse(json_data)
Expand Down Expand Up @@ -238,7 +264,6 @@ def saveChanges(self):
json_data = json.dumps(data_ret)
return HttpResponse(json_data)


def listPackages(self):
userID = self.request.session['userID']
currentACL = ACLManager.loadedACL(userID)
Expand All @@ -247,7 +272,15 @@ def listPackages(self):
{"packList": packageList}, 'listPackages')
return proc.render()

def listPackagesAPI(self,data=None):
def listPackagesV2(self):
userID = self.request.session['userID']
currentACL = ACLManager.loadedACL(userID)
packageList = ACLManager.loadPackages(userID, currentACL)
proc = httpProc(self.request, 'packages/listPackagesV2.html',
{"packList": packageList}, 'listPackages')
return proc.render()

def listPackagesAPI(self, data=None):
"""
List of packages for API
:param data:
Expand All @@ -273,7 +306,6 @@ def fetchPackagesTable(self):
if ACLManager.currentContextPermission(currentACL, 'listPackages') == 0:
return ACLManager.loadErrorJson()


packages = ACLManager.loadPackageObjects(userID, currentACL)

json_data = "["
Expand Down
Loading

0 comments on commit 58d11cc

Please sign in to comment.