Only show edit role link if user has the appropriate permission

This commit is contained in:
Philipp Dorschner 2019-09-25 15:04:54 +02:00 committed by Johannes Meyer
parent 57b64f85bf
commit 564fb8c320
2 changed files with 22 additions and 16 deletions

View File

@ -170,6 +170,7 @@ class UserController extends AuthBackendController
$admissionLoader = new AdmissionLoader(); $admissionLoader = new AdmissionLoader();
$admissionLoader->applyRoles($userObj); $admissionLoader->applyRoles($userObj);
$this->view->userObj = $userObj; $this->view->userObj = $userObj;
$this->view->allowedToEditRoles = $this->hasPermission('config/authentication/roles/edit');
} }
/** /**

View File

@ -43,22 +43,27 @@ use Icinga\Data\Selectable;
<tr> <tr>
<th><?= $this->translate('Role Memberships'); ?></th> <th><?= $this->translate('Role Memberships'); ?></th>
<td> <td>
<?php $roleObj = $userObj->getRoles(); ?> <?php $roleObj = $userObj->getRoles(); ?>
<?php if (! empty($roleObj)): ?> <?php if (! empty($roleObj)): ?>
<ul class="role-memberships"> <ul class="role-memberships">
<?php foreach($roleObj as $role): ?> <?php foreach($roleObj as $role): ?>
<li><?= $this->qlink( <li>
$role->getName(), <?php if ($this->allowedToEditRoles): ?>
'role/edit', <?= $this->qlink(
['role' => $role->getName()], $role->getName(),
['title' => sprintf($this->translate('Edit role %s'), $role->getName())] 'role/edit',
) ?> ['role' => $role->getName()],
</li> ['title' => sprintf($this->translate('Edit role %s'), $role->getName())]
<?php endforeach ?> ) ?>
</ul> <?php else: ?>
<?php else: ?> <?= $role->getName() ?>
<p><?= $this->translate('No memberships found'); ?></p> <?php endif ?>
<?php endif ?> </li>
<?php endforeach ?>
</ul>
<?php else: ?>
<p><?= $this->translate('No memberships found'); ?></p>
<?php endif ?>
</td> </td>
</tr> </tr>
</table> </table>