-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backend For Group Permissions #15
base: main
Are you sure you want to change the base?
Conversation
ankitamk14
commented
Oct 9, 2023
- Added backend for group permission form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not required.
def post(self, request): | ||
try: | ||
data = request.data | ||
permissions = data.get('permissions', {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't give default values for mandatory parameters.