Skip to content

Commit ae5937a

Browse files
dev
1 parent c706508 commit ae5937a

File tree

10 files changed

+177
-208
lines changed

10 files changed

+177
-208
lines changed

src/console/controllers/InitController.php

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use skeeks\cms\backend\IBackendComponent;
1313
use skeeks\cms\IHasPermissions;
1414
use skeeks\cms\models\User;
15-
use skeeks\cms\modules\admin\components\UrlRule;
1615
use skeeks\cms\modules\admin\controllers\AdminController;
1716
use skeeks\cms\rbac\CmsManager;
1817
use Yii;

src/controllers/AdminRoleController.php

+122-108
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,40 @@
1111

1212
namespace skeeks\cms\rbac\controllers;
1313

14+
use skeeks\cms\backend\actions\BackendModelAction;
15+
use skeeks\cms\backend\controllers\BackendModelStandartController;
16+
use skeeks\cms\backend\grid\DefaultActionColumn;
1417
use skeeks\cms\helpers\RequestResponse;
1518
use skeeks\cms\modules\admin\actions\AdminAction;
1619
use skeeks\cms\modules\admin\actions\modelEditor\AdminOneModelEditAction;
17-
use skeeks\cms\modules\admin\controllers\AdminModelEditorController;
1820
use skeeks\cms\rbac\CmsManager;
1921
use skeeks\cms\rbac\models\AuthItem;
22+
use skeeks\cms\rbac\models\CmsAuthItem;
2023
use skeeks\cms\rbac\models\searchs\AuthItem as AuthItemSearch;
24+
use skeeks\yii2\form\fields\HtmlBlock;
2125
use Yii;
22-
use yii\filters\VerbFilter;
26+
use yii\base\Event;
27+
use yii\data\ActiveDataProvider;
28+
use yii\db\ActiveQuery;
2329
use yii\helpers\ArrayHelper;
2430
use yii\helpers\Html;
2531
use yii\rbac\Item;
2632
use yii\rbac\Role;
27-
use yii\web\Controller;
2833
use yii\web\NotFoundHttpException;
2934
use yii\web\Response;
3035
use yii\widgets\ActiveForm;
3136

