Note that there are some explanatory texts on larger screens.

plurals
  1. POcakephp: single code line or block to allow all authenticated users to action
    primarykey
    data
    text
    <p>I am using cake 2.x</p> <p>I am also using Auth and Acl Component.</p> <p>I want to allow a single action to all the logged in users.</p> <p>But this results in me writing this code several times and then running the initDB.</p> <pre><code>public function initDB() { $group = $this-&gt;User-&gt;Group; //Allow ADMINISTRATORS to everything $group-&gt;id = ADMINISTRATORS; $this-&gt;Acl-&gt;allow($group, 'controllers'); //allow SALES_MANAGERS to upload SOW file at `products` $group-&gt;id = SALES_MANAGERS; $this-&gt;Acl-&gt;deny($group, 'controllers'); $this-&gt;Acl-&gt;allow($group, 'controllers/Pages'); //allow SOLUTION_ARCHITECTS to only add and edit on posts and widgets $group-&gt;id = SOLUTION_ARCHITECTS; $this-&gt;Acl-&gt;deny($group, 'controllers'); $this-&gt;Acl-&gt;allow($group, 'controllers/Pages'); //allow IMPLEMENTATION_MANAGERS to only add and edit on posts and widgets $group-&gt;id = IMPLEMENTATION_MANAGERS; $this-&gt;Acl-&gt;deny($group, 'controllers'); $this-&gt;Acl-&gt;allow($group, 'controllers/Pages'); //we add an exit to avoid an ugly "missing views" error message echo "all done"; exit; } </code></pre> <p>As you noticed I needed to allow Pages to all the various groups.</p> <p>I prefer a simple way similar to Auth->allow that allows certain actions always to ALL logged in users.</p> <p>Thank you.</p> <p><strong>UPDATE</strong></p> <p>THis is my workaround. Any better solution?</p> <pre><code>public function initDB() { $group = $this-&gt;User-&gt;Group; ... // didn't want to repeat this part which is same as above. // we allow all groups the following actions $onlyForLoggedInUsers = array( 'controllers/Users/logout', 'controllers/Pages', ); $this-&gt;_allowAllGroupsThisAction($onlyForLoggedInUsers); //we add an exit to avoid an ugly "missing views" error message echo "all done"; exit; } protected function _allowAllGroupsThisAction($actions) { $groups = array(SALES_MANAGERS, SOLUTION_ARCHITECTS, IMPLEMENTATION_MANAGERS); $actions = (array)$actions; $group = $this-&gt;User-&gt;Group; foreach ($groups as $id) { $group-&gt;id = $id; foreach($actions as $action) { $this-&gt;Acl-&gt;allow($group, $action); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload