diff --git a/application/forms/Command/Object/DeleteCommentForm.php b/application/forms/Command/Object/DeleteCommentForm.php index 55e2a28a..25275baf 100644 --- a/application/forms/Command/Object/DeleteCommentForm.php +++ b/application/forms/Command/Object/DeleteCommentForm.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\Forms\Command\Object; +use Generator; use Icinga\Module\Icingadb\Command\Object\DeleteCommentCommand; use Icinga\Module\Icingadb\Forms\Command\CommandForm; use Icinga\Web\Notification; @@ -55,13 +56,17 @@ class DeleteCommentForm extends CommandForm protected function getCommands(Traversable $objects): Traversable { - foreach ($objects as $object) { - if (! $this->isGrantedOn('icingadb/command/comment/delete', $object->{$object->object_type})) { - continue; + $granted = (function () use ($objects): Generator { + foreach ($objects as $object) { + if ($this->isGrantedOn('icingadb/command/comment/delete', $object->{$object->object_type})) { + yield $object; + } } + })(); + if ($granted->valid()) { $command = new DeleteCommentCommand(); - $command->setCommentName($object->name); + $command->setObjects($granted); $command->setAuthor($this->getAuth()->getUser()->getUsername()); yield $command; diff --git a/library/Icingadb/Command/Object/DeleteCommentCommand.php b/library/Icingadb/Command/Object/DeleteCommentCommand.php index 8bfc2a37..c06a73c9 100644 --- a/library/Icingadb/Command/Object/DeleteCommentCommand.php +++ b/library/Icingadb/Command/Object/DeleteCommentCommand.php @@ -4,49 +4,10 @@ namespace Icinga\Module\Icingadb\Command\Object; -use Icinga\Module\Icingadb\Command\IcingaCommand; - /** * Delete a host or service comment */ -class DeleteCommentCommand extends IcingaCommand +class DeleteCommentCommand extends ObjectsCommand { use CommandAuthor; - - /** - * Name of the comment - * - * @var string - */ - protected $commentName; - - /** - * Get the name of the comment - * - * @return string - */ - public function getCommentName(): string - { - if ($this->commentName === null) { - throw new \LogicException( - 'You are accessing an unset property. Please make sure to set it beforehand.' - ); - } - - return $this->commentName; - } - - /** - * Set the name of the comment - * - * @param string $commentName - * - * @return $this - */ - public function setCommentName(string $commentName): self - { - $this->commentName = $commentName; - - return $this; - } } diff --git a/library/Icingadb/Command/Renderer/IcingaApiCommandRenderer.php b/library/Icingadb/Command/Renderer/IcingaApiCommandRenderer.php index 44671996..5b9f206d 100644 --- a/library/Icingadb/Command/Renderer/IcingaApiCommandRenderer.php +++ b/library/Icingadb/Command/Renderer/IcingaApiCommandRenderer.php @@ -274,10 +274,16 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface public function renderDeleteComment(DeleteCommentCommand $command): IcingaApiCommand { + $comments = []; + + foreach ($command->getObjects() as $object) { + $comments[] = $object->name; + } + $endpoint = 'actions/remove-comment'; $data = [ 'author' => $command->getAuthor(), - 'comment' => $command->getCommentName() + 'comments' => $comments ]; return IcingaApiCommand::create($endpoint, $data);