Exemplo n.º 1
0
 def update_permissions(self, request, pk):
     data = JSONParser().parse(request)
     if 'permission_id' in data:
         permission_id = int(data['permission_id'])
     elif 'permission_group' in data:
         permission_group = data['permission_group']
         permission_id = None
     else:
         permission_group = None
         permission_id = None
     
     user_permissions = UserLocationPermission.objects.filter(account__id = request.user.id)
         
     permission_list = data['permissions']
     new_permissions = []
     for perm_data in permission_list:
         serializer = UserLocationPermissionSerializer(data=perm_data)
         if serializer.is_valid():
             perm_obj = serializer.create_local()
             new_permissions.append(perm_obj)
     
     issues = UserLocationPermission.check_valid_permission_set(pk, new_permissions, permission_id, permission_group)
     if len(issues) > 0:
         code = status.HTTP_500_INTERNAL_SERVER_ERROR
     else:
         code = UserLocationPermission.update_permission_set (pk, new_permissions, permission_id, permission_group, user_permissions)
         if code == status.HTTP_200_OK:
             self.update_account_permission(pk)
         
     return Response({"data": data}, code)
Exemplo n.º 2
0
    def update_permissions(self, request, pk):
        data = JSONParser().parse(request)
        if 'permission_id' in data:
            permission_id = int(data['permission_id'])
        elif 'permission_group' in data:
            permission_group = data['permission_group']
            permission_id = None
        else:
            permission_group = None
            permission_id = None

        user_permissions = UserLocationPermission.objects.filter(
            account__id=request.user.id,
            permission__permission_group='ACCOUNTS',
            permission__action='MANAGE')

        permission_list = data['permissions']
        new_permissions = []
        for perm_data in permission_list:
            serializer = UserLocationPermissionSerializer(data=perm_data)
            if serializer.is_valid():
                perm_obj = serializer.create_local()
                new_permissions.append(perm_obj)

        issues = UserLocationPermission.check_valid_permission_set(
            pk, new_permissions, permission_id, permission_group)
        if len(issues) > 0:
            return_data = {'error_text': issues[0]}
            code = status.HTTP_500_INTERNAL_SERVER_ERROR
        else:
            result = UserLocationPermission.update_permission_set(
                pk, new_permissions, permission_id, permission_group,
                user_permissions)
            code = result['code']
            if code == status.HTTP_200_OK:
                self.update_account_permission(pk)
                return_data = data
            else:
                return_data = {'error_text': result['error']}

        return Response(return_data, code)