Skip to content

Commit

Permalink
Merge pull request #48 from CakeDC/feature/47-fix-callable-plugin-name
Browse files Browse the repository at this point in the history
Refs #47 fix callable plugin name
  • Loading branch information
rochamarcelo committed Aug 26, 2019
2 parents d2a26fc + ed5bdac commit e494d68
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Rbac/Rbac.php
Expand Up @@ -171,7 +171,7 @@ protected function _matchPermission(array $permission, array $user, $role, Serve
$key = ltrim($key, '*');
}

if (is_callable($value)) {
if (!is_string($value) && is_callable($value)) {
$return = (bool)call_user_func($value, $user, $role, $request);
} elseif ($value instanceof Rule) {
$return = (bool)$value->allowed($user, $role, $request);
Expand Down
23 changes: 23 additions & 0 deletions tests/TestCase/Rbac/RbacTest.php
Expand Up @@ -1099,6 +1099,29 @@ function () {
//expected
false,
],
'plugin-name-matches-callable-function' => [
//permissions
[[
'plugin' => 'Ord',
'controller' => 'Tests',
'action' => 'test',
'role' => 'admin',
]],
//user
[
'id' => 1,
'username' => 'luke',
'role' => 'admin',
],
//request
[
'plugin' => 'Ord',
'controller' => 'Tests',
'action' => 'test'
],
//expected
true,
],
'named-route' => [
//permissions
[[
Expand Down
5 changes: 5 additions & 0 deletions tests/config/routes.php
Expand Up @@ -72,6 +72,11 @@
'controller' => 'Tests',
'action' => 'one',
]);
$routes->connect('/ord/tests/test', [
'plugin' => 'Ord',
'controller' => 'Tests',
'action' => 'test',
]);

$routes->fallbacks(\Cake\Routing\Route\DashedRoute::class);

Expand Down

0 comments on commit e494d68

Please sign in to comment.