RBAC for Yii 2.0
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist anli/yii2-rbac "*"
or add
"anli/yii2-rbac": "*"
to the require section of your composer.json
file.
Add to the modules
section of config/web.php
and config/console.php
file with:
'rbac' => [
'class' => 'anli\rbac\Module',
'initialRoles' => [
'user',
'manager',
'admin',
],
],
Add to the components
section of config/web.php
and config/console.php
file with:
'authManager' => [
'class' => 'yii\rbac\DbManager',
'defaultRoles' => [
'user',
'manager',
'admin',
],
],
Run the yii2 RBAC migrations files:
php yii migrate/up --migrationPath=@yii/rbac/migrations
php yii migrate/up --migrationPath=@vendor/anli/rbac/migrations
Add to the config/console.php
file with:
'controllerMap' => [
'rbac' => 'anli\rbac\commands\RbacController'
],
Run the RBAC initialization command:
php yii rbac/init
Add to your controller behavior
section with:
use yii\filters\AccessControl;
...
return [
...
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => [
'import', 'export', 'delete-all',
'index', 'view', 'update', 'create', 'delete',
'name-list',
],
'allow' => true,
'roles' => ['@'],
'matchCallback' => function ($rule, $action) {
return Yii::$app->user->can('admin');
}
],
[
'actions' => [
'name-list',
],
'allow' => true,
'roles' => ['@'],
],
],
],
];
To create the link to update the roles for the login tenant:
Html::a(['/rbac/user-role/'])
chg
Changed user role index pagebug
Fixed bug to delete user role correctlychg
Refactor user querychg
Changed role select2 widget in user role to use local datasetchg
Changed access control to be based on auth0 metadatachg
Changed user role index page to show only tenant user records
Comments