私はケーキ2.xを使用しています
AuthとAclコンポーネントも使用しています。
ログインしているすべてのユーザーに単一のアクションを許可したい。
しかし、これにより、このコードを数回記述してから、initDBを実行することになります。
public function initDB() {
$group = $this->User->Group;
//Allow ADMINISTRATORS to everything
$group->id = ADMINISTRATORS;
$this->Acl->allow($group, 'controllers');
//allow SALES_MANAGERS to upload SOW file at `products`
$group->id = SALES_MANAGERS;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Pages');
//allow SOLUTION_ARCHITECTS to only add and edit on posts and widgets
$group->id = SOLUTION_ARCHITECTS;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Pages');
//allow IMPLEMENTATION_MANAGERS to only add and edit on posts and widgets
$group->id = IMPLEMENTATION_MANAGERS;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Pages');
//we add an exit to avoid an ugly "missing views" error message
echo "all done";
exit;
}
お気づきのとおり、Pagesをさまざまなグループすべてに許可する必要がありました。
私は、Auth-> allowに似た単純な方法を好みます。これにより、ログインしているすべてのユーザーに対して常に特定のアクションを実行できます。
ありがとうございました。
アップデート
これが私の回避策です。より良い解決策はありますか?
public function initDB() {
$group = $this->User->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->_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->User->Group;
foreach ($groups as $id) {
$group->id = $id;
foreach($actions as $action) {
$this->Acl->allow($group, $action);
}
}
}