|
@@ -7,55 +7,35 @@ class ModelService:
|
|
# 获取当前用户角色名
|
|
# 获取当前用户角色名
|
|
@staticmethod
|
|
@staticmethod
|
|
def getRole(rid):
|
|
def getRole(rid):
|
|
- Roles = Role.objects.get(rid=rid)
|
|
|
|
- return Roles.roleName
|
|
|
|
-
|
|
|
|
- @staticmethod
|
|
|
|
- def getValidateMember(userID):
|
|
|
|
- device_user_query_set = Device_User.objects.get(userID=userID)
|
|
|
|
- role_query_set = device_user_query_set.role.all()
|
|
|
|
- role_dict = CommonService.qs_to_dict(role_query_set)
|
|
|
|
- permission = role_dict["datas"][0]["fields"]["permission"]
|
|
|
|
- if len(permission):
|
|
|
|
- if 92 in permission:
|
|
|
|
- return True
|
|
|
|
- return False
|
|
|
|
|
|
+ return Role.objects.get(rid=rid).roleName
|
|
|
|
|
|
# 获取用户所有权限
|
|
# 获取用户所有权限
|
|
@staticmethod
|
|
@staticmethod
|
|
def own_permission(userID):
|
|
def own_permission(userID):
|
|
- device_user_query_set = Device_User.objects.get(userID=userID)
|
|
|
|
- role_query_set = device_user_query_set.role.all()
|
|
|
|
- if role_query_set.exists():
|
|
|
|
- role_dict = CommonService.qs_to_dict(role_query_set)
|
|
|
|
- permission = role_dict["datas"][0]["fields"]["permission"]
|
|
|
|
- if len(permission):
|
|
|
|
- return permission
|
|
|
|
|
|
+ permission = Device_User.objects.get(userID=userID).role.values_list('permission',flat=True)
|
|
|
|
+ if permission:
|
|
|
|
+ return list(permission)
|
|
return []
|
|
return []
|
|
|
|
|
|
# 获取用户角色相关
|
|
# 获取用户角色相关
|
|
@staticmethod
|
|
@staticmethod
|
|
def own_role(userID):
|
|
def own_role(userID):
|
|
- device_user_query_set = Device_User.objects.get(userID=userID)
|
|
|
|
- role_query_set = device_user_query_set.role.all()
|
|
|
|
- if role_query_set.exists():
|
|
|
|
- return {'rid': role_query_set[0].rid, 'roleName': role_query_set[0].roleName}
|
|
|
|
|
|
+ try:
|
|
|
|
+ role_qs = Device_User.objects.get(userID=userID).role.values('rid','roleName')
|
|
|
|
+ if role_qs.exists():
|
|
|
|
+ return {'rid': role_qs[0]['rid'], 'roleName': role_qs[0]['roleName']}
|
|
|
|
+ except Exception as e:
|
|
|
|
+ pass
|
|
return {'rid': '', 'roleName': ''}
|
|
return {'rid': '', 'roleName': ''}
|
|
|
|
|
|
# 检测权限有无
|
|
# 检测权限有无
|
|
@staticmethod
|
|
@staticmethod
|
|
def check_permission(userID, permID):
|
|
def check_permission(userID, permID):
|
|
try:
|
|
try:
|
|
- device_user_query_set = Device_User.objects.get(userID=userID)
|
|
|
|
- if device_user_query_set:
|
|
|
|
- role_query_set = device_user_query_set.role.all()
|
|
|
|
- if role_query_set:
|
|
|
|
- role_dict = CommonService.qs_to_dict(role_query_set)
|
|
|
|
- permission = role_dict["datas"][0]["fields"]["permission"]
|
|
|
|
- print(permission)
|
|
|
|
- if len(permission) > 0:
|
|
|
|
- if permID in permission:
|
|
|
|
- return True
|
|
|
|
|
|
+ perm_list = Device_User.objects.get(userID=userID).role.values_list('permission', flat=True)
|
|
|
|
+ if perm_list:
|
|
|
|
+ if permID in perm_list:
|
|
|
|
+ return True
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return False
|
|
return False
|
|
return False
|
|
return False
|
|
@@ -64,13 +44,10 @@ class ModelService:
|
|
@staticmethod
|
|
@staticmethod
|
|
def check_user_own_device(userID, deviceID):
|
|
def check_user_own_device(userID, deviceID):
|
|
try:
|
|
try:
|
|
- device_user = Device_User.objects.get(userID=userID)
|
|
|
|
- device_info_queryset = device_user.device_info_set.all().values('id')
|
|
|
|
- id_list = []
|
|
|
|
- for id_dict in list(device_info_queryset):
|
|
|
|
- id_list.append(id_dict['id'])
|
|
|
|
- if deviceID in id_list:
|
|
|
|
- return True
|
|
|
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID).values_list('id',flat=True)
|
|
|
|
+ if dvqs:
|
|
|
|
+ if deviceID in dvqs:
|
|
|
|
+ return True
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return False
|
|
return False
|
|
return False
|
|
return False
|
|
@@ -78,8 +55,8 @@ class ModelService:
|
|
# 根据设设备唯一名称UID判断是否拥有该设备
|
|
# 根据设设备唯一名称UID判断是否拥有该设备
|
|
@staticmethod
|
|
@staticmethod
|
|
def check_own_device(userID, UID):
|
|
def check_own_device(userID, UID):
|
|
- device_info_queryset = Device_Info.objects.filter(userID_id=userID, UID=UID)
|
|
|
|
- if device_info_queryset.exists():
|
|
|
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID, UID=UID)
|
|
|
|
+ if dvqs.exists():
|
|
return True
|
|
return True
|
|
return False
|
|
return False
|
|
|
|
|
|
@@ -125,4 +102,4 @@ class ModelService:
|
|
View_Password=View_Password, ChannelIndex=ChannelIndex)
|
|
View_Password=View_Password, ChannelIndex=ChannelIndex)
|
|
if device_info_queryset.exists():
|
|
if device_info_queryset.exists():
|
|
return True
|
|
return True
|
|
- return False
|
|
|
|
|
|
+ return False
|