A
A
akula222017-01-31 15:16:38
Yii
akula22, 2017-01-31 15:16:38

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') {

        }
    }

but I don’t catch up on how to check if the admin rights change, that is, I don’t know how to get data on what rights the changes occur

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
akula22, 2017-01-31
@akula22 Автор вопроса

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;
}
}
}

Дмитрий, 2017-01-31
@slo_nik Куратор тега Yii

Добрый день.
А как Вы выставляете права? Через форму? Есть выпадающий список прав?
Если да, то может проще, в зависимости от уровня доступа, показывать список прав?
Для root одни, для админа свой список, для модератора вообще этот список не показывать.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question