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

Permissions do not implement has_object_permission #21

Closed
sg2002 opened this issue Apr 9, 2019 · 2 comments · Fixed by #25
Closed

Permissions do not implement has_object_permission #21

sg2002 opened this issue Apr 9, 2019 · 2 comments · Fixed by #25
Assignees
Milestone

Comments

@sg2002
Copy link

sg2002 commented Apr 9, 2019

Hello. Really like your package. Here's a problem I've ran into while implementing an api based on it.
I have a user REST API and I wanted to allow updating user only for the user himself or an apikey. I wrote a simple permission called IsTheSameUser, but chaining it using OR with HasAPIKey didn't work - requests were passing.
Looking into it, I noticed that permissions provided by this project don't implement has_object_permission and my permission class cannot implement has_permission, since it's only becomes aware at has_object_permission level.
So, may I suggest adding has_object_permission method that wraps has_permisison:

    def has_object_permission(self, request, view, obj):
        return self.has_permission(request, view)

I subclassed for now, don't see any harm that can be done with this addition.

@florimondmanca
Copy link
Owner

florimondmanca commented Apr 9, 2019

Absolutely, sounds good to me. I don't have the means to send a fix currently, so feel free to throw together a PR based on the fix you found.

Note — there are a few caveats documented in the DRF docs. Notably, one needs to manually check object permissions unless they use generic views. Have you made sure that this is what you did when "requests were passing"?

@florimondmanca
Copy link
Owner

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 a pull request may close this issue.

2 participants