anli/yii2-rbac RBAC for Yii 2.0

extension

anli\rbac

RBAC for Yii 2.0

Installation

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

Usage

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/'])

Changelog

CHANGELOG

1.4.0 [19 Nov 2015]

  • chg Changed user role index page
  • bug Fixed bug to delete user role correctly

1.3.0 [3 Sep 2015]

  • chg Refactor user query

1.2.0 [1 Sep 2015]

  • chg Changed role select2 widget in user role to use local dataset

1.1.0 [28 Aug 2015]

  • chg Changed access control to be based on auth0 metadata
  • chg Changed user role index page to show only tenant user records

1.0.0 [25 Aug 2015]

  • Initial release

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



1.4.0 is the latest of 6 releases



MIT license
Stats
0 github stars & 0 github forks
0 downloads in the last day
0 downloads in the last 30 days
68 total downloads