A
A
alex4answ2020-05-07 08:26:48
Yii
alex4answ, 2020-05-07 08:26:48

Role inheritance from permission not working?

RBAC inherited role from permission, assign this role to user, check if he can do "permission" - false response:

role: admin
permission: canAdmin

auth_item_child:

parent         |  child
--------------+--------
canAdmin    |  admin


auth assignment:
item_name  | user_id 
--------------+-----------
admin          | 1


when checking: UPD: Through fraud, I realized that it is necessary to inherit not the role from the permission (which is logical), but the permission from the role (which is not at all logical) Why is that? After all, usually inheriting - we get the parent's saints, but here it turns out somehow the other way around
\Yii::$app->user->can('canAdmin'); // false


Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2020-05-10
@alex4answ

Through fraud, I realized that it is necessary to inherit not the role from the permission (which is logical), but the permission from the role (which is not at all logical)
Why is that?
After all, usually inheriting - we get the parent's saints, but here it turns out somehow the other way around

It's the other way around for you. In real life, a role combines powers. You even yourself first role, then permission.
role: admin
permission: canAdmin
And in the table do the opposite.
The director can have access to the admin panel, but the client does not. The admin can manage the content, but the user can't. If this is flipped, then the permission to manage content is obtained can have access to the admin . Where is the logic here?
A role is a group of permissions.
You can assign permissions directly to the user, or combine them into a group and assign a group (role) to the user. No other way. I hope it's clear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question