Skip to content

Commit

Permalink
allow multiple roles for a rule to be specified as string or array
Browse files Browse the repository at this point in the history
  • Loading branch information
0x20h committed Jan 13, 2012
1 parent ef5eead commit 95a41af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
14 changes: 10 additions & 4 deletions lib/Cake/Controller/Component/Acl/PhpAcl.php
Expand Up @@ -300,13 +300,19 @@ public function build(array $allow, array $deny = array()) {
$tree = array();
$root = &$tree;

foreach ($allow as $dotPath => $commaSeparatedAros) {
$aros = array_map('trim', explode(',', $commaSeparatedAros));
foreach ($allow as $dotPath => $aros) {
if (is_string($aros)) {
$aros = array_map('trim', explode(',', $aros));
}

$this->access($aros, $dotPath, null, 'allow');
}

foreach ($deny as $dotPath => $commaSeparatedAros) {
$aros = array_map('trim', explode(',', $commaSeparatedAros));
foreach ($deny as $dotPath => $aros) {
if (is_string($aros)) {
$aros = array_map('trim', explode(',', $aros));
}

$this->access($aros, $dotPath, null, 'deny');
}
}
Expand Down
12 changes: 8 additions & 4 deletions lib/Cake/Test/test_app/Config/acl.php
Expand Up @@ -20,7 +20,7 @@


// -------------------------------------
// AROs
// Roles
// -------------------------------------
$config['roles'] = array(
'Role/admin' => null,
Expand All @@ -30,6 +30,7 @@
'Role/sales' => null,
'Role/data_analyst' => 'Role/data_acquirer, Role/database_manager',
'Role/reports' => 'Role/data_analyst',
// allow inherited roles to be defined as an array or comma separated list
'Role/manager' => array(
'Role/accounting',
'Role/sales',
Expand All @@ -49,7 +50,7 @@
);

//-------------------------------------
// ACOs
// Rules
//-------------------------------------
$config['rules']['allow'] = array(
'/*' => 'Role/admin',
Expand All @@ -67,6 +68,9 @@
);
$config['rules']['deny'] = array(
// accountants and sales should not delete anything
'/controllers/*/delete' => 'Role/sales, Role/accounting',
'/controllers/db/drop' => 'User/db_manager_2',
'/controllers/*/delete' => array(
'Role/sales',
'Role/accounting'
),
'/controllers/db/drop' => 'User/db_manager_2',
);

0 comments on commit 95a41af

Please sign in to comment.