public function actionUpdateRole($name)
{
$role = Yii::$app->authManager->getRole($name);
$permissions = ArrayHelper::map(Yii::$app->authManager->getPermissions(), 'name', 'description');
$role_permit = array_keys(Yii::$app->authManager->getPermissionsByRole($name));
if ($role instanceof Role) {
if (Yii::$app->request->post('name') && $this->validate(Yii::$app->request->post('name'), $this->pattern4Role)) {
if (Yii::$app->request->post('name') != $name && !$this->isUnique(Yii::$app->request->post('name'), 'role')) {
return $this->render('updateRole', ['role' => $role, 'permissions' => $permissions, 'role_permit' => $role_permit, 'error' => $this->error]);
}
$role = $this->setAttribute($role, Yii::$app->request->post());
Yii::$app->authManager->update($name, $role);
$this->updatePermissions($permissions, Yii::$app->request->post('permissions', []), $role);
return $this->redirect(Url::toRoute(['update-role', 'name' => $role->name]));
}
return $this->render('updateRole', ['role' => $role, 'permissions' => $permissions, 'role_permit' => $role_permit, 'error' => $this->error]);
} else {
throw new BadRequestHttpException(Yii::t('db_rbac', 'Страница не найдена'));
}
}