Answer the question
In order to leave comments, you need to log in
How correctly to make check of access rights on change of these rights?
I want when an admin, moderator or root changes their access rights in the admin panel, set a ban.
If root, then you can change everything, if admin, then you can set the rights to the level up to the admin, (the root can’t set, if the moderator can’t change the rights at all.
The question is how to do this, through Rbac or in the model through the rules?
I went the road through rbac
made a ChangeRoles rule
with this code
public function execute($user_id, $item, $params)
{
$role = \Yii::$app->user->identity->role;
if($role == 'moder')
return false;
if($role == 'root')
return true;
if($role == 'admin') {
}
}
Answer the question
In order to leave comments, you need to log in
I don’t know if it’s right or not, but I did it like this:
checking like this
Yii::$app->user->can('changeRoles', $model->attributes['role'])
and in the class
public function execute($user_id, $ item, $params)
{
$role = \Yii::$app->user->identity->role;
if($role == 'moder')
return false;
if($role == 'root')
return true;
if($role == 'admin') {
if($params == 'root') {
return false
} else {
return true;
}
}
}
Добрый день.
А как Вы выставляете права? Через форму? Есть выпадающий список прав?
Если да, то может проще, в зависимости от уровня доступа, показывать список прав?
Для root одни, для админа свой список, для модератора вообще этот список не показывать.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question