|
@@ -2,7 +2,7 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
from itertools import chain
|
|
|
from django.views.generic.base import View
|
|
|
-import django.dispatch, traceback,simplejson as json
|
|
|
+import django.dispatch, traceback, simplejson as json
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from Model.models import Permissions, Role, Device_User
|
|
@@ -11,7 +11,6 @@ from Service.ModelService import ModelService
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
|
|
|
-
|
|
|
# 创建信号
|
|
|
roles_done = django.dispatch.Signal(providing_args=[])
|
|
|
perms_done = django.dispatch.Signal(providing_args=[])
|
|
@@ -31,6 +30,7 @@ class Roles(object):
|
|
|
rid.append(role.rid)
|
|
|
except Exception as e:
|
|
|
pass
|
|
|
+
|
|
|
def __init__(self):
|
|
|
'''
|
|
|
信号监听, 注册信号
|
|
@@ -81,8 +81,8 @@ class Roles(object):
|
|
|
listSets.append(data)
|
|
|
return listSets
|
|
|
|
|
|
- def queryAllRoles(self, rolenames=None, exclude=None,response=ResponseObject()):
|
|
|
- roles =[]
|
|
|
+ def queryAllRoles(self, rolenames=None, exclude=None, response=ResponseObject()):
|
|
|
+ roles = []
|
|
|
for role in chain(Roles.roles):
|
|
|
if rolenames and role.roleName not in rolenames:
|
|
|
continue
|
|
@@ -90,23 +90,23 @@ class Roles(object):
|
|
|
continue
|
|
|
roles.append(role)
|
|
|
if len(roles) > 0:
|
|
|
- resultDict=CommonService.qs_to_dict(roles)
|
|
|
+ resultDict = CommonService.qs_to_dict(roles)
|
|
|
for k, v in enumerate(resultDict["datas"]):
|
|
|
if len(v['fields']['permission']) > 0:
|
|
|
- resultDict["datas"][k]['fields']['permissionJson']={}
|
|
|
+ resultDict["datas"][k]['fields']['permissionJson'] = {}
|
|
|
for pid in v['fields']['permission']:
|
|
|
- permission_query_set= Permissions.objects.get(id=pid)
|
|
|
- resultDict["datas"][k]['fields']['permissionJson'][pid]=permission_query_set.permName
|
|
|
- return response.json(0,resultDict)
|
|
|
-
|
|
|
+ permission_query_set = Permissions.objects.get(id=pid)
|
|
|
+ resultDict["datas"][k]['fields']['permissionJson'][pid] = permission_query_set.permName
|
|
|
+ return response.json(0, resultDict)
|
|
|
+
|
|
|
else:
|
|
|
return response.json(0, {})
|
|
|
|
|
|
- def addRoles(self, content=None,response=ResponseObject()):
|
|
|
+ def addRoles(self, content=None, response=ResponseObject()):
|
|
|
try:
|
|
|
roleContent = json.loads(content)
|
|
|
except Exception as e:
|
|
|
- return response.json(803,repr(e))
|
|
|
+ return response.json(803, repr(e))
|
|
|
else:
|
|
|
rid = roleContent.get('rid', None)
|
|
|
if rid == None:
|
|
@@ -122,18 +122,18 @@ class Roles(object):
|
|
|
if len(permission_list) > 0:
|
|
|
role.permission.add(*permission_list)
|
|
|
except Exception as e:
|
|
|
- return response.json(808,repr(e))
|
|
|
+ return response.json(808, repr(e))
|
|
|
else:
|
|
|
self.startSignal()
|
|
|
return response.json(0)
|
|
|
|
|
|
- def delRoles(self, rid=None, rolename=None,response=ResponseObject()):
|
|
|
+ def delRoles(self, rid=None, rolename=None, response=ResponseObject()):
|
|
|
if rid != None:
|
|
|
if rid not in Roles.rid:
|
|
|
return response.json(190)
|
|
|
|
|
|
try:
|
|
|
- roletuple = Role.objects.filter(rid = rid).delete()
|
|
|
+ roletuple = Role.objects.filter(rid=rid).delete()
|
|
|
except Exception as e:
|
|
|
return response.json(192, repr(e))
|
|
|
else:
|
|
@@ -141,12 +141,12 @@ class Roles(object):
|
|
|
self.startSignal()
|
|
|
return self.queryAllRoles(response=response)
|
|
|
else:
|
|
|
- return response.json(193,{'error_msg':roletuple})
|
|
|
+ return response.json(193, {'error_msg': roletuple})
|
|
|
elif rolename != None:
|
|
|
if rid not in Roles.rolename:
|
|
|
return response.json(191)
|
|
|
try:
|
|
|
- roletuple = Role.objects.filter(roleName = rolename).delete()
|
|
|
+ roletuple = Role.objects.filter(roleName=rolename).delete()
|
|
|
except Exception as e:
|
|
|
return response.json(192)
|
|
|
else:
|
|
@@ -156,7 +156,7 @@ class Roles(object):
|
|
|
else:
|
|
|
return response.json(193)
|
|
|
|
|
|
- def modifyRoles(self, rid=None, content=None,response=ResponseObject()):
|
|
|
+ def modifyRoles(self, rid=None, content=None, response=ResponseObject()):
|
|
|
if rid not in Roles.rid:
|
|
|
return response.json(190)
|
|
|
try:
|
|
@@ -169,7 +169,7 @@ class Roles(object):
|
|
|
try:
|
|
|
permission_list = roleContent['permission']
|
|
|
roleContent.pop('permission')
|
|
|
- roleCount = Role.objects.filter(rid = rid).update(**roleContent)
|
|
|
+ roleCount = Role.objects.filter(rid=rid).update(**roleContent)
|
|
|
if roleCount:
|
|
|
if len(permission_list) > 0:
|
|
|
Role.objects.get(rid=rid).permission.set(permission_list)
|
|
@@ -185,6 +185,7 @@ class Roles(object):
|
|
|
else:
|
|
|
return response.json(195)
|
|
|
|
|
|
+
|
|
|
class Permission(object):
|
|
|
try:
|
|
|
id = []
|
|
@@ -195,6 +196,7 @@ class Permission(object):
|
|
|
permname.append(perm.permName)
|
|
|
except Exception as e:
|
|
|
pass
|
|
|
+
|
|
|
def __init__(self):
|
|
|
perms_done.connect(self.callback)
|
|
|
|
|
@@ -212,56 +214,52 @@ class Permission(object):
|
|
|
def startSignal(self):
|
|
|
perms_done.send(sender=self.__class__)
|
|
|
|
|
|
- def queryAllPerms(self, perms=None, exclude=None,response=ResponseObject()):
|
|
|
- opts =[]
|
|
|
+ def queryAllPerms(self, perms=None, exclude=None, response=ResponseObject()):
|
|
|
+ opts = []
|
|
|
for perm in chain(Permission.permname):
|
|
|
if perms and perm not in perms:
|
|
|
continue
|
|
|
if exclude and perm in exclude:
|
|
|
continue
|
|
|
opts.append(perm)
|
|
|
- return response.json(0,{'perms':opts})
|
|
|
+ return response.json(0, {'perms': opts})
|
|
|
|
|
|
- def delPerms(self, id=None, permName=None,response=ResponseObject()):
|
|
|
+ def delPerms(self, id=None, permName=None, response=ResponseObject()):
|
|
|
+ if id != None:
|
|
|
+ perm = Permissions.objects.filter(id=id)
|
|
|
+ elif permName != None:
|
|
|
+ perm = Permissions.objects.filter(permName=permName)
|
|
|
+ else:
|
|
|
+ return response.json(444, 'id,perm')
|
|
|
+ if not perm:
|
|
|
+ return response.json(817)
|
|
|
try:
|
|
|
- if id != None:
|
|
|
- perm = Permissions.objects.filter(id = id)
|
|
|
- elif permName != None:
|
|
|
- perm = Permissions.objects.filter(permName = permName)
|
|
|
- else:
|
|
|
- return response.json(800)
|
|
|
+ perm.delete()
|
|
|
except Exception as e:
|
|
|
- return response.json(500, repr(e))
|
|
|
+ return response.json(818, repr(e))
|
|
|
else:
|
|
|
- if not perm:
|
|
|
- return response.json(817)
|
|
|
- try:
|
|
|
- perm.delete()
|
|
|
- except Exception as e:
|
|
|
- return response.json(818, repr(e))
|
|
|
- else:
|
|
|
- self.startSignal()
|
|
|
- qs =Permissions.objects.all()
|
|
|
- res = CommonService.qs_to_dict(qs)
|
|
|
- return response.json(0,res)
|
|
|
+ self.startSignal()
|
|
|
+ qs = Permissions.objects.all()
|
|
|
+ res = CommonService.qs_to_dict(qs)
|
|
|
+ return response.json(0, res)
|
|
|
|
|
|
@staticmethod
|
|
|
def getAllPermission(response=ResponseObject()):
|
|
|
- send_dict=CommonService.qs_to_dict(Permissions.objects.all())
|
|
|
+ send_dict = CommonService.qs_to_dict(Permissions.objects.all())
|
|
|
return response.json(0, send_dict)
|
|
|
|
|
|
|
|
|
class permManager(object):
|
|
|
|
|
|
def queryMoreRole(self, rid=None):
|
|
|
- role = Role.objects.filter(rid = rid)
|
|
|
+ role = Role.objects.filter(rid=rid)
|
|
|
if not role:
|
|
|
roleDict = {'rid': role[0].rid, 'error_msg': u'The rid does not exist!'}
|
|
|
return roleDict
|
|
|
- roleDict = {'rid' : role[0].rid, 'perms': role[0].get_all_permission()}
|
|
|
+ roleDict = {'rid': role[0].rid, 'perms': role[0].get_all_permission()}
|
|
|
return roleDict
|
|
|
|
|
|
- def queryAllRole(self,response=ResponseObject()):
|
|
|
+ def queryAllRole(self, response=ResponseObject()):
|
|
|
qs = Role.objects.all()
|
|
|
res = CommonService.qs_to_dict(qs)
|
|
|
return response.json(0, res)
|
|
@@ -285,34 +283,29 @@ class queryRoleView(View):
|
|
|
|
|
|
def ValidationError(self, token):
|
|
|
response = ResponseObject()
|
|
|
- if token is not None:
|
|
|
- tko = TokenObject(token)
|
|
|
- tko.valid()
|
|
|
- response.lang = tko.lang
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- if userID:
|
|
|
- return self.queryUserRole(userID,response)
|
|
|
- else:
|
|
|
- return response.json(309)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if userID:
|
|
|
+ return self.queryUserRole(userID, response)
|
|
|
else:
|
|
|
- return response.json(800)
|
|
|
+ return response.json(309)
|
|
|
|
|
|
- def queryUserRole(self, userID,response):
|
|
|
- eUser = Device_User.objects.filter(userID = userID)
|
|
|
+ def queryUserRole(self, userID, response):
|
|
|
+ eUser = Device_User.objects.filter(userID=userID)
|
|
|
if not eUser:
|
|
|
return response.json(102)
|
|
|
if 100 in eUser[0].get_role_id():
|
|
|
role = Roles()
|
|
|
return role.queryAllRoles(response=response)
|
|
|
own_permission = ModelService.check_permission(userID=userID, permID=30)
|
|
|
- if own_permission is True:
|
|
|
- role = Roles()
|
|
|
- return role.queryAllRoles(response=response)
|
|
|
- else:
|
|
|
+ if own_permission is not True:
|
|
|
return response.json(404)
|
|
|
+ role = Roles()
|
|
|
+ return role.queryAllRoles(response=response)
|
|
|
+
|
|
|
|
|
|
class addNewRoleView(View):
|
|
|
@method_decorator(csrf_exempt)
|
|
@@ -321,58 +314,45 @@ class addNewRoleView(View):
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'gb2312'
|
|
|
- token = request.GET.get('token', None)
|
|
|
- content = request.GET.get('content', None)
|
|
|
-
|
|
|
- return self.ValidationError(token, content)
|
|
|
+ request_dict = request.GET
|
|
|
+ return self.ValidationError(request_dict)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
- token = request.POST.get('token', None)
|
|
|
- content = request.POST.get('content', None)
|
|
|
-
|
|
|
- return self.ValidationError(token, content)
|
|
|
+ request_dict = request.POST
|
|
|
+ return self.ValidationError(request_dict)
|
|
|
|
|
|
- def ValidationError(self, token, content):
|
|
|
+ def ValidationError(self, request_dict):
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ content = request_dict.get('content', None)
|
|
|
response = ResponseObject()
|
|
|
- if token != None and content != None:
|
|
|
- tko = TokenObject(token)
|
|
|
- tko.valid()
|
|
|
- response.lang = tko.lang
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- if userID:
|
|
|
-
|
|
|
- return self.AddNewUserRole(userID, content,response)
|
|
|
- else:
|
|
|
- return response.json(309)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
-
|
|
|
- else:
|
|
|
- return response.json(800)
|
|
|
-
|
|
|
- def AddNewUserRole(self, userID, content,response):
|
|
|
- try:
|
|
|
- User = Device_User.objects.filter(userID = userID)
|
|
|
- except Exception as e:
|
|
|
- return response.json(500,repr(e))
|
|
|
- else:
|
|
|
- rids = User[0].get_role_id()
|
|
|
- if rids == None:
|
|
|
- return response.json(606)
|
|
|
- Aperms = False
|
|
|
- for rid in rids:
|
|
|
- if rid < 10:
|
|
|
- continue
|
|
|
- else:
|
|
|
- Aperms = True
|
|
|
-
|
|
|
- if Aperms:
|
|
|
- role = Roles()
|
|
|
- return role.addRoles(content=content,response=response)
|
|
|
+ if not content:
|
|
|
+ return response.json(444, 'content')
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if not userID:
|
|
|
+ return response.json(309)
|
|
|
+ return self.AddNewUserRole(userID, content, response)
|
|
|
+
|
|
|
+ def AddNewUserRole(self, userID, content, response):
|
|
|
+ User = Device_User.objects.filter(userID=userID)
|
|
|
+
|
|
|
+ rids = User[0].get_role_id()
|
|
|
+ if rids == None:
|
|
|
+ return response.json(606)
|
|
|
+ Aperms = False
|
|
|
+ for rid in rids:
|
|
|
+ if rid < 10:
|
|
|
+ continue
|
|
|
else:
|
|
|
- return response.json(611)
|
|
|
+ Aperms = True
|
|
|
+ if not Aperms:
|
|
|
+ return response.json(404)
|
|
|
+ role = Roles()
|
|
|
+ return role.addRoles(content=content, response=response)
|
|
|
|
|
|
|
|
|
class delRoleView(View):
|
|
@@ -382,42 +362,35 @@ class delRoleView(View):
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'gb2312'
|
|
|
- token = request.GET.get('token', None)
|
|
|
- rid = request.GET.get('rid', None)
|
|
|
-
|
|
|
- return self.ValidationError(token, rid)
|
|
|
+ request_dict = request.GET
|
|
|
+ return self.ValidationError(request_dict)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
- token = request.POST.get('token', None)
|
|
|
- rid = request.POST.get('rid', None)
|
|
|
-
|
|
|
- return self.ValidationError(token, rid)
|
|
|
+ request_dict = request.POST
|
|
|
+ return self.ValidationError(request_dict)
|
|
|
|
|
|
- def ValidationError(self, token, rid):
|
|
|
+ def ValidationError(self, request_dict):
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ rid = request_dict.get('rid', None)
|
|
|
response = ResponseObject()
|
|
|
- if token != None and rid != None:
|
|
|
- tko = TokenObject(token)
|
|
|
- tko.valid()
|
|
|
- response.lang = tko.lang
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- if userID:
|
|
|
- return self.delRole(userID, int(rid),response)
|
|
|
- else:
|
|
|
- return response.json(309)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
- else:
|
|
|
- return response.json(444,'token,rid')
|
|
|
-
|
|
|
- def delRole(self, userID, rid,response):
|
|
|
+ if not rid:
|
|
|
+ return response.json(444, 'rid')
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if not userID:
|
|
|
+ return response.json(104)
|
|
|
+ return self.delRole(userID, int(rid), response)
|
|
|
+
|
|
|
+ def delRole(self, userID, rid, response):
|
|
|
own_permission = ModelService.check_permission(userID=userID, permID=10)
|
|
|
- if own_permission is True:
|
|
|
- role = Roles()
|
|
|
- return role.delRoles(rid=rid,response=response)
|
|
|
- else:
|
|
|
+ if own_permission is not True:
|
|
|
return response.json(404)
|
|
|
+ role = Roles()
|
|
|
+ return role.delRoles(rid=rid, response=response)
|
|
|
|
|
|
|
|
|
class modifyRoleView(View):
|
|
@@ -426,56 +399,46 @@ class modifyRoleView(View):
|
|
|
return super(modifyRoleView, self).dispatch(*args, **kwargs)
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
- request.encoding = 'gb2312'
|
|
|
- token = request.GET.get('token', None)
|
|
|
- rid = request.GET.get('rid', None)
|
|
|
- content = request.GET.get('content', None)
|
|
|
- return self.ValidationError(token, rid, content)
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ request_dict = request.GET
|
|
|
+ return self.ValidationError(request_dict)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
- token = request.POST.get('token', None)
|
|
|
- rid = request.POST.get('rid', None)
|
|
|
- content = request.POST.get('content', None)
|
|
|
- return self.ValidationError(token, rid, content)
|
|
|
+ request_dict = request.POST
|
|
|
+ return self.ValidationError(request_dict)
|
|
|
|
|
|
- def ValidationError(self, token, rid, content):
|
|
|
+ def ValidationError(self, request_dict):
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ rid = request_dict.get('rid', None)
|
|
|
+ content = request_dict.get('content', None)
|
|
|
response = ResponseObject()
|
|
|
- if token != None and content != None and rid != None:
|
|
|
- tko = TokenObject(token)
|
|
|
- tko.valid()
|
|
|
- response.lang = tko.lang
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- if userID:
|
|
|
- return self.modifyRole(userID, int(rid), content,response)
|
|
|
- else:
|
|
|
- return response.json(309)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
- else:
|
|
|
- return response.json(444,'token,content,rid')
|
|
|
-
|
|
|
- def modifyRole(self, userID, rid, content,response):
|
|
|
- try:
|
|
|
- User = Device_User.objects.filter(userID = userID)
|
|
|
- except Exception as e:
|
|
|
- return response.json(500, repr(e))
|
|
|
- else:
|
|
|
- rids = User[0].get_role_id()
|
|
|
- if rids == None:
|
|
|
- return response.json(606)
|
|
|
- Aperms = False
|
|
|
- for rrid in rids:
|
|
|
- if rrid < 10:
|
|
|
- continue
|
|
|
- else:
|
|
|
- Aperms = True
|
|
|
- if Aperms:
|
|
|
- role = Roles()
|
|
|
- return role.modifyRoles(rid=rid, content=content,response=response)
|
|
|
+ if not content or not rid:
|
|
|
+ return response.json(444, 'rid,content')
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if not userID:
|
|
|
+ return response.json(104)
|
|
|
+ return self.modifyRole(userID, int(rid), content, response)
|
|
|
+
|
|
|
+ def modifyRole(self, userID, rid, content, response):
|
|
|
+ User = Device_User.objects.filter(userID=userID)
|
|
|
+ rids = User[0].get_role_id()
|
|
|
+ if rids == None:
|
|
|
+ return response.json(606)
|
|
|
+ Aperms = False
|
|
|
+ for rrid in rids:
|
|
|
+ if rrid < 10:
|
|
|
+ continue
|
|
|
else:
|
|
|
- return response.json(611)
|
|
|
+ Aperms = True
|
|
|
+ if not Aperms:
|
|
|
+ return response.json(404)
|
|
|
+ role = Roles()
|
|
|
+ return role.modifyRoles(rid=rid, content=content, response=response)
|
|
|
|
|
|
|
|
|
# 权限View
|
|
@@ -497,41 +460,32 @@ class addNewPermsView(View):
|
|
|
def ValidationError(self, request_dict):
|
|
|
response = ResponseObject()
|
|
|
token = request_dict.get('token', None)
|
|
|
- type = request_dict.get('type', None)
|
|
|
- if token != None:
|
|
|
- tko = TokenObject(token)
|
|
|
- tko.valid()
|
|
|
- response.lang = tko.lang
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- if userID:
|
|
|
- if type == 'PC':
|
|
|
- return self.addNewPermission(userID=userID, request_dict=request_dict,response=response)
|
|
|
- else:
|
|
|
- return response.json(309)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if not userID:
|
|
|
+ return response.json(104)
|
|
|
+ return self.addNewPermission(userID, request_dict, response)
|
|
|
+
|
|
|
+ def addNewPermission(self, userID, request_dict, response):
|
|
|
+ own_perm = ModelService.check_permission(userID, 40)
|
|
|
+ if own_perm is not True:
|
|
|
+ return response.json(404)
|
|
|
else:
|
|
|
- return response.json(800)
|
|
|
-
|
|
|
- def addNewPermission(self, userID, request_dict,response):
|
|
|
- user_valid = Device_User.objects.filter(userID=userID).order_by('-data_joined')
|
|
|
- if user_valid:# 判断是否为超级管理员
|
|
|
- own_perm = ModelService.check_permission(userID,40)
|
|
|
- # if user_valid[0].is_superuser == 100 and user_valid[0].is_superuser != 1 and user_valid[0].is_superuser != 10:
|
|
|
- if own_perm is not True:
|
|
|
- return response.json(612)
|
|
|
+ add_dict = {
|
|
|
+ 'id': int(request_dict['id']),
|
|
|
+ 'permName': request_dict['permName'],
|
|
|
+ 'description': request_dict['description']}
|
|
|
+ try:
|
|
|
+ perm = Permissions(**add_dict)
|
|
|
+ perm.save()
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(816, repr(e))
|
|
|
else:
|
|
|
- add_dict = {'id':int(request_dict['id']),'permName':request_dict['permName'],'description':request_dict['description']}
|
|
|
- try:
|
|
|
- perm = Permissions(**add_dict)
|
|
|
- perm.save()
|
|
|
- except Exception as e:
|
|
|
- return response.json(816,repr(e))
|
|
|
- else:
|
|
|
- return Permission.getAllPermission(response=response)
|
|
|
- else:
|
|
|
- return response.json(113)
|
|
|
+ return Permission.getAllPermission(response=response)
|
|
|
+
|
|
|
|
|
|
class delPermsView(View):
|
|
|
@method_decorator(csrf_exempt)
|
|
@@ -552,42 +506,33 @@ class delPermsView(View):
|
|
|
token = request_dict.get('token', None)
|
|
|
id = request_dict.get('id', None)
|
|
|
response = ResponseObject()
|
|
|
- if token != None and id != None:
|
|
|
- tko = TokenObject(token)
|
|
|
- tko.valid()
|
|
|
- response.lang = tko.lang
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- if userID:
|
|
|
- return self.delPerms(userID, id,response)
|
|
|
- else:
|
|
|
- return response.json(309)
|
|
|
+ if not id:
|
|
|
+ return response.json(444, 'id')
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if not userID:
|
|
|
+ return response.json(104)
|
|
|
+ return self.delPerms(userID, id, response)
|
|
|
+
|
|
|
+ def delPerms(self, userID, id, response):
|
|
|
+ User = Device_User.objects.filter(userID=userID)
|
|
|
+ rids = User[0].get_role_id()
|
|
|
+ if len(rids) == 0:
|
|
|
+ return response.json(606)
|
|
|
+ Aperms = False
|
|
|
+ for rid in rids:
|
|
|
+ if rid < 10:
|
|
|
+ continue
|
|
|
else:
|
|
|
- return response.json(tko.code)
|
|
|
- else:
|
|
|
- return response.json(800)
|
|
|
-
|
|
|
- def delPerms(self, userID, id,response):
|
|
|
- try:
|
|
|
- User = Device_User.objects.filter(userID = userID)
|
|
|
- except Exception as e:
|
|
|
- return response.json(500, repr(e))
|
|
|
+ Aperms = True
|
|
|
+ if not Aperms:
|
|
|
+ return response.json(404)
|
|
|
+ perms = Permission()
|
|
|
+ return perms.delPerms(id=id, response=response)
|
|
|
|
|
|
- else:
|
|
|
- rids = User[0].get_role_id()
|
|
|
- if len(rids) == 0:
|
|
|
- return response.json(606)
|
|
|
- Aperms = False
|
|
|
- for rid in rids:
|
|
|
- if rid < 10:
|
|
|
- continue
|
|
|
- else:
|
|
|
- Aperms = True
|
|
|
- if Aperms:
|
|
|
- perms = Permission()
|
|
|
- return perms.delPerms(id=id,response=response)
|
|
|
- else:
|
|
|
- return response.json(611)
|
|
|
|
|
|
class queryPermsView(View):
|
|
|
@method_decorator(csrf_exempt)
|
|
@@ -595,69 +540,56 @@ class queryPermsView(View):
|
|
|
return super(queryPermsView, self).dispatch(*args, **kwargs)
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
- request.encoding = 'gb2312'
|
|
|
- token = request.GET.get('token', None)
|
|
|
- request_data = request.GET
|
|
|
- return self.ValidationError(token,request_data)
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ request_dict = request.GET
|
|
|
+ return self.ValidationError(request_dict)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
- token = request.POST.get('token', None)
|
|
|
- request_data = request.POST
|
|
|
- return self.ValidationError(token,request_data)
|
|
|
+ request_dict = request.POST
|
|
|
+ return self.ValidationError(request_dict)
|
|
|
+
|
|
|
+ def ValidationError(self, request_dict):
|
|
|
+ token = request_dict.get('token', None)
|
|
|
+ type = request_dict.get('type', None)
|
|
|
|
|
|
- def ValidationError(self, token, request_data):
|
|
|
response = ResponseObject()
|
|
|
- if token != None:
|
|
|
- tko = TokenObject(token)
|
|
|
- tko.valid()
|
|
|
- response.lang = tko.lang
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- if userID:
|
|
|
- type = request_data.get('type',None)
|
|
|
- if type == 'PC':
|
|
|
- return self.querAllPermission(userID,response)
|
|
|
- else:
|
|
|
- return self.delPerms(userID,response)
|
|
|
- else:
|
|
|
- return response.json(309)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if not userID:
|
|
|
+ return response.json(104)
|
|
|
+ if type == 'PC':
|
|
|
+ return self.querAllPermission(userID, response)
|
|
|
else:
|
|
|
- return response.json(800)
|
|
|
+ return self.delPerms(userID, response)
|
|
|
|
|
|
- def querAllPermission(self, userID,response):
|
|
|
- own_perm = ModelService.check_permission(userID,30)
|
|
|
- if own_perm is True:
|
|
|
- qs = Permissions.objects.all()
|
|
|
- res = CommonService.qs_to_dict(qs)
|
|
|
- return response.json(0, res)
|
|
|
- else:
|
|
|
+ def querAllPermission(self, userID, response):
|
|
|
+ own_perm = ModelService.check_permission(userID, 30)
|
|
|
+ if own_perm is not True:
|
|
|
return response.json(404)
|
|
|
+ qs = Permissions.objects.all()
|
|
|
+ res = CommonService.qs_to_dict(qs)
|
|
|
+ return response.json(0, res)
|
|
|
|
|
|
- def delPerms(self, userID,response):
|
|
|
- try:
|
|
|
- User = Device_User.objects.filter(userID = userID)
|
|
|
- except Exception as e:
|
|
|
- return response.json(500, repr(e))
|
|
|
- else:
|
|
|
- rids = User[0].get_role_id()
|
|
|
- if len(rids) == 0:
|
|
|
- return response.json(606)
|
|
|
-
|
|
|
- Aperms = False
|
|
|
- for rid in rids:
|
|
|
- if rid < 10:
|
|
|
- continue
|
|
|
- else:
|
|
|
- Aperms = True
|
|
|
-
|
|
|
- if Aperms:
|
|
|
- perms = Permission()
|
|
|
- return perms.queryAllPerms(response=response)
|
|
|
+ def delPerms(self, userID, response):
|
|
|
+ User = Device_User.objects.filter(userID=userID)
|
|
|
+ rids = User[0].get_role_id()
|
|
|
+ if len(rids) == 0:
|
|
|
+ return response.json(606)
|
|
|
+ Aperms = False
|
|
|
+ for rid in rids:
|
|
|
+ if rid < 10:
|
|
|
+ continue
|
|
|
else:
|
|
|
- return response.json(611)
|
|
|
+ Aperms = True
|
|
|
+ if not Aperms:
|
|
|
+ return response.json(404)
|
|
|
+ perms = Permission()
|
|
|
+ return perms.queryAllPerms(response=response)
|
|
|
+
|
|
|
|
|
|
class modifyPermsView(View):
|
|
|
@method_decorator(csrf_exempt)
|
|
@@ -665,38 +597,33 @@ class modifyPermsView(View):
|
|
|
return super(modifyPermsView, self).dispatch(*args, **kwargs)
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
- request.encoding = 'gb2312'
|
|
|
+ request.encoding = 'utf-8'
|
|
|
request_dict = request.GET
|
|
|
return self.ValidationError(request_dict)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
- # token = request.POST.get('token', None)
|
|
|
request_dict = request.POST
|
|
|
return self.ValidationError(request_dict)
|
|
|
|
|
|
def ValidationError(self, request_dict):
|
|
|
token = request_dict.get('token', None)
|
|
|
response = ResponseObject()
|
|
|
- if token != None:
|
|
|
- tko = TokenObject(token)
|
|
|
- tko.valid()
|
|
|
- response.lang = tko.lang
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- if userID:
|
|
|
- update_dict = {'permName':request_dict['permName'],'description':request_dict['description']}
|
|
|
- return self.modifyPerms(userID=userID,id=request_dict['id'], update_dict=update_dict,response=response)
|
|
|
- else:
|
|
|
- return response.json(309)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if userID:
|
|
|
+ update_dict = {'permName': request_dict['permName'], 'description': request_dict['description']}
|
|
|
+ return self.modifyPerms(userID=userID, id=request_dict['id'], update_dict=update_dict,
|
|
|
+ response=response)
|
|
|
else:
|
|
|
- return response.json(800)
|
|
|
+ return response.json(309)
|
|
|
|
|
|
- def modifyPerms(self, userID, id, update_dict,response):
|
|
|
+ def modifyPerms(self, userID, id, update_dict, response):
|
|
|
try:
|
|
|
- User = Device_User.objects.filter(userID = userID)
|
|
|
+ User = Device_User.objects.filter(userID=userID)
|
|
|
except Exception as e:
|
|
|
return response.json(500, repr(e))
|
|
|
else:
|
|
@@ -709,16 +636,15 @@ class modifyPermsView(View):
|
|
|
continue
|
|
|
else:
|
|
|
Aperms = True
|
|
|
-
|
|
|
- if Aperms:
|
|
|
- try:
|
|
|
- Permissions.objects.filter(id = int(id)).update(**update_dict)
|
|
|
- except Exception as e:
|
|
|
- return response.json(500,repr(e))
|
|
|
- else:
|
|
|
- return Permission.getAllPermission(response=response)
|
|
|
+ if not Aperms:
|
|
|
+ return response.json(404)
|
|
|
+ try:
|
|
|
+ Permissions.objects.filter(id=int(id)).update(**update_dict)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, repr(e))
|
|
|
else:
|
|
|
- return response.json(611)
|
|
|
+ return Permission.getAllPermission(response=response)
|
|
|
+
|
|
|
|
|
|
class queryRolePermsView(View):
|
|
|
@method_decorator(csrf_exempt)
|
|
@@ -743,46 +669,37 @@ class queryRolePermsView(View):
|
|
|
|
|
|
def ValidationError(self, token, allUser):
|
|
|
response = ResponseObject()
|
|
|
- if token != None:
|
|
|
- tko = TokenObject(token)
|
|
|
- tko.valid()
|
|
|
- response.lang = tko.lang
|
|
|
- if tko.code == 0:
|
|
|
- userID = tko.userID
|
|
|
- if userID:
|
|
|
- return self.queryRolePerms(userID, allUser,response)
|
|
|
- else:
|
|
|
- return response.json(309)
|
|
|
- else:
|
|
|
- return response.json(tko.code)
|
|
|
+ tko = TokenObject(token)
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ userID = tko.userID
|
|
|
+ if userID:
|
|
|
+ return self.queryRolePerms(userID, allUser, response)
|
|
|
+ else:
|
|
|
+ return response.json(309)
|
|
|
+
|
|
|
+ def queryRolePerms(self, userID, allUser, response):
|
|
|
+ dUser = Device_User.objects.filter(userID=userID).order_by('-data_joined')
|
|
|
+ if not dUser:
|
|
|
+ return response.json(104)
|
|
|
+ if allUser == '0' or allUser == 'False' or allUser == 'false':
|
|
|
+ allUser = False
|
|
|
+ elif allUser == '1' or allUser == 'True' or allUser == 'true':
|
|
|
+ allUser = True
|
|
|
else:
|
|
|
- return response.json(800)
|
|
|
+ allUser = False
|
|
|
+ pM = permManager()
|
|
|
+ if not allUser:
|
|
|
+ ridslist = []
|
|
|
+ rids = dUser[0].get_role_id()
|
|
|
|
|
|
- def queryRolePerms(self, userID, allUser,response):
|
|
|
- try:
|
|
|
- dUser = Device_User.objects.filter(userID=userID).order_by('-data_joined')
|
|
|
- except Exception as e:
|
|
|
- return response.json(500, repr(e))
|
|
|
+ for rid in rids:
|
|
|
+ ridslist.append(pM.queryMoreRole(rid=rid))
|
|
|
+ sqlDict = dict(zip(["datas"], [ridslist]))
|
|
|
+ return response.json(0, sqlDict)
|
|
|
else:
|
|
|
- if not dUser:
|
|
|
- return response.json(113)
|
|
|
- if allUser == '0' or allUser == 'False' or allUser == 'false':
|
|
|
- allUser = False
|
|
|
- elif allUser == '1' or allUser == 'True' or allUser == 'true':
|
|
|
- allUser = True
|
|
|
+ if 100 in dUser[0].get_role_id():
|
|
|
+ return pM.queryAllRole(response=response)
|
|
|
else:
|
|
|
- allUser = False
|
|
|
- pM = permManager()
|
|
|
- if not allUser:
|
|
|
- ridslist =[]
|
|
|
- rids = dUser[0].get_role_id()
|
|
|
-
|
|
|
- for rid in rids:
|
|
|
- ridslist.append(pM.queryMoreRole(rid=rid))
|
|
|
- sqlDict = dict(zip(["datas"], [ridslist]))
|
|
|
- return response.json(0,sqlDict)
|
|
|
- else:
|
|
|
- if 100 in dUser[0].get_role_id():
|
|
|
- return pM.queryAllRole(response=response)
|
|
|
- else:
|
|
|
- return response.json(612)
|
|
|
+ return response.json(404)
|