Allow role checks to be bypassed for a given view

- Override the 'get_permission_model' attribute with None
This commit is contained in:
Oliver Walters
2024-08-22 06:25:18 +00:00
parent fc36f0bcde
commit 682dbc83fc
2 changed files with 10 additions and 0 deletions

View File

@ -79,6 +79,9 @@ class RolePermission(permissions.BasePermission):
# Extract the model name associated with this request
model = get_model_for_view(view)
if model is None:
return True
app_label = model._meta.app_label
model_name = model._meta.model_name

View File

@ -154,6 +154,13 @@ class MeUserDetail(RetrieveUpdateAPI, UserDetail):
"""Always return the current user object."""
return self.request.user
def get_permission_model(self):
"""Return the model for the permission check.
Note that for this endpoint, the current user can *always* edit their own details.
"""
return None
class UserList(ListCreateAPI):
"""List endpoint for detail on all users."""