Skip to content

Commit

Permalink
Merge pull request #410 from re3lex/feature
Browse files Browse the repository at this point in the history
Do not show routes on Permissions list when advanced config is enabled
  • Loading branch information
sihar authored Jun 5, 2020
2 parents 4b29035 + f554f7e commit ae57d01
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions models/AuthItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,20 @@ 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) {
$available[$name] = 'role';
}
}
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]);
Expand Down
11 changes: 9 additions & 2 deletions models/searchs/AuthItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ae57d01

Please sign in to comment.