Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RoleForm: Highlight set privileges in headers #4345

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions application/forms/Security/RoleForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Icinga\Forms\RepositoryForm;
use Icinga\Util\StringHelper;
use Icinga\Web\Notification;
use ipl\Web\Widget\Icon;

/**
* Form for managing roles
Expand Down Expand Up @@ -119,17 +120,12 @@ public function createInsertElements(array $formData = array())
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', [
Expand All @@ -147,6 +143,11 @@ public function createInsertElements(array $formData = array())
$hasFullPerm = false;
foreach ($permissionList as $name => $spec) {
$elementName = $this->filterName($name);

if (isset($formData[$elementName]) && $formData[$elementName]) {
$anythingGranted = true;
}

if ($hasFullPerm || $hasAdminPerm) {
$elementName .= '_fake';
}
Expand All @@ -160,6 +161,10 @@ public function createInsertElements(array $formData = array())
]);
$this->addElement($denyCheckbox);
$this->removeFromIteration($denyCheckbox->getName());

if (isset($formData[$denyCheckbox->getName()]) && $formData[$denyCheckbox->getName()]) {
$anythingRefused = true;
}
}

$elements[] = $elementName;
Expand Down Expand Up @@ -223,6 +228,11 @@ public function createInsertElements(array $formData = array())

foreach ($this->providedRestrictions[$moduleName] as $name => $spec) {
$elementName = $this->filterName($name);

if (isset($formData[$elementName]) && $formData[$elementName]) {
$anythingRestricted = true;
}

$elements[] = $elementName;
$this->addElement(
'text',
Expand Down Expand Up @@ -257,6 +267,28 @@ public function createInsertElements(array $formData = array())
}
}

$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',
Expand Down
21 changes: 21 additions & 0 deletions public/css/icinga/widgets.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down