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, 'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true], 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
], ],
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
'session' => [ 'session' => [
// this is the name of the session cookie used for login on the backend // this is the name of the session cookie used for login on the backend
'name' => 'advanced-backend', 'name' => 'advanced-backend',

View File

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

View File

@ -20,7 +20,6 @@ use yii\widgets\ActiveForm;
<div class="col-xs-6"> <div class="col-xs-6">
<?= $form->field($model, 'fio')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'fio')->textInput(['maxlength' => true]) ?>
</div> </div>
<div class="col-xs-6"> <div class="col-xs-6">
<?= $form->field($model, 'passport')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'passport')->textInput(['maxlength' => true]) ?>
</div> </div>
@ -28,7 +27,7 @@ use yii\widgets\ActiveForm;
<div class="row" style="padding-bottom: 15px"> <div class="row" style="padding-bottom: 15px">
<div class="imgUpload col-xs-6"> <div class="imgUpload col-xs-6">
<div class="media__upload_img"><img src="<?= $model->photo; ?>" width="100px" /></div> <div class="media__upload_img"><img src="<?= $model->photo; ?>" width="100px"/></div>
<?php <?php
echo InputFile::widget([ echo InputFile::widget([
'language' => 'ru', 'language' => 'ru',
@ -47,7 +46,7 @@ use yii\widgets\ActiveForm;
?> ?>
</div> </div>
<div class="col-xs-6"> <div class="col-xs-6">
<!--<div class="media__upload_img"><img src="<?/*= $model->photo; */ ?>" width="100px"/></div>--> <!--<div class="media__upload_img"><img src="<? /*= $model->photo; */ ?>" width="100px"/></div>-->
<?php <?php
echo InputFile::widget([ echo InputFile::widget([
'language' => 'ru', 'language' => 'ru',
@ -118,9 +117,11 @@ use yii\widgets\ActiveForm;
</div> </div>
<div class="row"> <div class="row">
<div class="col-xs-6"> <?php if (Yii::$app->user->can('confidential_information')): ?>
<?= $form->field($model, 'salary')->textInput(['maxlength' => true]) ?> <div class="col-xs-6">
</div> <?= $form->field($model, 'salary')->textInput(['maxlength' => true]) ?>
</div>
<?php endif; ?>
<div class="col-xs-6"> <div class="col-xs-6">
<?= $form->field($model, 'position_id')->dropDownList( <?= $form->field($model, 'position_id')->dropDownList(
\yii\helpers\ArrayHelper::map(\backend\modules\settings\models\Position::find()->all(), 'id', 'name'), \yii\helpers\ArrayHelper::map(\backend\modules\settings\models\Position::find()->all(), 'id', 'name'),
@ -169,7 +170,7 @@ use yii\widgets\ActiveForm;
</div> </div>
</div> </div>
<?= $form->field($model, 'vc_text')->widget(EditorClassic::className(),[ <?= $form->field($model, 'vc_text')->widget(EditorClassic::className(), [
'clientOptions' => [ 'clientOptions' => [
'language' => 'ru', 'language' => 'ru',
] ]
@ -181,8 +182,8 @@ use yii\widgets\ActiveForm;
'cloneButton' => true, 'cloneButton' => true,
'columns' => [ 'columns' => [
[ [
'name' => 'field_id', 'name' => 'field_id',
'type' => 'dropDownList', 'type' => 'dropDownList',
'title' => 'Поле', 'title' => 'Поле',
'defaultValue' => null, 'defaultValue' => null,
'items' => \yii\helpers\ArrayHelper::map( 'items' => \yii\helpers\ArrayHelper::map(
@ -213,7 +214,7 @@ use yii\widgets\ActiveForm;
], ],
], ],
[ [
'name' => 'order', 'name' => 'order',
'title' => 'Приоритет', 'title' => 'Приоритет',
'enableError' => true, 'enableError' => true,
'options' => [ 'options' => [

View File

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

View File

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

View File

@ -4,6 +4,7 @@
namespace console\controllers; namespace console\controllers;
use common\models\User;
use Yii; use Yii;
use yii\console\Controller; use yii\console\Controller;
@ -33,4 +34,41 @@ class RbacController extends Controller
$auth->assign($user, 2); $auth->assign($user, 2);
$auth->assign($admin, 1); $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;
}
} }