Simple RBAC Manager for Yii2 (minify of yii2-admin)

Overview

Yii2 Mimin

Simple RBAC Manager fo Yii 2.0. Minify of yii2-admin extension with awesome features

Latest Stable Version Total Downloads Latest Unstable Version License

Attention

Before you install and use this extension, then make sure that your application has been using the login authentication to the database. especially for yii basic template. Because without it, this extension will produce error and useless.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist hscstudio/yii2-mimin "~1.1.5"

or add

"hscstudio/yii2-mimin": "~1.1.5"

or add this for install last change

"hscstudio/yii2-mimin": "~1.*"

to the require section of your composer.json file.

Configuration

Once the extension is installed, simply use it in your code by :

in config

'as access' => [
     'class' => '\hscstudio\mimin\components\AccessControl',
	 'allowActions' => [
		// add wildcard allowed action here!
		'site/*',
		'debug/*',
		'mimin/*', // only in dev mode
	],
],
...,
'modules' => [
	'mimin' => [
		'class' => '\hscstudio\mimin\Module',
	],
	...
],
'components' => [
	'authManager' => [
		'class' => 'yii\rbac\DbManager', // only support DbManager
	],
],

Because this extension use 'yii\rbac\DbManager'as authManager, so You should migrate rbac sql first:

yii migrate --migrationPath=@yii/rbac/migrations

If You use Yii 2.0.6 version or newer, so then migrate custom table for this extension

yii migrate --migrationPath=@hscstudio/mimin/migrations

But if You install Yii 2.0.5 version or older, so then migrate custom table for this extension

yii migrate --migrationPath=@hscstudio/mimin/migrations/old

Usage

This RBAC manager have three main page, they are:

Route

To get all action route from application. In here, You can on / off permission so not shown in menu role, rename alias/type of action route, so easy readable by end user. You can then access Route through the following URL:

http://localhost/path/to/index.php?r=mimin/route

Role

To define level access of user, what he superadmin?, staff?, cashier? etc. In this menu, You can assign permission / action route (actions in application, they are create, update, delete, etc) to role. You can then access Role through the following URL:

http://localhost/path/to/index.php?r=mimin/role

Below screenshoot of route assignment to role Screenshoot Role

User

For standard user management, create/update/delete user, and assign role to user. You can then access User through the following URL:

http://localhost/path/to/index.php?r=mimin/user

We recommendate you for activate pretty URL.

Implementation on Widgets

Example dynamic button

It is used for checking if route right to access

if ((Mimin::checkRoute($this->context->id.'/create'))){
    echo Html::a('Create Note', ['create'], ['class' => 'btn btn-success']);
}

// in other case maybe You want ensure same of route so You can add parameter strict true
if ((Mimin::checkRoute($this->context->id.'/create',true))){

Example dynamic menu

It is is used for filtering right access menu

use hscstudio\mimin\components\Mimin;
$menuItems = [
    ['label' => 'Home', 'url' => ['/site/index']],
    ['label' => 'About', 'url' => ['/site/about']],
    ['label' => 'Contact', 'url' => ['/site/contact']],
];

if (\Yii::$app->user->isGuest){
    $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
}
else{
    $menuItems[] = ['label' => 'App', 'items' => [
        ['label' => 'Category', 'url' => ['/category/index']],
        ['label' => 'Product', 'url' => ['/product/index']],
        ['label' => 'Cart', 'url' => ['/cart/index']],
    ]];
    $menuItems[] = [
        'label' => 'Logout (' . \Yii::$app->user->identity->username . ')',
        'url' => ['/site/logout'],
        'linkOptions' => ['data-method' => 'post']
    ];
}

$menuItems = Mimin::filterMenu($menuItems);
// in other case maybe You want ensure same of route so You can add parameter strict true
// $menuItems = Mimin::filterMenu($menuItems,true); 

echo Nav::widget([
    'options' => ['class' => 'navbar-nav navbar-right'],
    'items' => $menuItems,
]);

Example dynamic action column template

It is used for filtering template of Gridview Action Column

use hscstudio\mimin\components\Mimin;
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ...,
        [
          'class' => 'yii\grid\ActionColumn',
          'template' => Mimin::filterActionColumn([
              'update','delete','download'
          ],$this->context->route),
          ...
        ]
    ]
]);

How to Contribute

This tools is an OpenSource project so your contribution is very welcome.

In order to get started:

  • Install this in your local (read installation section)
  • Clone this repository.
  • Check README.md.
  • Send pull requests.

