From be4626482ba8761da39746a6ac60d133d3852a0f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:45:00 +0200 Subject: Merging upstream version 1.1.2. Signed-off-by: Daniel Baumann --- .../Command/Object/AcknowledgeProblemForm.php | 10 ++++++-- .../forms/Command/Object/AddCommentForm.php | 10 ++++++-- application/forms/Command/Object/CheckNowForm.php | 27 ++++++++++------------ .../forms/Command/Object/DeleteCommentForm.php | 17 +++++++------- .../forms/Command/Object/DeleteDowntimeForm.php | 21 ++++++++--------- .../Command/Object/ProcessCheckResultForm.php | 17 +++++++------- .../Command/Object/RemoveAcknowledgementForm.php | 10 ++++++-- .../forms/Command/Object/ScheduleCheckForm.php | 27 ++++++++++------------ .../Command/Object/ScheduleHostDowntimeForm.php | 10 ++++++-- .../Command/Object/ScheduleServiceDowntimeForm.php | 10 ++++++-- .../Command/Object/SendCustomNotificationForm.php | 10 ++++++-- .../Command/Object/ToggleObjectFeaturesForm.php | 9 ++++++-- 12 files changed, 104 insertions(+), 74 deletions(-) (limited to 'application/forms/Command/Object') diff --git a/application/forms/Command/Object/AcknowledgeProblemForm.php b/application/forms/Command/Object/AcknowledgeProblemForm.php index 81b93e2..f5e7923 100644 --- a/application/forms/Command/Object/AcknowledgeProblemForm.php +++ b/application/forms/Command/Object/AcknowledgeProblemForm.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; +use CallbackFilterIterator; use DateInterval; use DateTime; use Icinga\Application\Config; @@ -14,9 +15,11 @@ use Icinga\Web\Notification; use ipl\Html\Attributes; use ipl\Html\HtmlElement; use ipl\Html\Text; +use ipl\Orm\Model; use ipl\Validator\CallbackValidator; use ipl\Web\FormDecorator\IcingaFormDecorator; use ipl\Web\Widget\Icon; +use Iterator; use Traversable; use function ipl\Stdlib\iterable_value_first; @@ -186,10 +189,13 @@ class AcknowledgeProblemForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = $this->filterGrantedOn('icingadb/command/acknowledge-problem', $objects); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $this->isGrantedOn('icingadb/command/acknowledge-problem', $object); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new AcknowledgeProblemCommand(); $command->setObjects($granted); diff --git a/application/forms/Command/Object/AddCommentForm.php b/application/forms/Command/Object/AddCommentForm.php index 9cd0754..e991e84 100644 --- a/application/forms/Command/Object/AddCommentForm.php +++ b/application/forms/Command/Object/AddCommentForm.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; +use CallbackFilterIterator; use DateInterval; use DateTime; use Icinga\Application\Config; @@ -14,9 +15,11 @@ use Icinga\Web\Notification; use ipl\Html\Attributes; use ipl\Html\HtmlElement; use ipl\Html\Text; +use ipl\Orm\Model; use ipl\Validator\CallbackValidator; use ipl\Web\FormDecorator\IcingaFormDecorator; use ipl\Web\Widget\Icon; +use Iterator; use Traversable; use function ipl\Stdlib\iterable_value_first; @@ -141,10 +144,13 @@ class AddCommentForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = $this->filterGrantedOn('icingadb/command/comment/add', $objects); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $this->isGrantedOn('icingadb/command/comment/add', $object); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new AddCommentCommand(); $command->setObjects($granted); diff --git a/application/forms/Command/Object/CheckNowForm.php b/application/forms/Command/Object/CheckNowForm.php index b7a506c..eb1e03b 100644 --- a/application/forms/Command/Object/CheckNowForm.php +++ b/application/forms/Command/Object/CheckNowForm.php @@ -4,11 +4,13 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; -use Generator; +use CallbackFilterIterator; use Icinga\Module\Icingadb\Command\Object\ScheduleCheckCommand; use Icinga\Module\Icingadb\Forms\Command\CommandForm; use Icinga\Web\Notification; +use ipl\Orm\Model; use ipl\Web\Widget\Icon; +use Iterator; use Traversable; class CheckNowForm extends CommandForm @@ -44,22 +46,17 @@ class CheckNowForm extends CommandForm ); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = (function () use ($objects): Generator { - foreach ($objects as $object) { - if ( - $this->isGrantedOn('icingadb/command/schedule-check', $object) - || ( - $object->active_checks_enabled - && $this->isGrantedOn('icingadb/command/schedule-check/active-only', $object) - ) - ) { - yield $object; - } - } - })(); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $this->isGrantedOn('icingadb/command/schedule-check', $object) + || ( + $object->active_checks_enabled + && $this->isGrantedOn('icingadb/command/schedule-check/active-only', $object) + ); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new ScheduleCheckCommand(); $command->setObjects($granted); diff --git a/application/forms/Command/Object/DeleteCommentForm.php b/application/forms/Command/Object/DeleteCommentForm.php index 25275ba..a35fc2e 100644 --- a/application/forms/Command/Object/DeleteCommentForm.php +++ b/application/forms/Command/Object/DeleteCommentForm.php @@ -4,12 +4,14 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; -use Generator; +use CallbackFilterIterator; use Icinga\Module\Icingadb\Command\Object\DeleteCommentCommand; use Icinga\Module\Icingadb\Forms\Command\CommandForm; use Icinga\Web\Notification; +use ipl\Orm\Model; use ipl\Web\Common\RedirectOption; use ipl\Web\Widget\Icon; +use Iterator; use Traversable; class DeleteCommentForm extends CommandForm @@ -54,16 +56,13 @@ class DeleteCommentForm extends CommandForm ); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = (function () use ($objects): Generator { - foreach ($objects as $object) { - if ($this->isGrantedOn('icingadb/command/comment/delete', $object->{$object->object_type})) { - yield $object; - } - } - })(); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $this->isGrantedOn('icingadb/command/comment/delete', $object->{$object->object_type}); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new DeleteCommentCommand(); $command->setObjects($granted); diff --git a/application/forms/Command/Object/DeleteDowntimeForm.php b/application/forms/Command/Object/DeleteDowntimeForm.php index 5f695b9..b13bcc5 100644 --- a/application/forms/Command/Object/DeleteDowntimeForm.php +++ b/application/forms/Command/Object/DeleteDowntimeForm.php @@ -4,12 +4,14 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; -use Generator; +use CallbackFilterIterator; use Icinga\Module\Icingadb\Command\Object\DeleteDowntimeCommand; use Icinga\Module\Icingadb\Forms\Command\CommandForm; use Icinga\Web\Notification; +use ipl\Orm\Model; use ipl\Web\Common\RedirectOption; use ipl\Web\Widget\Icon; +use Iterator; use Traversable; class DeleteDowntimeForm extends CommandForm @@ -66,19 +68,14 @@ class DeleteDowntimeForm extends CommandForm ); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = (function () use ($objects): Generator { - foreach ($objects as $object) { - if ( - $this->isGrantedOn('icingadb/command/downtime/delete', $object->{$object->object_type}) - && $object->scheduled_by === null - ) { - yield $object; - } - } - })(); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $object->scheduled_by === null + && $this->isGrantedOn('icingadb/command/downtime/delete', $object->{$object->object_type}); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new DeleteDowntimeCommand(); $command->setObjects($granted); diff --git a/application/forms/Command/Object/ProcessCheckResultForm.php b/application/forms/Command/Object/ProcessCheckResultForm.php index 5764bf8..7c612bf 100644 --- a/application/forms/Command/Object/ProcessCheckResultForm.php +++ b/application/forms/Command/Object/ProcessCheckResultForm.php @@ -4,7 +4,7 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; -use Generator; +use CallbackFilterIterator; use Icinga\Module\Icingadb\Command\Object\ProcessCheckResultCommand; use Icinga\Module\Icingadb\Forms\Command\CommandForm; use Icinga\Module\Icingadb\Model\Host; @@ -15,6 +15,7 @@ use ipl\Html\Text; use ipl\Orm\Model; use ipl\Web\FormDecorator\IcingaFormDecorator; use ipl\Web\Widget\Icon; +use Iterator; use Traversable; use function ipl\Stdlib\iterable_value_first; @@ -133,16 +134,14 @@ class ProcessCheckResultForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = (function () use ($objects): Generator { - foreach ($this->filterGrantedOn('icingadb/command/process-check-result', $objects) as $object) { - if ($object->passive_checks_enabled) { - yield $object; - } - } - })(); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $object->passive_checks_enabled + && $this->isGrantedOn('icingadb/command/process-check-result', $object); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new ProcessCheckResultCommand(); $command->setObjects($granted); diff --git a/application/forms/Command/Object/RemoveAcknowledgementForm.php b/application/forms/Command/Object/RemoveAcknowledgementForm.php index 8697985..d81fe7f 100644 --- a/application/forms/Command/Object/RemoveAcknowledgementForm.php +++ b/application/forms/Command/Object/RemoveAcknowledgementForm.php @@ -4,11 +4,14 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; +use CallbackFilterIterator; use Icinga\Module\Icingadb\Command\Object\RemoveAcknowledgementCommand; use Icinga\Module\Icingadb\Forms\Command\CommandForm; use Icinga\Module\Icingadb\Model\Host; use Icinga\Web\Notification; +use ipl\Orm\Model; use ipl\Web\Widget\Icon; +use Iterator; use Traversable; use function ipl\Stdlib\iterable_value_first; @@ -62,10 +65,13 @@ class RemoveAcknowledgementForm extends CommandForm ); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = $this->filterGrantedOn('icingadb/command/remove-acknowledgement', $objects); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $this->isGrantedOn('icingadb/command/remove-acknowledgement', $object); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new RemoveAcknowledgementCommand(); $command->setObjects($granted); diff --git a/application/forms/Command/Object/ScheduleCheckForm.php b/application/forms/Command/Object/ScheduleCheckForm.php index 9b32ea1..bdeba53 100644 --- a/application/forms/Command/Object/ScheduleCheckForm.php +++ b/application/forms/Command/Object/ScheduleCheckForm.php @@ -4,9 +4,9 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; +use CallbackFilterIterator; use DateInterval; use DateTime; -use Generator; use Icinga\Module\Icingadb\Command\Object\ScheduleCheckCommand; use Icinga\Module\Icingadb\Forms\Command\CommandForm; use Icinga\Module\Icingadb\Model\Host; @@ -14,8 +14,10 @@ use Icinga\Web\Notification; use ipl\Html\Attributes; use ipl\Html\HtmlElement; use ipl\Html\Text; +use ipl\Orm\Model; use ipl\Web\FormDecorator\IcingaFormDecorator; use ipl\Web\Widget\Icon; +use Iterator; use Traversable; use function ipl\Stdlib\iterable_value_first; @@ -109,22 +111,17 @@ class ScheduleCheckForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = (function () use ($objects): Generator { - foreach ($objects as $object) { - if ( - $this->isGrantedOn('icingadb/command/schedule-check', $object) - || ( - $object->active_checks_enabled - && $this->isGrantedOn('icingadb/command/schedule-check/active-only', $object) - ) - ) { - yield $object; - } - } - })(); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $this->isGrantedOn('icingadb/command/schedule-check', $object) + || ( + $object->active_checks_enabled + && $this->isGrantedOn('icingadb/command/schedule-check/active-only', $object) + ); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new ScheduleCheckCommand(); $command->setObjects($granted); diff --git a/application/forms/Command/Object/ScheduleHostDowntimeForm.php b/application/forms/Command/Object/ScheduleHostDowntimeForm.php index bc21114..a09b00d 100644 --- a/application/forms/Command/Object/ScheduleHostDowntimeForm.php +++ b/application/forms/Command/Object/ScheduleHostDowntimeForm.php @@ -4,13 +4,16 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; +use CallbackFilterIterator; use DateInterval; use DateTime; use Icinga\Application\Config; use Icinga\Module\Icingadb\Command\Object\PropagateHostDowntimeCommand; use Icinga\Module\Icingadb\Command\Object\ScheduleHostDowntimeCommand; use Icinga\Web\Notification; +use ipl\Orm\Model; use ipl\Web\FormDecorator\IcingaFormDecorator; +use Iterator; use Traversable; class ScheduleHostDowntimeForm extends ScheduleServiceDowntimeForm @@ -87,10 +90,13 @@ class ScheduleHostDowntimeForm extends ScheduleServiceDowntimeForm $decorator->decorate($this->getElement('child_options')); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = $this->filterGrantedOn('icingadb/command/downtime/schedule', $objects); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $this->isGrantedOn('icingadb/command/downtime/schedule', $object); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { if (($childOptions = (int) $this->getValue('child_options'))) { $command = new PropagateHostDowntimeCommand(); diff --git a/application/forms/Command/Object/ScheduleServiceDowntimeForm.php b/application/forms/Command/Object/ScheduleServiceDowntimeForm.php index 184a4e8..b237408 100644 --- a/application/forms/Command/Object/ScheduleServiceDowntimeForm.php +++ b/application/forms/Command/Object/ScheduleServiceDowntimeForm.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; +use CallbackFilterIterator; use DateInterval; use DateTime; use Icinga\Application\Config; @@ -13,9 +14,11 @@ use Icinga\Web\Notification; use ipl\Html\Attributes; use ipl\Html\HtmlElement; use ipl\Html\Text; +use ipl\Orm\Model; use ipl\Validator\CallbackValidator; use ipl\Web\FormDecorator\IcingaFormDecorator; use ipl\Web\Widget\Icon; +use Iterator; use Traversable; class ScheduleServiceDowntimeForm extends CommandForm @@ -242,10 +245,13 @@ class ScheduleServiceDowntimeForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = $this->filterGrantedOn('icingadb/command/downtime/schedule', $objects); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $this->isGrantedOn('icingadb/command/downtime/schedule', $object); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new ScheduleServiceDowntimeCommand(); $command->setObjects($granted); diff --git a/application/forms/Command/Object/SendCustomNotificationForm.php b/application/forms/Command/Object/SendCustomNotificationForm.php index dfb1e96..4b0539e 100644 --- a/application/forms/Command/Object/SendCustomNotificationForm.php +++ b/application/forms/Command/Object/SendCustomNotificationForm.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; +use CallbackFilterIterator; use Icinga\Application\Config; use Icinga\Module\Icingadb\Command\Object\SendCustomNotificationCommand; use Icinga\Module\Icingadb\Forms\Command\CommandForm; @@ -12,8 +13,10 @@ use Icinga\Web\Notification; use ipl\Html\Attributes; use ipl\Html\HtmlElement; use ipl\Html\Text; +use ipl\Orm\Model; use ipl\Web\FormDecorator\IcingaFormDecorator; use ipl\Web\Widget\Icon; +use Iterator; use Traversable; use function ipl\Stdlib\iterable_value_first; @@ -108,10 +111,13 @@ class SendCustomNotificationForm extends CommandForm (new IcingaFormDecorator())->decorate($this->getElement('btn_submit')); } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { - $granted = $this->filterGrantedOn('icingadb/command/send-custom-notification', $objects); + $granted = new CallbackFilterIterator($objects, function (Model $object): bool { + return $this->isGrantedOn('icingadb/command/send-custom-notification', $object); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new SendCustomNotificationCommand(); $command->setObjects($granted); diff --git a/application/forms/Command/Object/ToggleObjectFeaturesForm.php b/application/forms/Command/Object/ToggleObjectFeaturesForm.php index 50767da..63530f6 100644 --- a/application/forms/Command/Object/ToggleObjectFeaturesForm.php +++ b/application/forms/Command/Object/ToggleObjectFeaturesForm.php @@ -4,12 +4,14 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; +use CallbackFilterIterator; use Icinga\Module\Icingadb\Command\Object\ToggleObjectFeatureCommand; use Icinga\Module\Icingadb\Forms\Command\CommandForm; use Icinga\Web\Notification; use ipl\Html\FormElement\CheckboxElement; use ipl\Orm\Model; use ipl\Web\FormDecorator\IcingaFormDecorator; +use Iterator; use Traversable; class ToggleObjectFeaturesForm extends CommandForm @@ -156,7 +158,7 @@ class ToggleObjectFeaturesForm extends CommandForm { } - protected function getCommands(Traversable $objects): Traversable + protected function getCommands(Iterator $objects): Traversable { foreach ($this->features as $feature => $spec) { if ($this->getElement($feature) instanceof CheckboxElement) { @@ -169,8 +171,11 @@ class ToggleObjectFeaturesForm extends CommandForm continue; } - $granted = $this->filterGrantedOn($spec['permission'], $objects); + $granted = new CallbackFilterIterator($objects, function (Model $object) use ($spec): bool { + return $this->isGrantedOn($spec['permission'], $object); + }); + $granted->rewind(); // Forwards the pointer to the first element if ($granted->valid()) { $command = new ToggleObjectFeatureCommand(); $command->setObjects($granted); -- cgit v1.2.3