S
S
Sergey2017-02-26 22:51:47
Yii
Sergey, 2017-02-26 22:51:47

How to setup AccessControl for dektrium/yii2-user module?

The dektrium/yii2-user module has an admins config in the array of which we specify a list of users who have access to the section for working with users. I don't want to hard code users and give access to the section for the admins role.
This role (admins) has been added to the manager user. I have added as access behavior for the user module, but I keep getting 403. But I only get 403 in this module! Below is the admin module, which contains almost the same configs and which allows the manager to access the admin routes. What could be the problem?

'modules' => [
        'user' => [
            'class' => 'dektrium\user\Module',
//            'admins' => ['manager'],
            'enableUnconfirmedLogin' => true,
//            'urlPrefix' => '',
//            'urlRules' => [
                //'admin/users/<action:>' => 'admin/<action>',
//            ],
            'controllerMap' => [
                'admin' => [
                    'class' => 'dektrium\user\controllers\AdminController',
                    'layout' => '@app/modules/admin/views/layouts/admin',
                ],
            ],
            'as access' => [
                'class' => yii\filters\AccessControl::className(),
                'ruleConfig' => [
                    'class' => dektrium\user\filters\AccessRule::className(),
                ],
                'rules' => [
                    [
                        'allow' => true,
                        'roles' => ['admins']
                    ]
                ]
            ]
        ],
        'admin' => [
            'class' => 'app\modules\admin\Module',
            'layout' => 'admin',
            'as access' => [
                'class' => yii\filters\AccessControl::className(),
                'rules' => [
                    [
                        'allow' => true,
                        'roles' => ['admins']
                    ]
                ]
            ]
        ],
        'rbac' => [
            'class' => 'dektrium\rbac\RbacWebModule',
            'controllerMap' => [
                'role' => [
                    'class' => 'dektrium\rbac\controllers\RoleController',
                    'layout' => '@app/modules/admin/views/layouts/admin',
                ],
                'permission' => [
                    'class' => 'dektrium\rbac\controllers\PermissionController',
                    'layout' => '@app/modules/admin/views/layouts/admin',
                ],
                'rule' => [
                    'class' => 'dektrium\rbac\controllers\RuleController',
                    'layout' => '@app/modules/admin/views/layouts/admin',
                ],
            ],
        ],
    ],

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2017-02-26
@zeyser

It turned out there is adminPermission for this)) https://github.com/dektrium/yii2-user/pull/600

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question