Skip to content

Yii2 module, provide a cli to load initial permission and roles in rbac from a yaml file

Notifications You must be signed in to change notification settings

marty-macfly/yii2-rbac-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 

Repository files navigation

yii2-rbac-cli

Create role and permission from the command line based on the content of a YAML or JSON file.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist "macfly/yii2-rbac-cli" "*"

or add

"macfly/yii2-rbac-cli": "*"

to the require section of your composer.json file.

Configure

Configure config/console.php as follows

  'modules' => [
     ................
    'rbac'  => [
      'class'       => 'macfly\rbac\Module',
    ],
    ................
  ],

Usage

Import static role and permission list

Create a yaml file with le list of static role and permission you want to create

# Permission section
permissions:
  list:
    desc: List user
  create:
    desc: Create user
  update:
    desc: Edit user
  profile:
    desc: Edit user profile
  delete:
    desc: Remove user

# Role section
roles:
  view:
    desc: View users
    children:
    - list
    - info
  admin:
    desc: Administration
    children:
    - view

# Assign permission and roles to a specific userid
assign:
  1:
  - admin
  - oauth.admin
  2:
  - user.info

After run the @rbac/yaml@ with the path to your yaml file

php yii rbac/load/yaml /tmp/role.yml

Add role or permission to a specific user

You can add some role and permission from the cli to a specific user id.

php yii rbac/load/add userid permissionOrRoleName

For example to add role 'view' to user with id '1' :

php yii rbac/load/add 1 view

About

Yii2 module, provide a cli to load initial permission and roles in rbac from a yaml file

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages