|
@@ -10,9 +10,11 @@ import logging
|
|
|
import time
|
|
|
|
|
|
from django.db import transaction
|
|
|
+from django.db.models import Q
|
|
|
from django.views import View
|
|
|
|
|
|
-from Model.models import DeviceSharePermission, DeviceChannelUserSet, DeviceChannelUserPermission, UidChannelSetModel
|
|
|
+from Model.models import DeviceSharePermission, DeviceChannelUserSet, DeviceChannelUserPermission, UidChannelSetModel, \
|
|
|
+ Device_Info
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Service.UserDeviceService import UserDeviceService
|
|
@@ -42,6 +44,8 @@ class UserDeviceShareView(View):
|
|
|
return self.get_user_share_permission(request_dict, response)
|
|
|
elif operation == 'permissions-save':
|
|
|
return self.user_channel_permission_save(request_dict, response)
|
|
|
+ elif operation == 'permissions-test':
|
|
|
+ return self.synch_share_device_permission(response)
|
|
|
else:
|
|
|
return response.json(404)
|
|
|
|
|
@@ -146,19 +150,19 @@ class UserDeviceShareView(View):
|
|
|
try:
|
|
|
if not all([user_id, uid]):
|
|
|
return False
|
|
|
- UserDeviceService.update_device_channel(uid)
|
|
|
- channel_qs = UidChannelSetModel.objects.filter(uid__uid=uid).values('channel')
|
|
|
- if not channel_qs.exists():
|
|
|
- return False
|
|
|
- channel_list = [str(val['channel']) for val in channel_qs]
|
|
|
- channel_str = ','.join(channel_list)
|
|
|
with transaction.atomic():
|
|
|
- now_time = int(time.time())
|
|
|
- device_set = {'uid': uid, 'user_id': user_id, 'channels': channel_str,
|
|
|
- 'created_time': now_time, 'updated_time': now_time}
|
|
|
ds_qs = DeviceChannelUserSet.objects.filter(user_id=user_id, uid=uid)
|
|
|
if ds_qs.exists():
|
|
|
return True
|
|
|
+ UserDeviceService.update_device_channel(uid)
|
|
|
+ channel_qs = UidChannelSetModel.objects.filter(uid__uid=uid).values('channel')
|
|
|
+ if not channel_qs.exists():
|
|
|
+ return False
|
|
|
+ channel_list = [str(val['channel']) for val in channel_qs]
|
|
|
+ channel_str = ','.join(channel_list)
|
|
|
+ now_time = int(time.time())
|
|
|
+ device_set = {'uid': uid, 'user_id': user_id, 'channels': channel_str,
|
|
|
+ 'created_time': now_time, 'updated_time': now_time}
|
|
|
device_user_set = DeviceChannelUserSet.objects.create(**device_set)
|
|
|
channel_permission_qs = DeviceSharePermission.objects \
|
|
|
.all().values('id', 'code').order_by('sort')
|
|
@@ -174,3 +178,18 @@ class UserDeviceShareView(View):
|
|
|
except Exception as e:
|
|
|
LOGGER.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return False
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def synch_share_device_permission(response):
|
|
|
+ """
|
|
|
+ 同步分析设备权限
|
|
|
+ @param response: 响应结果
|
|
|
+ """
|
|
|
+ device_info_qs = Device_Info.objects \
|
|
|
+ .filter(~Q(Type__in=[1, 2, 3, 4, 10001]), ~Q(primaryUserID=''), isShare=1) \
|
|
|
+ .values('userID_id', 'UID').order_by('-data_joined')
|
|
|
+ if not device_info_qs.exists():
|
|
|
+ return response.json(0)
|
|
|
+ for item in device_info_qs:
|
|
|
+ UserDeviceShareView.qrcode_share_channel_permission_save(item['userID_id'], item['UID'])
|
|
|
+ return response.json(0)
|