Skip to content
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] add & update doc entries on AbstractVoter implementation #4257

Closed
wants to merge 5 commits into from
Closed

[Security] add & update doc entries on AbstractVoter implementation #4257

wants to merge 5 commits into from

Conversation

inoryy
Copy link
Contributor

@inoryy inoryy commented Sep 23, 2014

Q A
Doc fix? no
New docs? yes (related to symfony/symfony#11183)
Applies to 2.6
Fixed tickets -

.. include:: /cookbook/security/voter_interface.rst.inc

The basic functionality covering common use cases is provided
and end developer is expected to implement the abstract methods.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end developer does not convey end user, either settle for end user or just developer

@xabbuh xabbuh added the On hold label Sep 23, 2014
fabpot added a commit to symfony/symfony that referenced this pull request Sep 23, 2014
This PR was squashed before being merged into the 2.6-dev branch (closes #11183).

Discussion
----------

[Security] add an AbstractVoter implementation

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT
| Doc PR        | symfony/symfony-docs#4257

The idea is to reduce boilerplate required to create custom Voter, doing most of the work for the developer and guiding him on the path by providing simple requirements via abstract methods that will be called by the AbstractVoter.

P.S. This is meant to be a [DX Initiative](https://github.com/symfony/symfony/issues?labels=DX&state=open) improvement.

Commits
-------

d3bafc6 [Security] add an AbstractVoter implementation
@@ -61,84 +62,45 @@ edit a particular object. Here's an example implementation:
// src/Acme/DemoBundle/Security/Authorization/Voter/PostVoter.php
namespace Acme\DemoBundle\Security\Authorization\Voter;

use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to import this TokenInterface class when using the new AbstractVoter?

@inoryy
Copy link
Contributor Author

inoryy commented Sep 30, 2014

@javiereguiluz @cordoval should be fixed now

@@ -92,6 +92,13 @@ the security layer. This can be done easily through the service container.
methods in your implementation of the ``vote()`` method and return ``ACCESS_ABSTAIN``
if your voter does not support the class or attribute.


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should actually use the AbstractVoter in this example. Other than mentioning that VoterInterface exists and you can just implement it, I don't see any disadvantage to always using AbstractVoter. Agree?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this particular use case VoterInterface is actually the better choice.
AbstractVoter assumes you know exactly what attributes and classes you want to match, whereas in this situation we're meant to allow everything through (look at how supportsAttribute and supportsClass are defined).

@weaverryan
Copy link
Member

@inoryy I just left some comments - sorry if it was a lot - this is just an under-appreciated feature that got a lot better!

@wouterj
Copy link
Member

wouterj commented Oct 31, 2014

@inoryy can you please apply @weaverryan 's comments? (btw, it also needs a rebase)

@weaverryan weaverryan added this to the 2.6 milestone Dec 31, 2014
@xabbuh
Copy link
Member

xabbuh commented Dec 31, 2014

@inoryy Do you have time to finish this? Anyway, I wish you a happy new year. 🎉

@inoryy
Copy link
Contributor Author

inoryy commented Jan 31, 2015

@weaverryan @wouterj @xabbuh should be done, sorry for the long delay


The :method:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\AbstractVoter::getSupportedClasses`
method tells Symfony that your voter should be called whenever an object of one of the given classes
is passed to `isGranted` For example, if you return ['\Acme\DemoBundle\Model\Product'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double-ticks around isGranted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the ['Acme\DemoBundle... to be AppBundle\Model\Product and use a full array( there instead of [.

Symfony will call your voter when a `Product` object is passed to `isGranted`.

The :method:`Symfony\\Component\\Security\\Core\\Authorization\\Voter\\AbstractVoter::getSupportedAttributes`
method tells Symfony that your voter should be called whenever one of these strings is passes as the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings is passed

@weaverryan
Copy link
Member

Thanks Roman - one last round of changes, I promise :)

@wouterj
Copy link
Member

wouterj commented May 15, 2015

Hi @inoryy. Ryan did another (last) round of comments on your PR some weeks ago. Do you have some time to update the PR, so we can merge it? If you don't, there is a doc sprint day on May 23rd were we can help you (or someone else can take the PR over and finish it).

Thanks for the patience!

@inoryy
Copy link
Contributor Author

inoryy commented May 15, 2015

@wouterj hello, unfortunately I'm swamped with studies right now, so yes - please do take over. Thanks!

@xabbuh xabbuh added the actionable Clear and specific issues ready for anyone to take them. label May 16, 2015
@javiereguiluz
Copy link
Member

This PR is being finished in #5423

@weaverryan
Copy link
Member

Thanks Javier!

@weaverryan weaverryan closed this Jun 22, 2015
weaverryan added a commit that referenced this pull request Jun 30, 2015
…plementation (Inoryy, javiereguiluz)

This PR was submitted for the 2.7 branch but it was merged into the 2.6 branch instead (closes #5423).

Discussion
----------

[Security] add & update doc entries on AbstractVoter implementation

| Q             | A
| ------------- | ---
| Doc fix?      | no
| New docs?     | yes (symfony/symfony#11183)
| Applies to    | 2.6+
| Fixed tickets | -

This PR finishes #4257.

Commits
-------

95537d3 Added a link to the AbstractVoter cookbook
73bd908 Fixed some typos
60643f0 Removed the abstract_voter.rst.inc file
59c60b1 add fixes to abstract_voter include file
e9053c0 fix problems pointed out by @javiereguiluz and @cordoval
968cb65 add & update doc entries on AbstractVoter implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable Clear and specific issues ready for anyone to take them. Status: Needs Work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants