Skip to content

Commit c706508

Browse files
dev
1 parent 47f862d commit c706508

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

_ide/YiiApplication.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
namespace yii\web;
1010

11+
use skeeks\cms\rbac\CmsManager;
1112
/**
12-
* Class Application
13-
* @package yii\web
13+
* @property CmsManager $authManager
14+
* @author Semenov Alexander <semenov@skeeks.com>
1415
*/
1516
class Application
1617
{

src/CmsManager.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace skeeks\cms\rbac;
1010

1111
use yii\base\InvalidConfigException;
12+
use yii\helpers\ArrayHelper;
1213

1314
/**
1415
* Class CmsManager
@@ -32,6 +33,10 @@ public function init()
3233
parent::init();
3334
}
3435

36+
/**
37+
* Доступ суперадминистратора
38+
*/
39+
const PERMISSION_ROOT_ACCESS = 'cms.root';
3540
/**
3641
* Доступ к админке
3742
*/
@@ -83,4 +88,29 @@ static public function protectedPermissions()
8388
];
8489
}
8590

91+
/**
92+
* @return array|\yii\rbac\Item[]|\yii\rbac\Role[]
93+
*/
94+
public function getAvailableRoles()
95+
{
96+
if (!\Yii::$app->user->identity || !\Yii::$app->user->identity) {
97+
return $this->getRoles();
98+
}
99+
100+
$roles = $this->getRoles();
101+
102+
if (!$roles) {
103+
return [];
104+
}
105+
106+
$result = [];
107+
if (\Yii::$app->user->can(self::PERMISSION_ROOT_ACCESS)) {
108+
return $roles;
109+
}
110+
111+
ArrayHelper::remove($roles, self::ROLE_ROOT);
112+
113+
return $roles;
114+
}
115+
86116
}

src/controllers/AdminPermissionController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public function init()
4444
$this->modelShowAttribute = "name";
4545
$this->modelPkAttribute = "name";
4646
$this->modelClassName = Permission::className();
47+
48+
$this->generateAccessActions = false;
49+
$this->permissionName = CmsManager::PERMISSION_ROOT_ACCESS;
50+
4751
parent::init();
4852
}
4953

src/controllers/AdminRoleController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function init()
4040
$this->modelShowAttribute = "name";
4141
$this->modelPkAttribute = "name";
4242
$this->modelClassName = Role::className();
43+
44+
$this->generateAccessActions = false;
45+
$this->permissionName = CmsManager::PERMISSION_ROOT_ACCESS;
46+
4347
parent::init();
4448
}
4549

0 commit comments

Comments
 (0)