-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Clarify VoterInterface with multiple attributes #32956
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
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.
IMO this is not a hard requirement for any voter and it's totally fine to implement a custom voter that behaves differently. I would suggest that we move this comment into the docblock of the
Voter
class instead.Uh oh!
There was an error while loading. Please reload this page.
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 would be very careful with this approach, as it might bring a lot of confusion.
There clearly are conflicting views here. Here's how the Twig doc for
is_granted()
evolved in the last few months:on 9 Oct 2018, Improve is_granted documentation symfony-docs#10461 by @Jean85 changed the wording to:
changed the same day by @javiereguiluz to:
on 25 Oct 2018, following this comment on #10461 by @xabbuh:
fix RoleVoter behaviour description symfony-docs#10580 by @xabbuh changed it to:
on 18 July 2019, [Security] Better explain what happens when multiple roles are passed symfony-docs#11988 by @javiereguiluz changed it back to:
As you can see, on the assumption that Twig's
is_granted()
follows the same rules asVoterInterface::vote()
, there is no current consensus on howis_granted()
should behave, and worse, there are regressions in the docs, ignoring relevant past comments:@Jean85 and @javiereguiluz think that the behaviour is influenced by the Access Decision Manager strategy, although @xabbuh proved that it's not; @Jean85 admitted that this was a mistake.
regardless of the point above, @xabbuh now thinks that it's fine for voters to behave as they wish on this point, upvoted by @ro0NL
the current Twig doc is clearly in infringement with the source code anyway, as it says that:
which directly contradicts @xabbuh's argument:
and the Voter class is opinionated about what should happen:
IMHO it was an unfortunate design decision to allow multiple values in the first place (forcing
isGranted('X') || isGranted('Y')
orisGranted('X') && isGranted('Y')
would have probably been much less confusing), now one will always wonder what the behaviour is should they pass multiple values, and going to the docs or the source code will only make things more confusing, until they're all in sync on this point.Now, to make things right without breaking BC, I would recommend to apply the "less bad" fix: