Also pass the object to the resource access checker in the serializer#3966
Merged
soyuka merged 1 commit intoJan 21, 2021
Merged
Conversation
…ty access checks in the serializer
chalasr
approved these changes
Jan 20, 2021
Member
|
thanks @Toflar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In #3503 @GregoireHebert introduced support for the
securityattribute on an api property.I found that this is very useful to me because I can get rid of my own normalizer. However, my permission system depends not only on roles but you can have different roles per organisation. This in turn means, it depends on the object.
The object itself is already passed on in e.g. the DenyAccessListener (https://github.com/api-platform/core/blob/master/src/Security/EventListener/DenyAccessListener.php#L100) so we should also have it here.
By introducing that, I was able to super conveniently restrict access to a certain property by registering my own custom expression language function. It now looks like this ❤️ :
Regarding docs, I guess I could expand a bit on what Frédéric already wrote in api-platform/docs#1000.