A
A
Anton2017-02-22 12:25:23
Yii
Anton, 2017-02-22 12:25:23

How to attach rbac admin to individual modules in Yii2 using mdmsoft yii2-admin?

Essence of a question:
There is a system on Yii2 (basic template). It has separate modules. There is a system of roles both for the application and for specific modules.
For specific modules, the separation of rights is organized by the configuration of the Module.php file:

public function init()
    {
        parent::init();

        $prefix = $this->id;

        $this->components = [
          'authManager' => [
            'class' => 'app\modules\moduleName\rbac\ModuleDbManager',
            'itemTable' => "{{%{$prefix}_auth_item}}",
            'itemChildTable' => "{{%{$prefix}_auth_item_child}}",
            'assignmentTable' => "{{%{$prefix}_auth_assignment}}",
            'ruleTable' => "{{%{$prefix}_auth_rule}}",
          ],
        ];
}

That is, each module has its own tables in the database with a prefix equal to the module name.
I'm trying to fasten the mdmsoft yii2-admin admin panel for editing roles, for modules. And there prefixes cannot be adjusted by a configuration. There, everywhere in the code there is such a call:
$manager = Yii::$app->getAuthManager();
That is, the rbac manager is called not for a specific module, but for the global manager of the application itself.
I don't know how to solve this problem. All that comes to mind is to fork mdmsoft yii2-admin and wherever the manager is called, add the configuration:
$manager = Yii::$app->getAuthManager();

        $prefix = 'moduleName';
        $manager->itemTable = "{{%{$prefix}_auth_item}}";
        $manager->itemChildTable = "{{%{$prefix}_auth_item_child}}";
        $manager->assignmentTable = "{{%{$prefix}_auth_assignment}}";
        $manager->ruleTable = "{{%{$prefix}_auth_rule}}";

I really don't want to mess with my bike. Can I somehow solve my problem at the configuration level? Can you suggest a more elegant solution?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-02-22
@slo_nik

Good morning.
There is a good article on how to add rbac to a website . Without third-party packages, by the forces of one framework. Just using yii2-basic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question