Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/stale@v7
- uses: actions/stale@v8
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
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'
Expand Down
4 changes: 2 additions & 2 deletions docs.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generate the HTML output.
FROM markstory/cakephp-docs-builder as builder
FROM ghcr.io/cakephp/docs-builder as builder

COPY docs /data/docs

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

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

# Configure search index script
ENV LANGS="en es fr ja"
Expand Down
2 changes: 1 addition & 1 deletion docs/en/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Then make your application's ``middleware()`` method look like::
->add(new BodyParserMiddleware())

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

// Add the AuthorizationMiddleware *after* routing, body parser
// and authentication middleware.
Expand Down
8 changes: 6 additions & 2 deletions docs/en/policies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Any return value that is not ``true`` or a ``ResultInterface`` object will be
considered a failure.

Policy Scopes
-------------
=============

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

Policy Pre-conditions
---------------------
=====================

In some policies you may wish to apply common checks across all operations in
a policy. This is useful when you need to deny all actions to the provided
Expand Down Expand Up @@ -131,3 +131,7 @@ Before hooks are expected to return one of three values:
- ``false`` The user is not allowed to proceed with the action.
- ``null`` The before hook did not make a decision, and the authorization method
will be invoked.

Applying Policies
-----------------
See :ref:`applying-policy-scopes` for how to apply policies in your controller actions.
19 changes: 18 additions & 1 deletion tests/TestCase/AuthorizationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function testAuthorizationCheckedWithCan()
$this->assertTrue($service->authorizationChecked());
}

public function testCallingMagicCallPolicy()
public function testCallingMagicCanCallPolicy()
{
$resolver = new MapResolver([
Article::class => MagicCallPolicy::class,
Expand All @@ -203,6 +203,23 @@ public function testCallingMagicCallPolicy()
$this->assertFalse($service->can($user, 'cantDoThis', $article));
}

public function testCallingMagicScopeCallPolicy()
{
$resolver = new MapResolver([
Article::class => MagicCallPolicy::class,
]);
$service = new AuthorizationService($resolver);

$user = new IdentityDecorator($service, [
'id' => 9,
'role' => 'admin',
]);

$article = new Article();
$this->assertTrue($service->applyScope($user, 'this', $article));
$this->assertFalse($service->applyScope($user, 'somethingElse', $article));
}

public function testAuthorizationCheckedWithApplyScope()
{
$resolver = new MapResolver([
Expand Down
5 changes: 5 additions & 0 deletions tests/TestCase/Command/PolicyCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class PolicyCommandTest extends TestCase
use ConsoleIntegrationTestTrait;
use StringCompareTrait;

/**
* @var string
*/
protected $comparisonDir = '';

/**
* @var string
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/TestCase/Controller/Component/AuthorizationComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
*/
class AuthorizationComponentTest extends TestCase
{
/**
* @var \Cake\Controller\Controller
*/
protected $Controller;

/**
* @var \Cake\Controller\ComponentRegistry
*/
protected $ComponentRegistry;

/**
* @var \Authorization\Controller\Component\AuthorizationComponent
*/
Expand Down
4 changes: 4 additions & 0 deletions tests/test_app/TestApp/Policy/MagicCallPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function __call($name, $arguments)
return true;
}

if ($name === 'scopeThis') {
return true;
}

return false;
}
}