-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
change get_permissions to return list #500
base: master
Are you sure you want to change the base?
Conversation
I found a case that supports def get_permissions(self) -> Sequence[_SupportsHasPermission]:
if self.action == 'list':
return [OR(IsAdminUser(), SomeOtherPermission())]
return super().get_permissions() |
59fefcc
to
5977c99
Compare
60422fb
to
d8bee67
Compare
I had to revert back to |
Thanks. I'll have a look in the evening. (feel free to ping if I forget) I'm not using the DRF permission system myself, so I'm not very familiar with it. Is it worth investigating support for boolean operators as well, e.g. |
The |
I have made things!
Proposal to change the signature of
get_permissions
tolist[BasePermission]
. This allows one to customize the permissions of a view as suggested by the documentation: https://www.django-rest-framework.org/api-guide/permissions/#overview-of-access-restriction-methodsThe source code also suggests that is is a
list
:https://github.com/encode/django-rest-framework/blob/f56b85b7dd7e4f786e0769bba6b7609d4507da83/rest_framework/views.py#L278
It was originally changed in #320 to
Sequence[_SupportsHasPermission]
.I am not sure if the element type has to be_SupportsHasPermission
instead ofBasePermission
. All the other method signatures use the base type.Update: In the end I reverted back for the same reason why the return type was changed to
Sequence
in #320 and added a few more test cases.Related issues
Refs #319 (PR: #320)