Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ankitamk14
Copy link
Contributor

  • Added backend for group permission form.

Copy link
Collaborator

@sunilshetye sunilshetye left a 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)
Copy link
Collaborator

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)
Copy link
Collaborator

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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Collaborator

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.

Comment on lines +142 to +144
if status:
gp = GroupPermission.objects.filter(role=group, permission_id=permission_id
).first()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

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', {})
Copy link
Collaborator

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', ''))
Copy link
Collaborator

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', {})
Copy link
Collaborator

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)
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants