RoleForm: Highlight set privileges in headers

resolves #4241
This commit is contained in:
Johannes Meyer 2021-04-08 09:51:55 +02:00
parent 6f317ade30
commit f782c08d80
2 changed files with 63 additions and 10 deletions

View File

@ -12,6 +12,7 @@ use Icinga\Forms\ConfigForm;
use Icinga\Forms\RepositoryForm;
use Icinga\Util\StringHelper;
use Icinga\Web\Notification;
use ipl\Web\Widget\Icon;
/**
* Form for managing roles
@ -119,17 +120,12 @@ class RoleForm extends RepositoryForm
foreach ($this->providedPermissions as $moduleName => $permissionList) {
$this->sortPermissions($permissionList);
$anythingGranted = false;
$anythingRefused = false;
$anythingRestricted = false;
$elements = [$moduleName . '_header'];
$this->addElement(
'note',
$moduleName . '_header',
[
'decorators' => ['ViewHelper'],
'value' => '<h3>' . ($moduleName !== 'application'
? sprintf('%s <em>%s</em>', $moduleName, $this->translate('Module'))
: 'Icinga Web 2') . '</h3>'
]
);
// The actual element is added last
$elements[] = 'permission_header';
$this->addElement('note', 'permission_header', [
@ -147,6 +143,11 @@ class RoleForm extends RepositoryForm
$hasFullPerm = false;
foreach ($permissionList as $name => $spec) {
$elementName = $this->filterName($name);
if (isset($formData[$elementName]) && $formData[$elementName]) {
$anythingGranted = true;
}
if ($hasFullPerm || $hasAdminPerm) {
$elementName .= '_fake';
}
@ -160,6 +161,10 @@ class RoleForm extends RepositoryForm
]);
$this->addElement($denyCheckbox);
$this->removeFromIteration($denyCheckbox->getName());
if (isset($formData[$denyCheckbox->getName()]) && $formData[$denyCheckbox->getName()]) {
$anythingRefused = true;
}
}
$elements[] = $elementName;
@ -223,6 +228,11 @@ class RoleForm extends RepositoryForm
foreach ($this->providedRestrictions[$moduleName] as $name => $spec) {
$elementName = $this->filterName($name);
if (isset($formData[$elementName]) && $formData[$elementName]) {
$anythingRestricted = true;
}
$elements[] = $elementName;
$this->addElement(
'text',
@ -257,6 +267,28 @@ class RoleForm extends RepositoryForm
}
}
$this->addElement(
'note',
$moduleName . '_header',
[
'decorators' => ['ViewHelper'],
'value' => '<h3>'
. '<span>' . ($moduleName !== 'application'
? sprintf('%s <em>%s</em>', $moduleName, $this->translate('Module'))
: 'Icinga Web 2'
) . '</span>'
. '<span class="privilege-preview">'
. ($hasAdminPerm || $anythingGranted ? new Icon('check-circle', ['class' => 'granted']) : '')
. ($anythingRefused ? new Icon('times-circle', ['class' => 'refused']) : '')
. (! $isUnrestricted && $anythingRestricted
? new Icon('filter', ['class' => 'restricted'])
: ''
)
. '</span>'
. '</h3>'
]
);
$this->addDisplayGroup($elements, $moduleName . '_elements', [
'decorators' => [
'FormElements',

View File

@ -230,6 +230,27 @@ form.role-form {
font-style: normal;
}
h3 {
> :first-child {
display: inline-block;
width: 20em / 1.167em; // element label width / h3 font-size
}
.privilege-preview .icon {
&.granted {
color: @color-granted;
}
&.refused {
color: @color-refused;
}
&.restricted {
color: @color-restricted;
}
}
}
fieldset.collapsible {
border: none;
padding: 0;