From 63944f962ee65fdd0d356678dea463b0690718e5 Mon Sep 17 00:00:00 2001 From: alexey_u Date: Sat, 20 Oct 2018 00:07:17 +0400 Subject: [PATCH 1/2] Do not show routes on Permissions list when advanced config is enabled --- models/searchs/AuthItem.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/models/searchs/AuthItem.php b/models/searchs/AuthItem.php index d08dd0dc..3811cd81 100644 --- a/models/searchs/AuthItem.php +++ b/models/searchs/AuthItem.php @@ -59,11 +59,18 @@ public function search($params) { /* @var \yii\rbac\Manager $authManager */ $authManager = Configs::authManager(); + $advanced = Configs::instance()->advanced; if ($this->type == Item::TYPE_ROLE) { $items = $authManager->getRoles(); } else { - $items = array_filter($authManager->getPermissions(), function($item) { - return $this->type == Item::TYPE_PERMISSION xor strncmp($item->name, '/', 1) === 0; + $items = array_filter($authManager->getPermissions(), function($item) use ($advanced){ + $isPermission = $this->type == Item::TYPE_PERMISSION; + if ($advanced) { + return $isPermission xor (strncmp($item->name, '/', 1) === 0 or strncmp($item->name, '@', 1) === 0); + } + else { + return $isPermission xor strncmp($item->name, '/', 1) === 0; + } }); } $this->load($params); From f554f7effd49de5f7c0b46863e955eb17cb23492 Mon Sep 17 00:00:00 2001 From: alexey_u Date: Sat, 20 Oct 2018 00:24:42 +0400 Subject: [PATCH 2/2] Do not show routes on Permissions list when advanced config is enabled. Fix AuthItem::getItems() method too. --- models/AuthItem.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/models/AuthItem.php b/models/AuthItem.php index 79813675..2c22929d 100644 --- a/models/AuthItem.php +++ b/models/AuthItem.php @@ -246,6 +246,7 @@ public function removeChildren($items) public function getItems() { $manager = Configs::authManager(); + $advanced = Configs::instance()->advanced; $available = []; if ($this->type == Item::TYPE_ROLE) { foreach (array_keys($manager->getRoles()) as $name) { @@ -253,12 +254,12 @@ public function getItems() } } foreach (array_keys($manager->getPermissions()) as $name) { - $available[$name] = $name[0] == '/' ? 'route' : 'permission'; + $available[$name] = $name[0] == '/' || $advanced && $name[0] == '@' ? 'route' : 'permission'; } $assigned = []; foreach ($manager->getChildren($this->_item->name) as $item) { - $assigned[$item->name] = $item->type == 1 ? 'role' : ($item->name[0] == '/' ? 'route' : 'permission'); + $assigned[$item->name] = $item->type == 1 ? 'role' : ($item->name[0] == '/' || $advanced && $item->name[0] == '@' ? 'route' : 'permission'); unset($available[$item->name]); } unset($available[$this->name]);