Create role and permission from the command line based on the content of a YAML or JSON file.
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 config/console.php as follows
'modules' => [
................
'rbac' => [
'class' => 'macfly\rbac\Module',
],
................
],
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
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