rmrevin/yii2-rbac-migration Extension for RBAC migrations for Yii2

rbacmigration

Yii 2 extension for RBAC migrations

Installation

Add in composer.json:

{
    "require": {
        "rmrevin/yii2-rbac-migration": "1.1.*"
    }
}

Usage

Create new migration extends \rmrevin\yii\rbac\RbacMigration and execute as normal migration

<?
// ...

class m140217_201400_rbac extends \rmrevin\yii\rbac\RbacMigration
{

    protected function getNewRoles()
    {
        return [
            RbacFactory::Role('admin', 'Administrator'),
            RbacFactory::Role('manager', 'Manager'),
            RbacFactory::Role('customer', 'Customer'),
            RbacFactory::Role('user', 'User'),
        ];
    }

    protected function getNewPermissions()
    {
        return [
            RbacFactory::Permission('catalog.view', 'Can view catalog'),
            RbacFactory::Permission('catalog.order', 'Can order items from catalog'),
            RbacFactory::Permission('catalog.favorite', 'Can mark favorite items'),
        ];
    }

    protected function getNewInheritance()
    {
        return [
            'admin' => [
                'manager', // inherit role manager and all permissions from role manager & user
            ],
            'manager' => [
                'user', // inherit role user and all permissions from role user
            ],
            'customer' => [
                'user', // inherit role user and all permissions from role user

                'catalog.order', // inherit permission catalog.order
                'catalog.favorite', // inherit permission catalog.favorite
            ],
            'user' => [
                'catalog.view', // inherit permission catalog.view
            ],
        ];
    }

    protected function getOldInheritance()
    {
        return [
            'admin' => [
                'manager', // inherit role manager and all permissions from role manager & user
            ],
            'manager' => [
                'user', // inherit role user and all permissions from role user
            ],
            'user' => [
            ],
        ];
    }
}

Reference

Inheritance:

  • protected getNewInheritance()
  • protected getOldInheritance()

Rules:

  • protected getNewRules()
  • protected getRenamedRules()
  • protected getRemoveRules()

Roles:

  • protected getNewRoles()
  • protected getRenamedRoles()
  • protected getRemoveRoles()

Permissions:

  • protected getNewPermissions()
  • protected getRenamedPermissions()
  • protected getRemovePermissions()

Changelog

2015-02-25

  • Delete method getInheritance. Now instead of it there are two methods getNewInheritance and getOldInheritance for the up and down respectively.
  • Add examples.

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



2.0.2 is the latest of 8 releases



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