Giter Site home page Giter Site logo

yii2-mimin's Introduction

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

yii2-mimin's People

Contributors

chabibnr avatar deolive avatar hscstudio avatar luckynvic avatar m-alfan avatar virbo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-mimin's Issues

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}

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.

Failed to update role on user

Dear Bang Hafid,
Saat update assign role ke user, harus dua kali menekan tombol update baru role terupdate.

Thanks buat mimin yang keren banget ini.

new picture 18

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/*"...

Membuat dynamic menu tiga tingkat

Menu pada tingkat kedua dapat di filter tapi ketika menu pada tingkat ke tiga tidak hilang, hanya muncul forbidden ketika di klik.

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

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

[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();

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

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

Navigasi tidak muncul setelah di filter Mimin::filterMenu

Menu tidak tampil saat permission diset * (semua di ijinkan) tidak satu per satu menu diset.
hasil debug sementara bahwa Mimin::checkRoute hanya melakukan check pada route yang diberikan, tanpa melakukan check terhadap parent route yang ada, sehingga jika permission yang di berikan adalah /admin/* sedangkan yang di cek adalah /admin/user/index maka menjadi return false;

Error saat menggunakan prefix table

Terjadi masalah saat menggunakan prefix table, di mana nama tabel yang terdapat di mimin tidak mengggunakan pattern untuk support prefix tabel.

public static function tableName() { return 'route'; }

mohon untuk diupdate. Misal
public static function tableName() { return '{{%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

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

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

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.