rmrevin/yii2-rbac-command

Extension for RBAC rules update for Yii2

Installs: 17 246

Dependents: 3

Suggesters: 0

Security: 0

Stars: 7

Watchers: 2

Forks: 1

Open Issues: 0

Type:yii2-extension

1.6.1 2017-03-08 13:42 UTC

This package is not auto-updated.

Last update: 2024-12-21 18:37:16 UTC


README

This extension provides a console command to update the RBAC rules, roles and permissions for Yii framework 2.0 applications.

Installation

composer require "rmrevin/yii2-rbac-command:~1.6"

Configuration

Create new console command extends \rmrevin\yii\rbac\Command (example)

<?php

namespace app\commands;

class RbacCommand extends \rmrevin\yii\rbac\Command
{

    protected function rules()
    {
        // ...
    }

    protected function roles()
    {
        // ...
    }

    protected function permissions()
    {
        // ...
    }

    protected function inheritanceRoles()
    {
        // ...
    }

    protected function inheritancePermissions()
    {
        // ...
    }
}

In console application config (example: /protected/config/console.php)

<?
return [
  // ...
	'controllerMap' => [
		// ...
		'rbac' => [
			'class' => 'app\commands\RbacCommand',
			'batchSize' => 1000,
			'forceAssign' => ['user'], // force assign user role for all users
			'assignmentsMap' => [
			    'frontend.old' => 'frontend.new', // after next update all `frontend.old` will be replaced by `frontend.new`
			],
			'useTransaction' => true,
			'useCache' => true,
		],
	],
	// ...
];

Usage

Execute command in command line

yii rbac/update