3237
/**
3338
* AuthItemController implements the CRUD actions for AuthItem model.
3439
*/
35-
class AdminRoleController extends AdminModelEditorController
40+
class AdminRoleController extends BackendModelStandartController
3641
{
3742
public function init()
3843
{
39-
$this->name = \Yii::t('app', "Managing Roles");
44+
$this->name = \Yii::t('skeeks/rbac', "Managing roles");
4045
$this->modelShowAttribute = "name";
4146
$this->modelPkAttribute = "name";
42-
$this->modelClassName = Role::className();
47+
$this->modelClassName = CmsAuthItem::class;
4348

4449
$this->generateAccessActions = false;
4550
$this->permissionName = CmsManager::PERMISSION_ROOT_ACCESS;
@@ -50,35 +55,102 @@ public function init()
5055
public function actions()
5156
{
5257
return ArrayHelper::merge(parent::actions(), [
53-
'index' =>
54-
[
55-
'class' => AdminAction::className(),
56-
'callback' => [$this, 'actionIndex']
58+
'index' => [
59+
"filters" => [
60+
'visibleFilters' => [
61+
'name',
62+
],
5763
],
58-
'view' =>
59-
[
60-
"class" => AdminOneModelEditAction::className(),
61-
"name" => \Yii::t('app', "Watch"),
62-
"icon" => "fa fa-eye",
63-
"callback" => [$this, "actionView"],
64-
],
65-
'create' =>
66-
[
67-
'class' => AdminAction::className(),
68-
'callback' => [$this, 'actionCreate']
69-
],
70-
"update" =>
71-
[
72-
'class' => AdminOneModelEditAction::className(),
73-
'callback' => [$this, 'actionUpdate']
74-
],
75-
"delete" =>
76-
[
77-
'callback' => [$this, 'actionDelete']
64+
'grid' => [
65+
'on init' => function (Event $e) {
66+
/**
67+
* @var $dataProvider ActiveDataProvider
68+
* @var $query ActiveQuery
69+
*/
70+
$query = $e->sender->dataProvider->query;
71+
$dataProvider = $e->sender->dataProvider;
72+
73+
$query->andWhere([
74+
CmsAuthItem::tableName().".type" => Role::TYPE_ROLE
75+
]);
76+
77+
/* $query->select([
78+
CmsContentProperty::tableName().'.*',
79+
//'countElementProperties' => new Expression("count(*)"),
80+
'countElementProperties' => $subQuery,
81+
]);*/
82+
},
83+
84+
'defaultOrder' => [
85+
'name' => SORT_DESC,
86+
],
87+
'visibleColumns' => [
88+
'checkbox',
89+
'actions',
90+
91+
'name',
92+
],
93+
94+
'columns' => [
95+
'name' => [
96+
'attribute' => 'name',
97+
'label' => \Yii::t('skeeks/rbac', 'Role'),
98+
'format' => 'raw',
99+
'value' => function (CmsAuthItem $cmsAuthItem) {
100+
return \yii\helpers\Html::a($cmsAuthItem->name, "#", [
101+
'class' => "sx-trigger-action",
102+
]). "<div style='color: gray'>{$cmsAuthItem->description}</div>";
103+
}
104+
]
105+
]
78106
],
107+
],
108+
'view' => [
109+
"class" => BackendModelAction::className(),
110+
"name" => \Yii::t('skeeks/rbac', "Watch"),
111+
"icon" => "fa fa-eye",
112+
"callback" => [$this, "actionView"],
113+
],
114+
'create' => [
115+
'fields' => [$this, 'updateFields'],
116+
],
117+
'update' => [
118+
'fields' => [$this, 'updateFields'],
119+
],
120+
/*'create' => [
121+
'class' => AdminAction::className(),
122+
'callback' => [$this, 'actionCreate'],
123+
],
124+
"update" => [
125+
'class' => AdminOneModelEditAction::className(),
126+
'callback' => [$this, 'actionUpdate'],
127+
],*/
128+
"delete" => [
129+
'callback' => [$this, 'actionDelete'],
130+
],
79131
]);
80132
}
81133

134+
public function updateFields($action)
135+
{
136+
$model = $action->model;
137+
$model->type = Item::TYPE_ROLE;
138+
139+
return [
140+
'name',
141+
'description',
142+
[
143+
'class' => HtmlBlock::class,
144+
'content' => '<div style="display: none">',
145+
],
146+
'type',
147+
148+
[
149+
'class' => HtmlBlock::class,
150+
'content' => '</div>',
151+
],
152+
];
153+
}
82154
/**
83155
* @return Role
84156
* @throws NotFoundHttpException
@@ -93,24 +165,10 @@ public function getModel()
93165
return $this->_model;
94166
}
95167

96-
/**
97-
* Lists all AuthItem models.
98-
* @return mixed
99-
*/
100-
public function actionIndex()
101-
{
102-
$searchModel = new AuthItemSearch(['type' => Item::TYPE_ROLE]);
103-
$dataProvider = $searchModel->search(Yii::$app->request->getQueryParams());
104-
return $this->render('index', [
105-
'dataProvider' => $dataProvider,
106-
'searchModel' => $searchModel,
107-
'controller' => $this,
108-
]);
109-
}
110168

111169
/**
112170
* Displays a single AuthItem model.
113-
* @param string $id
171+
* @param string $id
114172
* @return mixed
115173
*/
116174
public function actionView()
@@ -120,35 +178,35 @@ public function actionView()
120178
$model = $this->findModel($id);
121179
$authManager = Yii::$app->getAuthManager();
122180
$avaliable = $assigned = [
123-
'Roles' => [],
181+
'Roles' => [],
124182
'Permission' => [],
125-
'Routes' => [],
183+
'Routes' => [],
126184
];
127185
$children = array_keys($authManager->getChildren($id));
128186
$children[] = $id;
129187
foreach ($authManager->getRoles() as $name => $role) {
130188
if (in_array($name, $children)) {
131189
continue;
132190
}
133-
$avaliable['Roles'][$name] = $name . '' . $role->description;
191+
$avaliable['Roles'][$name] = $name.''.$role->description;
134192
}
135193
foreach ($authManager->getPermissions() as $name => $role) {
136194
if (in_array($name, $children)) {
137195
continue;
138196
}
139197

140198
if (isset($name[0])) {
141-
$avaliable[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name . '' . $role->description;
199+
$avaliable[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name.''.$role->description;
142200
}
143201
}
144202
foreach ($authManager->getChildren($id) as $name => $child) {
145203
if ($child->type == Item::TYPE_ROLE) {
146-
$assigned['Roles'][$name] = $name . '' . $child->description;
204+
$assigned['Roles'][$name] = $name.''.$child->description;
147205
} else {
148206
if (isset($name[0])) {
149-
$assigned[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name . '' . $child->description;
207+
$assigned[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name.''.$child->description;
150208
} else {
151-
$assigned['Permission'][$name] = $name . '' . $child->description;
209+
$assigned['Permission'][$name] = $name.''.$child->description;
152210
}
153211
}
154212
}
@@ -157,53 +215,6 @@ public function actionView()
157215
return $this->render('view', ['model' => $model, 'avaliable' => $avaliable, 'assigned' => $assigned]);
158216
}
159217

160-
/**
161-
* Creates a new AuthItem model.
162-
* If creation is successful, the browser will be redirected to the 'view' page.
163-
* @return mixed
164-
*/
165-
public function actionCreate()
166-
{
167-
$model = new AuthItem(null);
168-
$model->type = Item::TYPE_ROLE;
169-
if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
170-
$model->load(\Yii::$app->request->post());
171-
\Yii::$app->response->format = Response::FORMAT_JSON;
172-
return ActiveForm::validate($model);
173-
}
174-
if ($model->load(Yii::$app->getRequest()->post()) && $model->save()) {
175-
return $this->redirect(['view', 'id' => $model->name]);
176-
} else {
177-
return $this->render('create', ['model' => $model,]);
178-
}
179-
}
180-
181-
/**
182-
* Updates an existing AuthItem model.
183-
* If update is successful, the browser will be redirected to the 'view' page.
184-
* @param string $id
185-
* @return mixed
186-
*/
187-
public function actionUpdate()
188-
{
189-
$model = $this->model;
190-
$id = $model->name;
191-
$model = $this->findModel($id);
192-
if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
193-
$model->load(\Yii::$app->request->post());
194-
\Yii::$app->response->format = Response::FORMAT_JSON;
195-
return ActiveForm::validate($model);
196-
}
197-
if (\Yii::$app->request->isAjax) {
198-
if ($model->load(\Yii::$app->request->post()) && $model->save()) {
199-
\Yii::$app->getSession()->setFlash('success', \Yii::t('app', 'Saved successfully'));
200-
} else {
201-
\Yii::$app->getSession()->setFlash('error', \Yii::t('app', 'Failed to save'));
202-
}
203-
}
204-
return $this->render('update', ['model' => $model,]);
205-
}
206-
207218
/**
208219
* Deletes an existing Game model.
209220
* If deletion is successful, the browser will be redirected to the 'index' page.
@@ -280,7 +291,7 @@ public function actionAssign()
280291
return [
281292
$this->actionRoleSearch($id, 'avaliable', $post['search_av']),
282293
$this->actionRoleSearch($id, 'assigned', $post['search_asgn']),
283-
$error
294+
$error,
284295
];
285296
}
286297

@@ -294,9 +305,9 @@ public function actionAssign()
294305
public function actionRoleSearch($id, $target, $term = '')
295306
{
296307
$result = [
297-
'Roles' => [],
308+
'Roles' => [],
298309
'Permission' => [],
299-
'Routes' => [],
310+
'Routes' => [],
300311
];
301312
$authManager = Yii::$app->authManager;
302313
if ($target == 'avaliable') {
@@ -307,7 +318,7 @@ public function actionRoleSearch($id, $target, $term = '')
307318
continue;
308319
}
309320
if (empty($term) or strpos($name, $term) !== false) {
310-
$result['Roles'][$name] = $name;
321+
$result['Roles'][$name] = $name.''.$role->description;
311322
}
312323
}
313324
foreach ($authManager->getPermissions() as $name => $role) {
@@ -316,19 +327,22 @@ public function actionRoleSearch($id, $target, $term = '')
316327
}
317328
if (empty($term) or strpos($name, $term) !== false) {
318329
if (isset($name[0])) {
319-
$result[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name;
330+
$result[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name. "".$role->description;
320331
} else {
321-
$result['Permission'][$name] = $name;
332+
$result['Permission'][$name] = $name. "".$role->description;
322333
}
323334
}
324335
}
325336
} else {
326337
foreach ($authManager->getChildren($id) as $name => $child) {
327338
if (empty($term) or strpos($name, $term) !== false) {
328339
if ($child->type == Item::TYPE_ROLE) {
329-
$result['Roles'][$name] = $name;
340+
$result['Roles'][$name] = $name. "".$child->description;
330341
} else {
331-
$result[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name;
342+
if (isset($name[0])) {
343+
$result[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name. "".$child->description;
344+
}
345+
332346
}
333347
}
334348
}
@@ -339,7 +353,7 @@ public function actionRoleSearch($id, $target, $term = '')
339353
/**
340354
* Finds the AuthItem model based on its primary key value.
341355
* If the model is not found, a 404 HTTP exception will be thrown.
342-
* @param string $id
356+
* @param string $id
343357
* @return AuthItem the loaded model
344358
* @throws HttpException if the model cannot be found
345359
*/

src/messages/ru/main.php

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php
22
return [
3+
"Avaliable" => "Доступно",
4+
"Assigned" => "Назначено",
5+
"Managing roles" => "Управление ролями",
6+
"Role" => "Роль",
37
"Roles" => "Роли",
48
"Privileges" => "Привилегии",
9+
"Watch" => "Смотреть",
510
];

0 commit comments

Comments
 (0)