-
-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
roles matrix sort by admin and group
admin roles sort by admin config and group config admin_label set admin translation domain
- Loading branch information
Showing
6 changed files
with
134 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ | |
|
||
/** | ||
* @author Silas Joisten <[email protected]> | ||
* | ||
* @phpstan-import-type Role from RolesBuilderInterface | ||
*/ | ||
final class AdminRolesBuilder implements AdminRolesBuilderInterface | ||
{ | ||
|
@@ -76,27 +78,65 @@ public function addExcludeAdmin(string $exclude): void | |
|
||
public function getRoles(?string $domain = null): array | ||
{ | ||
$adminServiceCodes = array_diff($this->pool->getAdminServiceCodes(), $this->excludeAdmins); | ||
|
||
// get groups and admins sort by config | ||
$adminRoles = []; | ||
foreach ($this->pool->getAdminServiceCodes() as $code) { | ||
if (\in_array($code, $this->excludeAdmins, true)) { | ||
continue; | ||
} | ||
foreach ($this->pool->getAdminGroups() as $groupCode => $group) { | ||
foreach ($group['items'] as $item) { | ||
if (!isset($item['admin'])) { | ||
continue; | ||
} | ||
|
||
$key = array_search($item['admin'], $adminServiceCodes, true); | ||
if (false === $key) { | ||
continue; | ||
} | ||
unset($adminServiceCodes[$key]); | ||
|
||
$admin = $this->pool->getInstance($code); | ||
$securityHandler = $admin->getSecurityHandler(); | ||
$baseRole = $securityHandler->getBaseRole($admin); | ||
foreach (array_keys($admin->getSecurityInformation()) as $key) { | ||
$role = sprintf($baseRole, $key); | ||
$adminRoles[$role] = [ | ||
'role' => $role, | ||
'label' => $key, | ||
'role_translated' => $this->translateRole($role, $domain), | ||
'is_granted' => $this->isMaster($admin) || $this->authorizationChecker->isGranted($role), | ||
'admin_label' => $admin->getTranslator()->trans($admin->getLabel() ?? ''), | ||
]; | ||
$groupLabelTranslated = $this->translator->trans($group['label'], [], $group['translation_domain']); | ||
|
||
$adminRoles = array_merge($adminRoles, $this->getAdminRolesByAdminCode($item['admin'], $domain, $groupLabelTranslated, $groupCode)); | ||
} | ||
} | ||
|
||
// admin with config "show_in_dashboard" set "false" does not have group | ||
$defaultGroupLabelTranslated = $this->translator->trans('_', [], $domain); | ||
$defaultGroupCode = '_'; | ||
foreach ($adminServiceCodes as $code) { | ||
$adminRoles = array_merge($adminRoles, $this->getAdminRolesByAdminCode($code, $domain, $defaultGroupLabelTranslated, $defaultGroupCode)); | ||
} | ||
|
||
return $adminRoles; | ||
} | ||
|
||
/** | ||
* @return array<string, array<string, string|bool>> | ||
* | ||
* @phpstan-return array<string, Role> | ||
*/ | ||
private function getAdminRolesByAdminCode(string $code, ?string $domain = null, string $groupLabelTranslated = '_', string $groupCode = '_'): array | ||
{ | ||
$adminRoles = []; | ||
$admin = $this->pool->getInstance($code); | ||
$securityHandler = $admin->getSecurityHandler(); | ||
$baseRole = $securityHandler->getBaseRole($admin); | ||
$adminLabelTranslated = $admin->getTranslator()->trans($admin->getLabel() ?? '', [], $admin->getTranslationDomain()); | ||
$isMasterAdmin = $this->isMaster($admin); | ||
foreach (array_keys($admin->getSecurityInformation()) as $key) { | ||
$role = sprintf($baseRole, $key); | ||
$adminRoles[$role] = [ | ||
'role' => $role, | ||
'label' => $key, | ||
'role_translated' => $this->translateRole($role, $domain), | ||
'is_granted' => $isMasterAdmin || $this->authorizationChecker->isGranted($role), | ||
'admin_label' => $adminLabelTranslated, | ||
'admin_code' => $code, | ||
'group_label' => $groupLabelTranslated, | ||
'group_code' => $groupCode, | ||
]; | ||
} | ||
|
||
return $adminRoles; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters