-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Research how permissions is implemented in Django and DRF #149
Comments
Seems to be that we can include permissions in a table by inserting a "permissions" line into the Meta class for each table. For example, if we wanted to restrict modifying the project description, we would include the following:
To assign it to a user we do
Lastly to make sure the restriction is in place, we will put |
Thanks for finding out how it works in django. I think maybe the issue description is too vague. We're looking for a solution that will allow us to assign permissions to users and user groups without having to change the source code. So, maybe an implementation is having a table that stores the user in relation to the permissions they have. The permissions need to be fairly fine-grained like they can update a row in a table but not create or delete it. I'm thinking of the example where a project manager can update the project's description but not create or delete the project. Since we're building this backend for other teams to connect their frontends, we really only care about the API layer which DRF creates. But I wasn't sure if we need to do the same thing for django itself or if doing it in the DRF/API layer is sufficient, or if the DRF implementation also takes care of setting it in django. So this is an exploratory issue to try to figure that out. The implementation I described above is just an example. I'm sure there are packages out there we can use and we wouldn't necessarily need to know the implementation in detail, just that it does what we need. Bonnie and Nicole have been meeting to figure out exactly what permissions each user level should have. So I guess it'd be mostly like a user group sharing a set of permissions. |
There are four default permissions in the Django admin site: add, create, delete, and view, which are specific to each table. The superuser, or any user with the "core | user | Can change user" permission, can assign any of these permissions to any user. This is done in the "Change user" view. For your example - if we want a user to be able to change a project description but not add or delete the project, we give it the permission "core | project | Can change project" but not "core | project | Can add project" or "core | project | Can delete project". There isn't a way in the interface to restrict specific rows. It appears the way to do that is to include a readonly_fields attribute for each admin class in app/core/admin.py, then overwriting the get_readonly_fields method for the specific user/group. See the documentation below: |
The default permission system in Django allows you to grant CRUD permissions at the model/table level but people depot is going to need at minimum object/field level permissions. Looking at the Django packages permissions page, we have a few options for object level permission add-ons
Nice article with examples of the last 4 options: https://www.vinta.com.br/blog/controlling-access-a-django-permission-apps-comparison |
From @ethanstrominger |
I can see that this is trying to extend the permission to add the Maybe the Github Copilot prompt could be tweaked to request adapter code for django rest framework. I tried adding a simpler logging click to expand
|
@ethanstrominger generated some code that tries to make it rest_framework-friendly. |
Overview
We need to research the permissions capabilities provided by Django and DRF. See instructions below.
Action Items
Instructions
What we want is something like:
The text was updated successfully, but these errors were encountered: