There are two roles: admin - has access to all admin settings, content manager - has access only to two admin sections
I created two roles: admin and Content manager. Content manager gave permisheny two sections.
<?php namespace console\controllers; use common\models\User; use Yii; use yii\console\Controller; class RbacController extends Controller { public function actionInit() { $auth = Yii::$app->authManager; //CREATE CONTENT MANAGER ROLE $contentManagerRole = Yii::$app->authManager->createRole('content_manager'); $contentManagerRole->description = 'Content manager'; //CREATE ADMIN ROLE $adminRole = Yii::$app->authManager->createRole('admin'); $adminRole->description = 'Administrator'; $auth->add($adminRole); //COMPLAIN PERMISSIONS $indexComplain = $auth->createPermission('complain-index'); $viewComplain = $auth->createPermission('complain-view'); $createComplain = $auth->createPermission('complain-create'); $updateComplain = $auth->createPermission('complain-update'); $deleteComplain = $auth->createPermission('complain-delete'); //ANNOUNCEMENT PERMISSIONS $indexAnnouncement = $auth->createPermission('announcement-index'); $viewAnnouncement = $auth->createPermission('announcement-view'); $createAnnouncement = $auth->createPermission('announcement-create'); $updateAnnouncement = $auth->createPermission('announcement-update'); $deleteAnnouncement = $auth->createPermission('announcement-delete'); $auth->add($indexComplain); $auth->add($viewComplain); $auth->add($createComplain); $auth->add($updateComplain); $auth->add($deleteComplain); $auth->add($indexAnnouncement); $auth->add($viewAnnouncement); $auth->add($createAnnouncement); $auth->add($updateAnnouncement); $auth->add($deleteAnnouncement); $auth->add($contentManagerRole); //ADDING PERMISSIONS IN ROLE CONTENT MANAGER $auth->addChild($contentManagerRole, $indexComplain); $auth->addChild($contentManagerRole, $viewComplain); $auth->addChild($contentManagerRole, $createComplain); $auth->addChild($contentManagerRole, $updateComplain); $auth->addChild($contentManagerRole, $deleteComplain); $auth->addChild($contentManagerRole, $indexAnnouncement); $auth->addChild($contentManagerRole, $viewAnnouncement); $auth->addChild($contentManagerRole, $createAnnouncement); $auth->addChild($contentManagerRole, $updateAnnouncement); $auth->addChild($contentManagerRole, $deleteAnnouncement); $auth->addChild($adminRole, $contentManagerRole); $auth->assign($contentManagerRole, User::getContentManagerUser()->id); $auth->assign($adminRole, User::getAdminUser()->id); } } In the config put ACF
'as beforeRequest' => [ 'class' => 'yii\filters\AccessControl', 'rules' => [ //COMMON [ 'actions' => ['logout', 'index'], 'allow' => true, 'roles' => ['admin', 'content_manager'], ], //ADMIN [ 'allow' => true, 'roles' => ['admin'], ], //CONTENT MANAGER [ 'allow' => true, 'roles' => ['content_manager'], ], [ 'actions' => ['login'], 'allow' => true, 'roles' => ['?'] ], ], ], How can I write a rule under which the content manager can go to the sections to which I gave permisenes, to the remaining 403.
In controllers with 2 sections added access of this type
'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'actions' => ['index'], 'roles' => ['complain-index'], ], [ 'allow' => true, 'actions' => ['view'], 'roles' => ['complain-view'], ], [ 'allow' => true, 'actions' => ['create'], 'roles' => ['complain-create'], ], [ 'allow' => true, 'actions' => ['update'], 'roles' => ['complain-update'], ], [ 'allow' => true, 'actions' => ['delete'], 'roles' => ['complain-delete'], ], ], ],