Giter Club home page Giter Club logo

yii2-rbac-plus's Introduction

yii2-rbac-plus

Latest Stable Version License Total Downloads Monthly Downloads Daily Downloads

Database role base access control manager for yii2 Actually, this is duplicate repo of https://github.com/johnitvn/yii2-rbac-plus Due to not being active and pulling request of contributor or listening to them, I created this one.

Features

  • CRUD operations for roles, permissions and rules
  • Allows to assign multiple roles to user
  • Nice views to intergrate right away
  • Integrated with Yii2-user-plus - flexible user management module

Yii2 RBAC manager

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist ahmadasjad/yii2-rbac-plus "*"

or add

"ahmadasjad/yii2-rbac-plus": "*"

to the require section of your composer.json file.

Usage

  1. Let 's add into modules config in your main config file
'components' => [
    'authManager' => [
        'class' => 'yii\rbac\DbManager',
    ],
],
'modules' => [
    'rbac' =>  [
        'class' => 'ahmadasjad\rbacplus\Module'
    ]
]

Next, update the database schema

$ php yii migrate/up --migrationPath=@yii/rbac/migrations

Ok. That's done. Avaiable route now:

  • /rbac/rule
  • /rbac/permission
  • /rbac/role
  • /rbac/assignment
  1. The module configuration avaible:
'modules' => [
    'rbac' =>  [
        'class' => 'ahmadasjad\rbacplus\Module',
        'userModelClassName'=>null,
        'userModelIdField'=>'id',
        'userModelLoginField'=>'username',
        'userModelLoginFieldLabel'=>null,
        'userModelExtraDataColumls'=>null,
        'beforeCreateController'=>null,
        'beforeAction'=>null
    ]
]
  • userModelClassName: The user model class.
    If you not set or set null, RBAC Plus will be get from Yii::$app->getUser()->identityClass
  • userModelIdField: The user model id field.
    Default id field is 'id', you must set this config if primary key of user table in database is not 'id'
  • userModelLoginField The user model login field.
    Default login field is 'username'. Maybe you use email field or something other for login. So you must change this config
  • userModelLoginFieldLabel The user model login field label.
    If you set null the label will get from $userModelClass->attributeLabels()[$userModelLoginField]
  • userModelExtraDataColumls The extra data columns you want to show in user assign views.
    The default in assignment data gridview just display id and login column data. if you want to add created_at column you can add
'userModelExtraDataColumls'=>[
    [
        'attributes'=>'created_at',
        'value'=>function($model){
            return date('m/d/Y', $model->created_at);
        }
    ]
]
  • beforeCreateController The callable before create all controller of Rbac Plus module. The default it is null. You need config this when you want to restrict access to Rbac Plus module.
    Example:
'beforeCreateController'=>function($route){
    /**
    *@var string $route The route consisting of module, controller and action IDs.
    */
}
  • beforeActionThe callable before action of all controller in Rbac Plus module.
    The default it is null. You need config this when you want to restrict access to any action in some controller of Rbac Plus module
    Example:
'beforeAction'=>function($action){
    /**
    *@var yii\base\Action $action the action to be executed.
    */
}

yii2-rbac-plus's People

Contributors

ahmadasjad avatar evgen1986 avatar johnitvn avatar max-dreamsoft avatar mikleua avatar pceuropa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.