Skip to content

Commit

Permalink
Simplify conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauh01 committed Jan 8, 2025
1 parent be2501e commit 0a0805c
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions library/Icinga/Authentication/AdmissionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,39 +183,38 @@ public function applyRoles(User $user)
$assignedRoles = [];
$isUnrestricted = false;
foreach ($this->roleConfig as $roleName => $roleConfig) {
$assigned = $this->match($username, $userGroups, $roleConfig);
if ($assigned) {
if ($this->match($username, $userGroups, $roleConfig)) {
$assignedRoles[] = $roleName;
}

if (! isset($roles[$roleName]) && $assigned) {
foreach ($this->loadRole($roleName, $roleConfig) as $role) {
/** @var Role $role */
if (isset($roles[$role->getName()])) {
continue;
}

$roles[$role->getName()] = $role;
if (! isset($roles[$roleName])) {
foreach ($this->loadRole($roleName, $roleConfig) as $role) {
/** @var Role $role */
if (isset($roles[$role->getName()])) {
continue;
}

$permissions = array_merge(
$permissions,
array_diff($role->getPermissions(), $permissions)
);
$roles[$role->getName()] = $role;

$roleRestrictions = $role->getRestrictions();
foreach ($roleRestrictions as $name => & $restriction) {
$restriction = str_replace(
'$user.local_name$',
$user->getLocalUsername(),
$restriction
$permissions = array_merge(
$permissions,
array_diff($role->getPermissions(), $permissions)
);
$restrictions[$name][] = $restriction;
}

$role->setRestrictions($roleRestrictions);

if (! $isUnrestricted) {
$isUnrestricted = $role->isUnrestricted();
$roleRestrictions = $role->getRestrictions();
foreach ($roleRestrictions as $name => & $restriction) {
$restriction = str_replace(
'$user.local_name$',
$user->getLocalUsername(),
$restriction
);
$restrictions[$name][] = $restriction;
}

$role->setRestrictions($roleRestrictions);

if (! $isUnrestricted) {
$isUnrestricted = $role->isUnrestricted();
}
}
}
}
Expand Down

0 comments on commit 0a0805c

Please sign in to comment.