-
Notifications
You must be signed in to change notification settings - Fork 59
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
Show related resources doesn't check related resource policy #111
Comments
When you're accessing something plural, like in your case "addresses", Could you tell me a bit more about what you see happening? |
I have a user which has many addresses, I defined all the policy methods of addresses as false (for debugging). When I do a request to /addresses I get 403. However when I do /users/1/addresses I get the list of addresses. Do I need to include some mixin? I have included When looking in the authorizer class I see some difference between /resource/:id/relationship and /resource?include=relationship. Is this maybe cause by that? Because when i do /user?include=addresses I do get a 403. Reference: |
Hmm yeah,
Have you perhaps overridden the definition for |
The specs here:
Should say that
As otherwise the spec would've returned 3 comments instead of only 1: jsonapi-authorization/spec/fixtures/comments.yml Lines 1 to 13 in 8176e89
|
Now I see why it is not working. It is not calling |
Hmm... when viewing related resources, we do not call jsonapi-authorization/lib/jsonapi/authorization/authorizing_processor.rb Lines 103 to 110 in 8176e89
That might be a bug. I wonder if we have the information in that place to figure out which related resource class we're trying to look at? The method should pass def show_related_resources(source_record:, related_record_class:)
::Pundit.authorize(user, source_record, 'show?')
::Pundit.authorize(user, related_record_class, 'index?')
end |
Yes, you should create a scope resolve method for the relationship. I think it should've errored out if you didn't have one defined? Or maybe you have some base class that defines an "all results are OK" scope resolver? |
Yes we have an base Scope which returns all the records. It would be great if for related resources it will call the related record policy index? as well (as you mentioned 2 comments above). For now I will work with the Scope.resolve |
Yeah sounds like a plan 😊 |
Hi,
I just found out that when accessing the relationships of a model (for example /users/1/addresses) with a has_many relationship only the
model#show?
policy is checked. I would expect that also the relationship policy is checked (in my exampleaddresses#show?
). What is the reason that this doesn't happen? Is this an error or is this intended?In my user addresses example I cannot forbid a user to get addresses of all the other users without forbidding all users to see another user. This is not what I want. How can I make this happen?
The text was updated successfully, but these errors were encountered: