diff --git a/backend/config/main.php b/backend/config/main.php index a8a0865..d868264 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -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', diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index df2d805..d618438 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -42,7 +42,7 @@ class UserCardController extends Controller 'rules' => [ [ 'allow' => true, - 'roles' => ['admin'], + 'roles' => ['admin', 'profileEditor'], ], ], ], diff --git a/backend/modules/card/views/user-card/_form.php b/backend/modules/card/views/user-card/_form.php index a75db10..897bb98 100755 --- a/backend/modules/card/views/user-card/_form.php +++ b/backend/modules/card/views/user-card/_form.php @@ -20,7 +20,6 @@ use yii\widgets\ActiveForm;
field($model, 'fio')->textInput(['maxlength' => true]) ?>
-
field($model, 'passport')->textInput(['maxlength' => true]) ?>
@@ -28,7 +27,7 @@ use yii\widgets\ActiveForm;
-
+
'ru', @@ -47,7 +46,7 @@ use yii\widgets\ActiveForm; ?>
- + 'ru', @@ -118,9 +117,11 @@ use yii\widgets\ActiveForm;
-
- field($model, 'salary')->textInput(['maxlength' => true]) ?> -
+ user->can('confidential_information')): ?> +
+ field($model, 'salary')->textInput(['maxlength' => true]) ?> +
+
field($model, 'position_id')->dropDownList( \yii\helpers\ArrayHelper::map(\backend\modules\settings\models\Position::find()->all(), 'id', 'name'), @@ -169,7 +170,7 @@ use yii\widgets\ActiveForm;
- field($model, 'vc_text')->widget(EditorClassic::className(),[ + field($model, 'vc_text')->widget(EditorClassic::className(), [ 'clientOptions' => [ 'language' => 'ru', ] @@ -181,8 +182,8 @@ use yii\widgets\ActiveForm; 'cloneButton' => true, 'columns' => [ [ - 'name' => 'field_id', - 'type' => 'dropDownList', + 'name' => 'field_id', + 'type' => 'dropDownList', 'title' => 'Поле', 'defaultValue' => null, 'items' => \yii\helpers\ArrayHelper::map( @@ -213,7 +214,7 @@ use yii\widgets\ActiveForm; ], ], [ - 'name' => 'order', + 'name' => 'order', 'title' => 'Приоритет', 'enableError' => true, 'options' => [ diff --git a/backend/modules/card/views/user-card/index.php b/backend/modules/card/views/user-card/index.php index f3242bb..a92b535 100755 --- a/backend/modules/card/views/user-card/index.php +++ b/backend/modules/card/views/user-card/index.php @@ -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', diff --git a/backend/modules/card/views/user-card/view.php b/backend/modules/card/views/user-card/view.php index 831dba9..06d5385 100755 --- a/backend/modules/card/views/user-card/view.php +++ b/backend/modules/card/views/user-card/view.php @@ -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 : 'Без должности', diff --git a/console/controllers/RbacController.php b/console/controllers/RbacController.php index 3e0fe75..94a5c6c 100644 --- a/console/controllers/RbacController.php +++ b/console/controllers/RbacController.php @@ -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; + } } \ No newline at end of file