Skip to content

Commit 464eddf

Browse files
authored
Merge pull request #243 from cakephp/3.x-merge
merge 2.x => 3.x
2 parents f215527 + a82d200 commit 464eddf

File tree

8 files changed

+47
-7
lines changed

8 files changed

+47
-7
lines changed

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- uses: actions/stale@v7
19+
- uses: actions/stale@v8
2020
with:
2121
repo-token: ${{ secrets.GITHUB_TOKEN }}
2222
stale-issue-message: 'This issue is stale because it has been open for 120 days with no activity. Remove the `stale` label or comment or this will be closed in 15 days'

docs.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Generate the HTML output.
2-
FROM markstory/cakephp-docs-builder as builder
2+
FROM ghcr.io/cakephp/docs-builder as builder
33

44
COPY docs /data/docs
55

@@ -10,7 +10,7 @@ RUN cd /data/docs-builder && \
1010
make website LANGS="$LANGS" SOURCE=/data/docs DEST=/data/website
1111

1212
# Build a small nginx container with just the static site in it.
13-
FROM markstory/cakephp-docs-builder:runtime as runtime
13+
FROM ghcr.io/cakephp/docs-builder:runtime as runtime
1414

1515
# Configure search index script
1616
ENV LANGS="en es fr ja"

docs/en/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Then make your application's ``middleware()`` method look like::
5050
->add(new BodyParserMiddleware())
5151

5252
// If you are using Authentication it should be *before* Authorization.
53-
->add(new AuthenticationMiddleware($this));
53+
->add(new AuthenticationMiddleware($this))
5454

5555
// Add the AuthorizationMiddleware *after* routing, body parser
5656
// and authentication middleware.

docs/en/policies.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Any return value that is not ``true`` or a ``ResultInterface`` object will be
8585
considered a failure.
8686

8787
Policy Scopes
88-
-------------
88+
=============
8989

9090
In addition to policies being able to define pass/fail authorization checks,
9191
they can also define 'scopes'. Scope methods allow you to modify another object
@@ -103,7 +103,7 @@ a list view to the current user::
103103
}
104104

105105
Policy Pre-conditions
106-
---------------------
106+
=====================
107107

108108
In some policies you may wish to apply common checks across all operations in
109109
a policy. This is useful when you need to deny all actions to the provided
@@ -131,3 +131,7 @@ Before hooks are expected to return one of three values:
131131
- ``false`` The user is not allowed to proceed with the action.
132132
- ``null`` The before hook did not make a decision, and the authorization method
133133
will be invoked.
134+
135+
Applying Policies
136+
-----------------
137+
See :ref:`applying-policy-scopes` for how to apply policies in your controller actions.

tests/TestCase/AuthorizationServiceTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function testAuthorizationCheckedWithCan()
186186
$this->assertTrue($service->authorizationChecked());
187187
}
188188

189-
public function testCallingMagicCallPolicy()
189+
public function testCallingMagicCanCallPolicy()
190190
{
191191
$resolver = new MapResolver([
192192
Article::class => MagicCallPolicy::class,
@@ -203,6 +203,23 @@ public function testCallingMagicCallPolicy()
203203
$this->assertFalse($service->can($user, 'cantDoThis', $article));
204204
}
205205

206+
public function testCallingMagicScopeCallPolicy()
207+
{
208+
$resolver = new MapResolver([
209+
Article::class => MagicCallPolicy::class,
210+
]);
211+
$service = new AuthorizationService($resolver);
212+
213+
$user = new IdentityDecorator($service, [
214+
'id' => 9,
215+
'role' => 'admin',
216+
]);
217+
218+
$article = new Article();
219+
$this->assertTrue($service->applyScope($user, 'this', $article));
220+
$this->assertFalse($service->applyScope($user, 'somethingElse', $article));
221+
}
222+
206223
public function testAuthorizationCheckedWithApplyScope()
207224
{
208225
$resolver = new MapResolver([

tests/TestCase/Command/PolicyCommandTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class PolicyCommandTest extends TestCase
3030
use ConsoleIntegrationTestTrait;
3131
use StringCompareTrait;
3232

33+
/**
34+
* @var string
35+
*/
36+
protected $comparisonDir = '';
37+
3338
/**
3439
* @var string
3540
*/

tests/TestCase/Controller/Component/AuthorizationComponentTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
*/
4444
class AuthorizationComponentTest extends TestCase
4545
{
46+
/**
47+
* @var \Cake\Controller\Controller
48+
*/
49+
protected $Controller;
50+
51+
/**
52+
* @var \Cake\Controller\ComponentRegistry
53+
*/
54+
protected $ComponentRegistry;
55+
4656
/**
4757
* @var \Authorization\Controller\Component\AuthorizationComponent
4858
*/

tests/test_app/TestApp/Policy/MagicCallPolicy.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public function __call($name, $arguments)
2121
return true;
2222
}
2323

24+
if ($name === 'scopeThis') {
25+
return true;
26+
}
27+
2428
return false;
2529
}
2630
}

0 commit comments

Comments
 (0)