0

私はケーキ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);
        }
    }
}
4

1 に答える 1

0

グループを階層的に作成すれば可能です。ツリーとして機能するグループ構造を作成し、次のようにデータを構造化します。

  • ユーザー
    • 管理者
    • マネージャー
      • セールスマネージャー
      • 実装マネージャー
    • 開発者
      • ソリューション アーキテクト

この構造では、親 ARO に割り当てられたアクセス許可はすべての子孫に継承されます。親の動作を設定する方法については、http: //book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-managed-application/simple-acl-managed-application を参照してください。 html#acts-as-a-requester

于 2013-02-25T04:04:18.743 に答える