From fe61086721b2848d343a67c9261773b7bd83e565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gonz=C3=A1lez?= Date: Thu, 1 Aug 2019 11:42:31 +0100 Subject: [PATCH] #47 fix callable plugin name --- src/Rbac/Rbac.php | 2 +- tests/TestCase/Rbac/RbacTest.php | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Rbac/Rbac.php b/src/Rbac/Rbac.php index 3c013f0..6e51013 100644 --- a/src/Rbac/Rbac.php +++ b/src/Rbac/Rbac.php @@ -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); diff --git a/tests/TestCase/Rbac/RbacTest.php b/tests/TestCase/Rbac/RbacTest.php index d04c4ed..1c21fe7 100644 --- a/tests/TestCase/Rbac/RbacTest.php +++ b/tests/TestCase/Rbac/RbacTest.php @@ -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, + ], ]; }