Aside from contributing via pull requests you may submit issues.

Our Team

We'd like to thank our contributors for improving this tools. Thank you!

Jakarta - Indonesia

Buku Panduan

Tutorial tentang dasar-dasar RBAC atau access controll di Yii 2 dan panduan yii2-mimin dibahas secara komprehensif di buku saya ini https://hscstudio.github.io/yii2-book-id

Comments
  • mistake Class hscstudio\yii2-mimin\components\AccessControl does not exist

    mistake Class hscstudio\yii2-mimin\components\AccessControl does not exist

    Class hscstudio\yii2-mimin\components\AccessControl does not exist. Yii2 2.0.6 basic. $config = [ ... 'as access' => [ 'class' => 'hscstudio\mimin\components\AccessControl', 'allowActions' => [ // add wildcard allowed action here! 'site/', 'debug/', 'mimin/*', // only in dev mode ], ]

    bug need more info to be verified 
    opened by dyar74 4
  • migrations not work correctly yii2 2.0.6

    migrations not work correctly yii2 2.0.6

    work when replace on : $tableOptions = null; $this->createTable('{{%route}}', [ 'name' => Schema::TYPE_STRING . '(64) NOT NULL', 'alias' => Schema::TYPE_STRING . '(64) NOT NULL', 'type' => Schema::TYPE_STRING . '(64) NOT NULL', 'status' => Schema::TYPE_SMALLINT . ' NOT NULL', 'PRIMARY KEY (name)' ], $tableOptions);

    But I not set status default value to 1.

    enhancement 
    opened by dyar74 4
  • How to prevent customer access in backend app

    How to prevent customer access in backend app

    Asalamulaikum uncle hafid,

    I want to ask, if i have 2 roles for admin and customer. Because now, customer can access but if he clicked menu customer he get forbiden page. How i can prevent customer cannot be access backend? if customer access backend, then redirect to page not found.

    Thanks, Zeihan Aulia

    question 
    opened by jejehan 3
  • Run migrate got errors.

    Run migrate got errors.

    ➜ ... git:(feature-mimin-rbac) ✗ yii migrate --migrationPath=@hscstudio/mimin/migrations Yii Migration Tool (based on Yii v2.0.6)

    Total 1 new migration to be applied: m151024_072453_create_route_table

    Apply the above migration? (yes|no) [no]:yes *** applying m151024_072453_create_route_table Exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: yii\db\ColumnSchemaBuilder::primaryKey()'

    in .../vendor/yiisoft/yii2/base/Object.php:220

    Stack trace: #0 .../vendor/hscstudio/yii2-mimin/migrations/m151024_072453_create_route_table.php(17): yii\base\Object->_call('primaryKey', Array) #1 .../vendor/hscstudio/yii2-mimin/migrations/m151024_072453_create_route_table.php(17): yii\db\ColumnSchemaBuilder->primaryKey() #2 .../vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(492): m151024_072453_create_route_table->up() #3 .../vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(129): yii\console\controllers\BaseMigrateController->migrateUp('m151024_072453...') #4 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0) #5 .../vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array) #6 .../vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array) #7 .../vendor/yiisoft/yii2/console/Controller.php(91): yii\base\Controller->runAction('', Array) #8 .../vendor/yiisoft/yii2/base/Module.php(455): yii\console\Controller->runAction('', Array) #9 .../vendor/yiisoft/yii2/console/Application.php(167): yii\base\Module->runAction('migrate', Array) #10 .../vendor/yiisoft/yii2/console/Application.php(143): yii\console\Application->runAction('migrate', Array) #11 .../vendor/yiisoft/yii2/base/Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request)) #12 .../yii(27): yii\base\Application->run() #13 {main}

    php: 5.4.45 yii2: 2.0.6 os: mac os

    opened by neatlife 3
  • Failed to update user password

    Failed to update user password

    Dear Bang Hafid,

    Saat update password user, password baru tidak bisa saat login. User masih bias login menggunakan password lama. Mungkin di old_password . CMIIW ...

    Thanks buat mimin yang keren ini

    Salam

    opened by ahmadfadlydziljalal 2
  • View role permission are not same as supposed

    View role permission are not same as supposed

    Assalamualaikum Uncle hafid, thanks for your good work with this extention, but i found little problems with your extentions. i have 2 role (admin and guest). but when i see view role for guest the checkbox check same like role for admin. i think its because $permission = $auth->getPermission($alias->name); not include role filter. https://github.com/hscstudio/yii2-mimin/blob/master/views/role/view.php#L68

    so i change that code like this:

    $autItemChild = AuthItemChild::find()
                                ->where(['parent'=>$model->name,'child'=>$alias->name])
                                ->exists();
    $checked = false;
    if($autItemChild) $checked = true;
    

    i added model for AuthItemChild.

    and now, its work's as supposed, can you consider to implement it or you have better solution to solved this issue.

    Thanks, Zeihan Aulia

    enhancement to be verified 
    opened by jejehan 2
  • Tidak bisa update password

    Tidak bisa update password

    Assalamualaikum mas Hafid,

    untuk perubahan ini #17 sepertinya belum terupdate di tag v1.1.3 saya tadi baru install mimin masih tidak bisa update password.

    Terima Kasih

    opened by alfarioekaputra 1
  • Wrong behavior Mimin::checkRoute

    Wrong behavior Mimin::checkRoute

    Mimin::checkRoute('<controller/action>') return true if you've allowed any action for this controller or controller whose name starts with the same. Fro example: You have routes: /client/* /client/create /client/view /client-source/*

    You allow access to /client/create and to/client-source/*, but if you check Mimin::checkRoute('/client/view') it returned true (.

    I think it hppen there https://github.com/hscstudio/yii2-mimin/blob/master/components/Mimin.php#L37 Because AuthItem::find()->where('name LIKE :param')->addParams([':param' => $parent.'%'])->all() get all where exist "/client%" -> "/client/create" and "/client-source/*"...

    opened by deolive 1
  • [Bug] Tampilan route di view role banyak yang double

    [Bug] Tampilan route di view role banyak yang double

    tampilan pada saat assign route(permission) ke role banyak yg double dikarenakan penggunaan distinct yang tidak tepat

    fix :

    $types = Route::find()->select('type')->distinct()->where(['status' => 1])->all(); atau $types = Route::find()->where(['status' => 1])->groupBy('type')->all();

    opened by nicovicz 1
  • PHP Parse Error 'yii\base\ErrorException' with message 'syntax error, unexpected  ',''

    PHP Parse Error 'yii\base\ErrorException' with message 'syntax error, unexpected ',''

    Yii Migration Tool (based on Yii v2.0.7-dev)

    Total 1 new migration to be applied: m151027_142811_create_route_table

    Apply the above migration? (yes|no) [no]:yes *** applying m151027_142811_create_route_table PHP Parse Error 'yii\base\ErrorException' with message 'syntax error, unexpected ',''

    in C:\xampp\htdocs\cobalagi\vendor\hscstudio\yii2-mimin\migrations\old\m151027_1 42811_create_route_table.php:22

    Stack trace:

    0 [internal function]: yii\base\ErrorHandler->handleFatalError()

    1 {main}

    bug 
    opened by adethis 1
  • Error : user table is not exist in yii2 basic template

    Error : user table is not exist in yii2 basic template

    Kindly add User table in your migration command

    it is not exists in Yii2 Basic. So add it https://github.com/yiisoft/yii2-app-advanced/blob/master/console/migrations/m130524_201442_init.php

    need more info under discussion 
    opened by PritiPhulari 1
  • Gagal Generate Route

    Gagal Generate Route

    `

    hscstudio\mimin\controllers\RouteController::getRouteRecrusive | Object configuration must be an array containing a "class" or "__class" element./app/vendor/hscstudio/yii2-mimin/controllers/RouteController.php:265/app/vendor/hscstudio/yii2-mimin/controllers/RouteController.php:230/app/vendor/hscstudio/yii2-mimin/controllers/RouteController.php:184 -- | --

    `

    Error pada Controller RouteController fungsi getRouteRecrusive PHP 7.4 Yii 2.0.38

    opened by agusedyc 0
  • tutorial integrasi yii2-mimin dengan ekstensi adminlte

    tutorial integrasi yii2-mimin dengan ekstensi adminlte

    gan, cara integrasi yii2-mimin dengan adminlte gimana ya? apa yang perlu diubah? kalau ada tutorialnya mohon link nya gan. sudah cari di google belum nemu nih. makasih..

    opened by ghost 0
  • tidak bisa generate route untuk frontend

    tidak bisa generate route untuk frontend

    Assalamualaikum mas Hafid,

    saya menggunakan advance template, ketika ingin generate route hanya yang ada dibackend saja yang tergenerate, sedangkan yang di frontend tidak.

    Terima Kasih

    under discussion 
    opened by alfarioekaputra 2
Releases(v1.1.5)
Owner
Hafid Mukhlasin
Hafid Mukhlasin
PHP slim framework middleware to minify HTML output

slim-minify Slim middleware to minify HTML output generated by the slim PHP framework. It removes whitespaces, empty lines, tabs beetween html-tags an

Christian Klisch 35 Oct 31, 2021
Tarantool connector for yii2 framework. Allow to use activerecord, schemas, widgets and more.

Tarantool connector for yii2 framework Tarantool connector for yii2 framework. Allow to use framework abstractions such as ActiveRecord, Schema, Table

Andrey 11 Nov 21, 2021
Web Push Notifications brought to Yii2

Web Push Notifications for Yii 2 An extension for implementing Web Push Notifications on your website in a breeze. Documentation is at docs/README.md

Mehdi Achour 12 May 19, 2022
yii2-app-advanced with Twitter Bootstrap 5

Yii 2 Advanced Project Template is a skeleton Yii 2 application best for developing complex Web applications with multiple tiers.

Nedarta 1 Nov 5, 2021
Prometheus exporter for Yii2

yii2-prometheus Prometheus Extension for Yii 2 This extension provides a Prometheus exporter component for Yii framework 2.0 applications. This extens

Mehdi Achour 3 Oct 27, 2021
Yii2-symfonymailer - Yii 2 Symfony mailer extension.

Yii Mailer Library - Symfony Mailer Extension This extension provides a Symfony Mailer mail solution for Yii framework 2.0. For license information ch

Yii Software 28 Dec 22, 2022
Yii2 console application used to write our processors of methods to responsible to client calling.

Microservice Application Skeleton Yii2 console application used to write our processors of methods to responsible to client calling. This application

Jafaripur 0 Mar 10, 2022
Date/Time Picker widget for Yii2 framework Based on Eonasdan's Bootstrap 3 Date/Time Picker

Yii2 Date/Time Picker Widget Date/Time Picker widget for Yii2 framework Based on Eonasdan's Bootstrap 3 Date/Time Picker Demo Since this is a part of

Yevhen Terentiev 8 Mar 14, 2022
Yii2 extension for format inputs based on AutoNumeric.js

Yii2 extension for format inputs based on AutoNumeric.js

extead 2 Oct 7, 2019
Yii2 SwitchInput widget turns checkboxes and radio buttons into toggle switchinputes

Yii2 SwitchInput widget turns checkboxes and radio buttons into toggle switchinputes

Kartik Visweswaran 38 Sep 21, 2022
An enhanced FileInput widget for Bootstrap 4.x/3.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)

yii2-widget-fileinput The FileInput widget is a customized file input widget based on Krajee's Bootstrap FileInput JQuery Plugin. The widget enhances

Kartik Visweswaran 227 Nov 6, 2022
An enhanced Yii 2 widget encapsulating the HTML 5 range input (sub repo split from yii2-widgets)

yii2-widget-rangeinput The RangeInput widget is a customized range slider control widget based on HTML5 range input. The widget enhances the default H

Kartik Visweswaran 19 Mar 12, 2022
A Yii2 module for embedding social plugins and widgets.

yii2-social Module that enables access to social plugins for Yii Framework 2.0. It includes support for embedding plugins from the following networks

Kartik Visweswaran 92 May 29, 2022
Pug Yii2 adapter

Yii 2 Pug (ex Jade) extension This extension provides a view renderer for Pug templates for Yii framework 2.0 applications. Support GutHub issues Inst

Pug PHP 8 Jun 17, 2022
This is Yii2 utilities

YII2-UTILITY This is Yii2 utilities. Requirements PHP >= 7.4 Curl extension for PHP7 must be enabled. Download Using Composer From your project direct

null 0 Jun 30, 2022
Alejandro Flores, Php Yii2 Emoac

Prueba Tecnica Emoac Proyecto basado en PHP con Yii2. Hecho por Alejandro Flores, Ingeniero en informática. Este proyecto consta de un CRUD de product

FlamesAlejandro 2 Sep 13, 2022
PPM is a process manager, supercharger and load balancer for modern PHP applications.

PPM - PHP Process Manager PHP-PM is a process manager, supercharger and load balancer for PHP applications. It's based on ReactPHP and works best with

PPM - PHP Process Manager 6.5k Dec 27, 2022
💾 High-performance PHP application server, load-balancer and process manager written in Golang. RR2 releases repository.

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 45 Nov 29, 2022
🤯 High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 6.9k Jan 3, 2023