Skip to content

Commit

Permalink
Utilize Auth::isGrantedOn() where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Jan 29, 2021
1 parent 75227aa commit 45aec8c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
1 change: 1 addition & 0 deletions library/Icingadb/Common/CommandActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
/**
* Trait CommandActions
*
* @todo Handle `Auth::isGrantedOn` for each object separately in a command's form
* @method mixed fetchCommandTargets() Fetch command targets, \ipl\Orm\Query or \ipl\Orm\Model[]
* @method object getFeatureStatus() Get status of toggleable features
* @method Url getCommandTargetsUrl() Get url to view command targets, used as redirection target
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/CommentDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function assemble()
$this->add($details);
}

if ($this->getAuth()->hasPermission('monitoring/command/comment/delete')) {
if ($this->isGrantedOn('monitoring/command/comment/delete', $this->comment)) {
$this->add($this->createRemoveCommentForm());
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/DowntimeDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected function assemble()
$this->add(Html::tag('h2', t('Progress')));
$this->add($this->createTimeline());

if ($this->getAuth()->hasPermission('monitoring/command/downtime/delete')) {
if ($this->isGrantedOn('monitoring/command/downtime/delete', $this->downtime)) {
$this->add($this->createCancelDowntimeForm());
}
}
Expand Down
42 changes: 32 additions & 10 deletions library/Icingadb/Widget/Detail/MultiselectQuickActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ protected function assemble()

if (
$this->summary->$unacknowledged > $this->summary->$acks
&& $this->getAuth()->hasPermission('monitoring/command/acknowledge-problem')
&& $this->isGrantedOnType(
'monitoring/command/acknowledge-problem',
$this->type,
$this->getBaseFilter()
)
) {
$this->assembleAction(
'acknowledge',
Expand All @@ -53,7 +57,11 @@ protected function assemble()

if (
$this->summary->$acks > 0
&& $this->getAuth()->hasPermission('monitoring/command/remove-acknowledgement')
&& $this->isGrantedOnType(
'monitoring/command/remove-acknowledgement',
$this->type,
$this->getBaseFilter()
)
) {
$removeAckForm = (new RemoveAcknowledgementCommandForm())
->setAction($this->getLink('removeAcknowledgement'))
Expand All @@ -64,10 +72,14 @@ protected function assemble()
}

if (
$this->getAuth()->hasPermission('monitoring/command/schedule-check')
$this->isGrantedOnType('monitoring/command/schedule-check', $this->type, $this->getBaseFilter())
|| (
$this->summary->$activeChecks > 0
&& $this->getAuth()->hasPermission('monitoring/command/schedule-check/active-only')
&& $this->isGrantedOnType(
'monitoring/command/schedule-check/active-only',
$this->type,
$this->getBaseFilter()
)
)
) {
$checkNowForm = (new CheckNowCommandForm())
Expand All @@ -76,7 +88,7 @@ protected function assemble()
$this->add(Html::tag('li', new HtmlString($checkNowForm->render())));
}

if ($this->getAuth()->hasPermission('monitoring/command/comment/add')) {
if ($this->isGrantedOnType('monitoring/command/comment/add', $this->type, $this->getBaseFilter())) {
$this->assembleAction(
'addComment',
t('Comment'),
Expand All @@ -85,7 +97,13 @@ protected function assemble()
);
}

if ($this->getAuth()->hasPermission('monitoring/command/send-custom-notification')) {
if (
$this->isGrantedOnType(
'monitoring/command/send-custom-notification',
$this->type,
$this->getBaseFilter()
)
) {
$this->assembleAction(
'sendCustomNotification',
t('Notification'),
Expand All @@ -94,7 +112,7 @@ protected function assemble()
);
}

if ($this->getAuth()->hasPermission('monitoring/command/downtime/schedule')) {
if ($this->isGrantedOnType('monitoring/command/downtime/schedule', $this->type, $this->getBaseFilter())) {
$this->assembleAction(
'scheduleDowntime',
t('Downtime'),
Expand All @@ -104,10 +122,14 @@ protected function assemble()
}

if (
$this->getAuth()->hasPermission('monitoring/command/schedule-check')
$this->isGrantedOnType('monitoring/command/schedule-check', $this->type, $this->getBaseFilter())
|| (
$this->summary->$activeChecks > 0
&& $this->getAuth()->hasPermission('monitoring/command/schedule-check/active-only')
&& $this->isGrantedOnType(
'monitoring/command/schedule-check/active-only',
$this->type,
$this->getBaseFilter()
)
)
) {
$this->assembleAction(
Expand All @@ -118,7 +140,7 @@ protected function assemble()
);
}

if ($this->getAuth()->hasPermission('monitoring/command/process-check-result')) {
if ($this->isGrantedOnType('monitoring/command/process-check-result', $this->type, $this->getBaseFilter())) {
$this->assembleAction(
'processCheckresult',
t('Process check result'),
Expand Down
20 changes: 10 additions & 10 deletions library/Icingadb/Widget/Detail/QuickActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ protected function assemble()
{
if ($this->object->state->is_problem) {
if ($this->object->state->is_acknowledged) {
if ($this->getAuth()->hasPermission('monitoring/command/remove-acknowledgement')) {
if ($this->isGrantedOn('monitoring/command/remove-acknowledgement', $this->object)) {
$removeAckForm = (new RemoveAcknowledgementCommandForm())
->setAction($this->getLink('removeAcknowledgement'))
->setLabelEnabled(true)
->setObjects([true]);

$this->add(Html::tag('li', new HtmlString($removeAckForm->render())));
}
} elseif ($this->getAuth()->hasPermission('monitoring/command/acknowledge-problem')) {
} elseif ($this->isGrantedOn('monitoring/command/acknowledge-problem', $this->object)) {
$this->assembleAction(
'acknowledge',
t('Acknowledge'),
Expand All @@ -55,10 +55,10 @@ protected function assemble()
}

if (
$this->getAuth()->hasPermission('monitoring/command/schedule-check')
$this->isGrantedOn('monitoring/command/schedule-check', $this->object)
|| (
$this->object->active_checks_enabled
&& $this->getAuth()->hasPermission('monitoring/command/schedule-check/active-only')
&& $this->isGrantedOn('monitoring/command/schedule-check/active-only', $this->object)
)
) {
$checkNowForm = (new CheckNowCommandForm())
Expand All @@ -67,7 +67,7 @@ protected function assemble()
$this->add(Html::tag('li', new HtmlString($checkNowForm->render())));
}

if ($this->getAuth()->hasPermission('monitoring/command/comment/add')) {
if ($this->isGrantedOn('monitoring/command/comment/add', $this->object)) {
$this->assembleAction(
'addComment',
t('Comment', 'verb'),
Expand All @@ -76,7 +76,7 @@ protected function assemble()
);
}

if ($this->getAuth()->hasPermission('monitoring/command/send-custom-notification')) {
if ($this->isGrantedOn('monitoring/command/send-custom-notification', $this->object)) {
$this->assembleAction(
'sendCustomNotification',
t('Notification'),
Expand All @@ -85,7 +85,7 @@ protected function assemble()
);
}

if ($this->getAuth()->hasPermission('monitoring/command/downtime/schedule')) {
if ($this->isGrantedOn('monitoring/command/downtime/schedule', $this->object)) {
$this->assembleAction(
'scheduleDowntime',
t('Downtime'),
Expand All @@ -95,10 +95,10 @@ protected function assemble()
}

if (
$this->getAuth()->hasPermission('monitoring/command/schedule-check')
$this->isGrantedOn('monitoring/command/schedule-check', $this->object)
|| (
$this->object->active_checks_enabled
&& $this->getAuth()->hasPermission('monitoring/command/schedule-check/active-only')
&& $this->isGrantedOn('monitoring/command/schedule-check/active-only', $this->object)
)
) {
$this->assembleAction(
Expand All @@ -109,7 +109,7 @@ protected function assemble()
);
}

if ($this->getAuth()->hasPermission('monitoring/command/process-check-result')) {
if ($this->isGrantedOn('monitoring/command/process-check-result', $this->object)) {
$this->assembleAction(
'processCheckresult',
t('Process check result'),
Expand Down

0 comments on commit 45aec8c

Please sign in to comment.