Skip to content

Abstract voter tweaks #15921

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

Merged
merged 1 commit into from
Sep 27, 2015
Merged

Abstract voter tweaks #15921

merged 1 commit into from
Sep 27, 2015

Conversation

weaverryan
Copy link
Member

Q A
Bug fix? yes (a little)
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

Based on suggestions from stof in #15870, this simplifies the BC and deprecation throwing code. This also adds a BadMethodCallException in case the user doesn't override isGranted or voteOnAttribute, because that's just plain wrong (as is calling isGranted() on the parent class directly, since that was formerly abstract).

@wouterj
Copy link
Member

wouterj commented Sep 26, 2015

Duplicate of #15886 ?

@weaverryan
Copy link
Member Author

@wouterj it is - do you want to update your PR - i.e. add the trigger_error and remove the reflection stuff? I'm not convinced whether my BadMethodCallException is needed or not.

@weaverryan weaverryan force-pushed the abstract-voter-tweaks branch from 528e2c6 to 5961edb Compare September 26, 2015 16:06
@stof
Copy link
Member

stof commented Sep 26, 2015

👍

Status: reviewed

@weaverryan the BadMethodCallException is a good idea: we will make voteOnAttribute abstract in 3.0 (we cannot yet in 2.8 for BC), so not overwriting anything must fail loudly

@@ -191,7 +178,8 @@ protected function getSupportedAttributes()
*/
protected function isGranted($attribute, $object, $user = null)
{
return false;
// forces isGranted() or voteOnAttribute() to be overridden
throw new \BadMethodCallException(sprintf('You must override either the voteOnAttribute() or isGranted() (deprecated) method in "%s"', get_class($this)));
Copy link
Member

Choose a reason for hiding this comment

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

we can only mention voteOnAttribute() here, can't we? No need to talk about overriding a method that shouldn't be used anymore

Copy link
Member

Choose a reason for hiding this comment

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

agreed

@wouterj
Copy link
Member

wouterj commented Sep 26, 2015

@weaverryan I think it's easier to finish this PR, I've closed mine.

@weaverryan
Copy link
Member Author

Great - PR updated - thanks!

@@ -191,7 +178,8 @@ protected function getSupportedAttributes()
*/
protected function isGranted($attribute, $object, $user = null)
{
return false;
// forces isGranted() or voteOnAttribute() to be overridden
throw new \BadMethodCallException(sprintf('You must override the voteOnAttribute() method in "%s"', get_class($this)));
Copy link
Member

Choose a reason for hiding this comment

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

very minor: All exceptions end with a full stop in Syfmony

@wouterj
Copy link
Member

wouterj commented Sep 26, 2015

I can't make any sense of the AbstractVoterTest. This is how I implemented it in a PR merged yesterday, while the code shown in the branch now (and in your PR) is just a copy of the test in a bad location... (seems like something went wrong in the merge: 6f7aae9)

@weaverryan
Copy link
Member Author

@wouterj I don't see it. In this PR, the 2.8 branch and your linked PR, it all looks like its in .../Security/Core/Tests/...

@weaverryan weaverryan force-pushed the abstract-voter-tweaks branch from bc7f342 to 54811ec Compare September 26, 2015 18:23
@wouterj
Copy link
Member

wouterj commented Sep 26, 2015

@weaverryan yeah, but take a look at the contents. The 2.8 branch (and your PR) has the contents of the tests that was in Security/Tests/Core (wrongly), while my linked PR has completely different tests

@weaverryan
Copy link
Member Author

@wouterj Ah, yep - I see the same thing (I thought the path was the problem). You should create a new PR to fix this, then I can rebase after your merged. You better to do that since that's your test code that needs to be re-added.

@Tobion
Copy link
Contributor

Tobion commented Sep 26, 2015

As I explained in #15886 (comment) here won't be any deprecation message for voters that don't support any attribute even though they will break in 3.0

@weaverryan
Copy link
Member Author

@Tobion good point - I'd vote to revert back to the Reflection stuff then - since the problem is with the class itself (not how some code in the class behaves), so it would be most awesome if we added a deprecation warning as soon as the problematic class is used.

@stof
Copy link
Member

stof commented Sep 26, 2015

@weaverryan can you rebase this branch so that tests of the Security component can actually run ? Your PR was opened at the time where the testsuite of the Security component was triggering a fatal error before reaching voters.

@weaverryan weaverryan force-pushed the abstract-voter-tweaks branch from 54811ec to c03f5c2 Compare September 26, 2015 21:07
@weaverryan
Copy link
Member Author

done - and thanks for fixing those tests

@wouterj
Copy link
Member

wouterj commented Sep 26, 2015

@weaverryan see #15932 for fixing the tests

@fabpot
Copy link
Member

fabpot commented Sep 27, 2015

Thank you @weaverryan.

@fabpot fabpot merged commit c03f5c2 into symfony:2.8 Sep 27, 2015
fabpot added a commit that referenced this pull request Sep 27, 2015
This PR was merged into the 2.8 branch.

Discussion
----------

Abstract voter tweaks

| Q             | A
| ------------- | ---
| Bug fix?      | yes (a little)
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Based on suggestions from stof in #15870, this simplifies the BC and deprecation throwing code. This also adds a BadMethodCallException in case the user doesn't override `isGranted` *or* `voteOnAttribute`, because that's just plain wrong (as is calling `isGranted()` on the parent class directly, since that was formerly abstract).

Commits
-------

c03f5c2 Massively simplifying the BC and deprecated-throwing code thanks to suggestions by stof in #15870
@weaverryan weaverryan deleted the abstract-voter-tweaks branch September 27, 2015 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants