Эх сурвалжийг харах

删除设备新增删除通道权限逻辑

zhangdongming 2 жил өмнө
parent
commit
1ac5e85c1c

+ 28 - 3
Controller/DeviceShare.py

@@ -16,15 +16,15 @@ import json
 import time
 import time
 
 
 from django.views.generic.base import View
 from django.views.generic.base import View
-from Object.RedisObject import RedisObject
+
 from Ansjer.config import SERVER_DOMAIN
 from Ansjer.config import SERVER_DOMAIN
-from Model.models import Device_Info, Device_User
+from Controller.SensorGateway.EquipmentFamilyController import EquipmentFamilyView
+from Model.models import Device_Info, Device_User, DeviceChannelUserSet, DeviceChannelUserPermission
 from Model.models import UID_Bucket
 from Model.models import UID_Bucket
 from Object.RedisObject import RedisObject
 from Object.RedisObject import RedisObject
 from Object.ResponseObject import ResponseObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.TokenObject import TokenObject
 from Service.CommonService import CommonService
 from Service.CommonService import CommonService
-from Controller.SensorGateway.EquipmentFamilyController import EquipmentFamilyView
 
 
 
 
 class DeviceShareView(View):
 class DeviceShareView(View):
@@ -262,7 +262,32 @@ class DeviceShareView(View):
             return response.json(444, 'id')
             return response.json(444, 'id')
         try:
         try:
             Device_Info.objects.filter(id__in=ids.split(','), primaryUserID=userID).delete()
             Device_Info.objects.filter(id__in=ids.split(','), primaryUserID=userID).delete()
+
         except Exception as e:
         except Exception as e:
             return response.json(10, repr(e))
             return response.json(10, repr(e))
         else:
         else:
             return response.json(0)
             return response.json(0)
+
+    @staticmethod
+    def del_device_channel_permission(user_id, uid):
+        """
+        删除设备通道权限
+        @param user_id: 用户ID
+        @param uid: 设备UID
+        @return: True | False
+        """
+        if user_id and uid:
+            user_channel_qs = DeviceChannelUserSet.objects.filter(user_id=user_id, uid=uid)
+            if user_channel_qs.exists():
+                DeviceChannelUserPermission.objects.filter(channel_user_id=user_channel_qs.first().id).delete()
+                user_channel_qs.delete()
+            return True
+        elif uid:
+            user_channel_qs = DeviceChannelUserSet.objects.filter(uid=uid)
+            if user_channel_qs.exists():
+                channels_user_list = [val.id for val in user_channel_qs]
+                DeviceChannelUserPermission.objects.filter(channel_user_id__in=channels_user_list).delete()
+                user_channel_qs.delete()
+            return True
+        else:
+            return False

+ 3 - 0
Controller/EquipmentManager.py

@@ -14,6 +14,7 @@ from django.utils import timezone
 from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY, BASE_DIR
 from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY, BASE_DIR
 from Ansjer.config import PUSH_REDIS_ADDRESS
 from Ansjer.config import PUSH_REDIS_ADDRESS
 from Controller.DetectController import DetectControllerView
 from Controller.DetectController import DetectControllerView
+from Controller.DeviceShare import DeviceShareView
 from Model.models import Device_User, Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel, \
 from Model.models import Device_User, Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel, \
     UIDCompanySerialModel, iotdeviceInfoModel, UidChannelSetModel, LogModel, UnicomDeviceInfo, SysMsgModel, CountryModel
     UIDCompanySerialModel, iotdeviceInfoModel, UidChannelSetModel, LogModel, UnicomDeviceInfo, SysMsgModel, CountryModel
 from Object.RedisObject import RedisObject
 from Object.RedisObject import RedisObject
@@ -824,6 +825,7 @@ def deleteInterface(request):
 
 
             if dv_qs[0].isShare:
             if dv_qs[0].isShare:
                 dv_qs.delete()
                 dv_qs.delete()
+                DeviceShareView.del_device_channel_permission(userID, uid)
             else:
             else:
                 # a.主用户删除设备
                 # a.主用户删除设备
                 dv_qs.delete()
                 dv_qs.delete()
@@ -840,6 +842,7 @@ def deleteInterface(request):
                     up_qs.delete()
                     up_qs.delete()
                 # b.删除次用户设备
                 # b.删除次用户设备
                 Device_Info.objects.filter(UID=uid, isShare=True, primaryUserID=userID).delete()
                 Device_Info.objects.filter(UID=uid, isShare=True, primaryUserID=userID).delete()
+                DeviceShareView.del_device_channel_permission('', uid)
 
 
             if not serial_number:
             if not serial_number:
                 serial_number = CommonService.query_serial_with_uid(uid)
                 serial_number = CommonService.query_serial_with_uid(uid)