-
Notifications
You must be signed in to change notification settings - Fork 46
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
3.x: add ability to add multiple optional parameters to table scopes #226
Changes from 3 commits
0ba427b
c6aa5e3
2dea1b1
10051f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
3.0 Migration Guide | ||
################### | ||
|
||
Authorization 3.0 contains new features and a few breaking changes. | ||
|
||
Breaking Changes | ||
================ | ||
|
||
The following interfaces now have appropriate parameter and return types added: | ||
|
||
- ``AuthorizationServiceInterface`` | ||
- ``IdentityInterface`` | ||
- ``BeforePolicyInterface`` | ||
- ``RequestPolicyInterface.php`` | ||
- ``ResolverInterface`` | ||
|
||
Multiple optional arguments for ``applyScope`` | ||
---------------------------------------------- | ||
|
||
``IdentityInterface::applyScope`` as well as ``AuthorizationServiceInterface::applyScope`` | ||
allow multiple optional arguments to be added. | ||
|
||
Removed methods | ||
--------------- | ||
|
||
- ``AuthorizationService::resultTypeCheck`` - has been replaced with an ``assert()`` call | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,13 @@ | |
use Authorization\Policy\BeforePolicyInterface; | ||
use Authorization\Policy\Exception\MissingMethodException; | ||
use Authorization\Policy\MapResolver; | ||
use Authorization\Policy\OrmResolver; | ||
use Authorization\Policy\Result; | ||
use Authorization\Policy\ResultInterface; | ||
use Cake\Datasource\QueryInterface; | ||
use Cake\TestSuite\TestCase; | ||
use TestApp\Model\Entity\Article; | ||
use TestApp\Model\Table\ArticlesTable; | ||
use TestApp\Policy\ArticlePolicy; | ||
use TestApp\Policy\MagicCallPolicy; | ||
|
||
|
@@ -173,6 +176,33 @@ public function testApplyScopeMethodMissing() | |
$result = $service->applyScope($user, 'nope', $article); | ||
} | ||
|
||
public function testApplyScopeAdditionalArguments() | ||
{ | ||
$service = new AuthorizationService(new OrmResolver()); | ||
$user = new IdentityDecorator($service, [ | ||
'id' => 9, | ||
'role' => 'admin', | ||
]); | ||
|
||
$articles = new ArticlesTable(); | ||
$query = $this->createMock(QueryInterface::class); | ||
$query->method('getRepository') | ||
->willReturn($articles); | ||
|
||
$query->expects($this->once()) | ||
->method('where') | ||
->with([ | ||
'identity_id' => 9, | ||
'firstArg' => 'first argument', | ||
'secondArg' => false, | ||
]) | ||
->willReturn($query); | ||
$result = $service->applyScope($user, 'additionalArguments', $query, 'first argument', false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will these changes also enable the use of named parameters? eg. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a test which proves it works 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yay! |
||
|
||
$this->assertInstanceOf(QueryInterface::class, $result); | ||
$this->assertSame($query, $result); | ||
} | ||
|
||
public function testBeforeFalse() | ||
{ | ||
$entity = new Article(); | ||
|
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.
This will be a breaking change as user-land code will have implemented this interface. We should add this to the documentation/migration guide.
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.
Indeed. I was just curious if you guys even like this idea or not 😄
The first version of the 3.0 migration guide has been added with the major changes I have seen via looking at 2.x...3.x-scope-params