-
Notifications
You must be signed in to change notification settings - Fork 42
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
Updating a model's relationships where the policy denies updating the relationship gives 200 OK, but doesn't update the relationship #281
Comments
I believe this is supported by the json-api spec 9.2.3.4 https://jsonapi.org/format/#crud-updating-resource-relationships
The policy decides whether or not a request is supported or not. If it denies the request, a 403 Forbidden should be sent back to the client. |
@Azeirah - the "supported" seems to be key here, if it's allowed under some circumstances but not others, it's still supported. Only if it's not supported under any circumstances does it provide a 403. |
Possibly, however paragraph 9 does state the following
In the example I provided, my request performs a partial update (only the upsells attributes are updated, but not the relations), this clearly goes against spec 9, and possibly goes against the spec 9.2.3.4 depending on how it is interpreted. |
@Azeirah - given that the documentation for this package lists that you need to add the authorization to modify the relationships, (https://laraveljsonapi.io/docs/3.0/tutorial/06-modifying-resources.html#authorization), it seems like it simply ignores the request's relationship changes unless the authorization is defined. So the Try setting the updateProducts policy to |
I'm surprised to hear this, I can't see how that has any affect. The Can you check your validation rules? We only fill the model with validated data, so if you haven't got a validation rule for the In relation to this from the spec:
We are compliant with that, because we authorise the request to update a resource or relationship. (Relationship in this context means the relationship endpoints, which are authorised as well as the resource endpoints.) Resource authorisation: https://laraveljsonapi.io/docs/3.0/requests/authorization.html#resource-authorization vs Relationship authorisation: https://laraveljsonapi.io/docs/3.0/requests/authorization.html#relationship-authorization With the latter section worth reading, as it explains all of this. And explains that the implementation is resource level authorisation, not field level authorisation. Hope this helps. |
I have the following Schema:
Note the "BelongsToMany" relationship with "products".
My policy for Upsell is as follows (in short, it allows any updates to the model):
Now when I make the following request, intending to replace an upsell's products relationship
I get a 200 OK, but the upsell#20.products relationship is not updated.
Once I added the following function to the UpsellPolicy, it does get updated.
I'm expecting a 401 Unauthorized exception, not a 200 OK.
The text was updated successfully, but these errors were encountered: