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

Object level permissions #2

Open
bogdandm opened this issue May 5, 2019 · 0 comments
Open

Object level permissions #2

bogdandm opened this issue May 5, 2019 · 0 comments

Comments

@bogdandm
Copy link

bogdandm commented May 5, 2019

https://www.django-rest-framework.org/api-guide/permissions/#object-level-permissions

def get_object(self):
    obj = get_object_or_404(self.get_queryset(), pk=self.kwargs["pk"])
    self.check_object_permissions(self.request, obj)
    return obj

So get_object already has check_permissions call. So it would be nice to impelement has_object_permission (https://github.com/encode/django-rest-framework/blob/master/rest_framework/permissions.py#L112).

It will have the same logic as has_permission but provide additional attribute object into conditions functions.

Signature of conditions would be f(self, request, view, action, object=None) -> bool. And object-level conditions should have this check:

if object is None:
    return True

P.S. If you agree with this I could impelement it and create PR.

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

No branches or pull requests

1 participant