-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Security][TwigBridge] Add access_decision() and access_decision_for_user()
#61379
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
[Security][TwigBridge] Add access_decision() and access_decision_for_user()
#61379
Conversation
nicolas-grekas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks useful to me
some tests + changelog entries would be needed
src/Symfony/Component/Mailer/Bridge/Resend/Transport/ResendApiTransport.php
Show resolved
Hide resolved
this is already covered by the AccessDecision::getMessage method |
e97da9a to
5a74291
Compare
|
Will update the changelogs in the next few days ! |
|
They're already up to date ;) |
access_decision() and access_decision_for_user()
90cf011 to
226b5f8
Compare
fabpot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have good alternative names, but I'm wondering if the method/function names couldn't be better. 🤔
For twig, I can't think of a better name than |
|
using a getter style might be easier to self-explain the fact that it's an object you're getting and not a boolean. For twig this is redundant indeed. |
226b5f8 to
9884b2d
Compare
|
PR ready, comments addressed. |
9884b2d to
1aead14
Compare
1aead14 to
9b9c72d
Compare
|
Thank you @florentdestremau. |
|
Thank you! I feel like I just put the thing in motion but you did the hard part 😄 |
This PR adds 2 new methods and the corresponding twig helpers to retrieve the access decision from a Voter rather than simply the result. This way, you can enumerate the AccessDecision::votes and retrieve the votes and their reason, and you can get the reason message.
For instance, in a controller or service:
Same for a user on his behalf, and same in Twig;
{% set access = access_decision('post_edit', post) %} <a href="/post/123/edit" {% if not access.isGranted %} title="You don't have access to this post : {{ access.message }}" disabled {% endif %} > Edit this post </a>