Conversation
ankitamk14
commented
Oct 9, 2023
- Added backend for group permission form.
sunilshetye
left a comment
There was a problem hiding this comment.
Looks good.
Added some comments. Please check.
I think the context should have a hierarchy also. This way, a state can assign district context to a reporter. We will discuss this further.
| """ | ||
| for permission, permission_data in permissions.items(): | ||
| permission_id = int(permission) | ||
| context_id = permission_data.get('context', None) |
There was a problem hiding this comment.
don't give a default value for mandatory parameters.
| for permission, permission_data in permissions.items(): | ||
| permission_id = int(permission) | ||
| context_id = permission_data.get('context', None) | ||
| status = permission_data.get('status', False) |
There was a problem hiding this comment.
Will each field have a separate checkbox for changing status? If yes, this is okay.
don't give a default value for mandatory parameters.
| context_id=context_id) | ||
| gp.delete() | ||
| except Exception as e: | ||
| print(f"\033[93mException ** {e}\033[0m") |
There was a problem hiding this comment.
| print(f"\033[93mException ** {e}\033[0m") | |
| print(f"Exception: {e}") |
Don't use ANSI colours.
| """ | ||
| role = models.ForeignKey(Group, on_delete=models.CASCADE) | ||
| permission = models.ForeignKey(Permission, on_delete=models.CASCADE) | ||
| context = models.ForeignKey(Context, on_delete=models.CASCADE) |
There was a problem hiding this comment.
Will need to discuss this context more.
| if status: | ||
| gp = GroupPermission.objects.filter(role=group, permission_id=permission_id | ||
| ).first() |
There was a problem hiding this comment.
| if status: | |
| gp = GroupPermission.objects.filter(role=group, permission_id=permission_id | |
| ).first() | |
| gps = GroupPermission.objects.filter(role=group, permission_id=permission_id) | |
| if status: | |
| gp = gps.first() |
do filter and get separately
| __str__(): Returns a string representation of the permission. | ||
|
|
||
| """ | ||
| RESOURCES = RESOURCES |
There was a problem hiding this comment.
This line is not required.
| def post(self, request): | ||
| try: | ||
| data = request.data | ||
| permissions = data.get('permissions', {}) |
There was a problem hiding this comment.
don't give default values for mandatory parameters.
| try: | ||
| data = request.data | ||
| permissions = data.get('permissions', {}) | ||
| group = Group.objects.create(name=data.get('name', '')) |
There was a problem hiding this comment.
don't give default values for mandatory parameters.
| class PermissionsDetailView(APIView): | ||
| def patch(self, request, pk): | ||
| data = request.data | ||
| permissions = data.get('permissions', {}) |
There was a problem hiding this comment.
don't give default values for mandatory parameters.
| permissions = data.get('permissions', {}) | ||
| try: | ||
| group = Group.objects.get(id=pk) | ||
| name = data.get('name', None) |
There was a problem hiding this comment.
don't give default values for mandatory parameters.