profile editor role

This commit is contained in:
andrey 2021-08-12 13:57:00 +03:00
parent 86c3146761
commit 3dc11f8075
6 changed files with 61 additions and 13 deletions

View File

@ -64,6 +64,9 @@ return [
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
'session' => [
// this is the name of the session cookie used for login on the backend
'name' => 'advanced-backend',

View File

@ -42,7 +42,7 @@ class UserCardController extends Controller
'rules' => [
[
'allow' => true,
'roles' => ['admin'],
'roles' => ['admin', 'profileEditor'],
],
],
],

View File

@ -20,7 +20,6 @@ use yii\widgets\ActiveForm;
<div class="col-xs-6">
<?= $form->field($model, 'fio')->textInput(['maxlength' => true]) ?>
</div>
<div class="col-xs-6">
<?= $form->field($model, 'passport')->textInput(['maxlength' => true]) ?>
</div>
@ -118,9 +117,11 @@ use yii\widgets\ActiveForm;
</div>
<div class="row">
<?php if (Yii::$app->user->can('confidential_information')): ?>
<div class="col-xs-6">
<?= $form->field($model, 'salary')->textInput(['maxlength' => true]) ?>
</div>
<?php endif; ?>
<div class="col-xs-6">
<?= $form->field($model, 'position_id')->dropDownList(
\yii\helpers\ArrayHelper::map(\backend\modules\settings\models\Position::find()->all(), 'id', 'name'),

View File

@ -38,7 +38,10 @@ $this->params['breadcrumbs'][] = $this->title;
'fio',
// 'city',
//'passport',
'salary',
[
'attribute' => 'salary',
'visible' => Yii::$app->user->can('confidential_information')
],
'email:email',
//'gender',
//'dob',

View File

@ -72,7 +72,10 @@ $this->params['breadcrumbs'][] = $this->title;
'attribute' => 'status',
'value' => $model->status0->name,
],
'salary',
[
'attribute' => 'salary',
'visible' => Yii::$app->user->can('confidential_information')
],
[
'attribute' => 'position_id',
'value' => (isset($model->position->name)) ? $model->position->name : 'Без должности',

View File

@ -4,6 +4,7 @@
namespace console\controllers;
use common\models\User;
use Yii;
use yii\console\Controller;
@ -33,4 +34,41 @@ class RbacController extends Controller
$auth->assign($user, 2);
$auth->assign($admin, 1);
}
public function actionCreateEditor()
{
$auth = Yii::$app->authManager;
$confidentialInformation = $auth->createPermission('confidential_information');
$confidentialInformation->description = 'Возможность видеть конфиденциальную информацию';
$auth->add($confidentialInformation);
$secure = $auth->getPermission('secure');
$profileEditor = $auth->createRole('profileEditor');
$auth->add($profileEditor);
$auth->addChild($profileEditor, $secure);
$admin = $auth->getRole('admin');
$auth->addChild($admin, $confidentialInformation);
$auth->addChild($admin, $profileEditor);
$profileEditorUser = $this->createEditor();
$auth->assign($profileEditor, $profileEditorUser->id);
}
private function createEditor()
{
if (!($user = User::findByUsername('profile_editor'))) {
$user = new User();
$user->username = 'profile_editor';
$user->email = 'profile_editor@itguild.info';
$user->setPassword('0023edsaqw');
$user->generateAuthKey();
$user->save(false);
}
return $user;
}
}