From b4e7d808072d915ad39a0c5625fd283d214b60cc Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 14 May 2020 13:50:48 +0200 Subject: [PATCH 1/5] Introduce trait `CommandAuthor` --- .../Command/Object/CommandAuthor.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 modules/monitoring/library/Monitoring/Command/Object/CommandAuthor.php diff --git a/modules/monitoring/library/Monitoring/Command/Object/CommandAuthor.php b/modules/monitoring/library/Monitoring/Command/Object/CommandAuthor.php new file mode 100644 index 000000000..577e3df76 --- /dev/null +++ b/modules/monitoring/library/Monitoring/Command/Object/CommandAuthor.php @@ -0,0 +1,38 @@ +author = (string) $author; + return $this; + } + + /** + * Get the author + * + * @return string + */ + public function getAuthor() + { + return $this->author; + } +} From a2009913c919055d1828e1a275a4984c16727e10 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 14 May 2020 13:51:21 +0200 Subject: [PATCH 2/5] WithCommentCommand: Utilize `CommandAuthor` --- .../Command/Object/WithCommentCommand.php | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Command/Object/WithCommentCommand.php b/modules/monitoring/library/Monitoring/Command/Object/WithCommentCommand.php index 511b769e6..aa2e43994 100644 --- a/modules/monitoring/library/Monitoring/Command/Object/WithCommentCommand.php +++ b/modules/monitoring/library/Monitoring/Command/Object/WithCommentCommand.php @@ -8,12 +8,7 @@ namespace Icinga\Module\Monitoring\Command\Object; */ abstract class WithCommentCommand extends ObjectCommand { - /** - * Author of the comment - * - * @var string - */ - protected $author; + use CommandAuthor; /** * Comment @@ -22,29 +17,6 @@ abstract class WithCommentCommand extends ObjectCommand */ protected $comment; - /** - * Set the author - * - * @param string $author - * - * @return $this - */ - public function setAuthor($author) - { - $this->author = (string) $author; - return $this; - } - - /** - * Get the author - * - * @return string - */ - public function getAuthor() - { - return $this->author; - } - /** * Set the comment * From 287edb79326d1b8b4d85fc91383023a1b547e179 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 14 May 2020 13:54:04 +0200 Subject: [PATCH 3/5] Transmit the user who deletes a comment --- .../forms/Command/Object/DeleteCommentCommandForm.php | 1 + .../forms/Command/Object/DeleteCommentsCommandForm.php | 1 + .../Monitoring/Command/Object/DeleteCommentCommand.php | 2 ++ .../Command/Renderer/IcingaApiCommandRenderer.php | 7 ++++--- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/application/forms/Command/Object/DeleteCommentCommandForm.php b/modules/monitoring/application/forms/Command/Object/DeleteCommentCommandForm.php index 366d7ebc8..cd15b19cf 100644 --- a/modules/monitoring/application/forms/Command/Object/DeleteCommentCommandForm.php +++ b/modules/monitoring/application/forms/Command/Object/DeleteCommentCommandForm.php @@ -94,6 +94,7 @@ class DeleteCommentCommandForm extends CommandForm { $cmd = new DeleteCommentCommand(); $cmd + ->setAuthor($this->Auth()->getUser()->getUsername()) ->setCommentId($this->getElement('comment_id')->getValue()) ->setCommentName($this->getElement('comment_name')->getValue()) ->setIsService($this->getElement('comment_is_service')->getValue()); diff --git a/modules/monitoring/application/forms/Command/Object/DeleteCommentsCommandForm.php b/modules/monitoring/application/forms/Command/Object/DeleteCommentsCommandForm.php index fb8b13099..70ea7b8db 100644 --- a/modules/monitoring/application/forms/Command/Object/DeleteCommentsCommandForm.php +++ b/modules/monitoring/application/forms/Command/Object/DeleteCommentsCommandForm.php @@ -73,6 +73,7 @@ class DeleteCommentsCommandForm extends CommandForm $cmd ->setCommentId($comment->id) ->setCommentName($comment->name) + ->setAuthor($this->Auth()->getUser()->getUsername()) ->setIsService(isset($comment->service_description)); $this->getTransport($this->request)->send($cmd); } diff --git a/modules/monitoring/library/Monitoring/Command/Object/DeleteCommentCommand.php b/modules/monitoring/library/Monitoring/Command/Object/DeleteCommentCommand.php index 4d791064f..348175a39 100644 --- a/modules/monitoring/library/Monitoring/Command/Object/DeleteCommentCommand.php +++ b/modules/monitoring/library/Monitoring/Command/Object/DeleteCommentCommand.php @@ -10,6 +10,8 @@ use Icinga\Module\Monitoring\Command\IcingaCommand; */ class DeleteCommentCommand extends IcingaCommand { + use CommandAuthor; + /** * ID of the comment that is to be deleted * diff --git a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php index 81883618d..c22424383 100644 --- a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php +++ b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php @@ -237,9 +237,10 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface public function renderDeleteComment(DeleteCommentCommand $command) { $endpoint = 'actions/remove-comment'; - $data = array( - 'comment' => $command->getCommentName() - ); + $data = [ + 'author' => $command->getAuthor(), + 'comment' => $command->getCommentName() + ]; return IcingaApiCommand::create($endpoint, $data); } From 08bc671fb74aceeeaf20565a4fd57c3fa8453ae2 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 14 May 2020 13:58:03 +0200 Subject: [PATCH 4/5] Transmit the user who cancels a downtime --- .../forms/Command/Object/DeleteDowntimeCommandForm.php | 1 + .../forms/Command/Object/DeleteDowntimesCommandForm.php | 1 + .../Monitoring/Command/Object/DeleteDowntimeCommand.php | 2 ++ .../Command/Renderer/IcingaApiCommandRenderer.php | 7 ++++--- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php b/modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php index be2109eec..5b3f49adc 100644 --- a/modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php +++ b/modules/monitoring/application/forms/Command/Object/DeleteDowntimeCommandForm.php @@ -94,6 +94,7 @@ class DeleteDowntimeCommandForm extends CommandForm { $cmd = new DeleteDowntimeCommand(); $cmd + ->setAuthor($this->Auth()->getUser()->getUsername()) ->setDowntimeId($this->getElement('downtime_id')->getValue()) ->setDowntimeName($this->getElement('downtime_name')->getValue()) ->setIsService($this->getElement('downtime_is_service')->getValue()); diff --git a/modules/monitoring/application/forms/Command/Object/DeleteDowntimesCommandForm.php b/modules/monitoring/application/forms/Command/Object/DeleteDowntimesCommandForm.php index e278409da..d4ee80348 100644 --- a/modules/monitoring/application/forms/Command/Object/DeleteDowntimesCommandForm.php +++ b/modules/monitoring/application/forms/Command/Object/DeleteDowntimesCommandForm.php @@ -73,6 +73,7 @@ class DeleteDowntimesCommandForm extends CommandForm $delDowntime ->setDowntimeId($downtime->id) ->setDowntimeName($downtime->name) + ->setAuthor($this->Auth()->getUser()->getUsername()) ->setIsService(isset($downtime->service_description)); $this->getTransport($this->request)->send($delDowntime); } diff --git a/modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php b/modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php index 63f4bbce3..a31486442 100644 --- a/modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php +++ b/modules/monitoring/library/Monitoring/Command/Object/DeleteDowntimeCommand.php @@ -10,6 +10,8 @@ use Icinga\Module\Monitoring\Command\IcingaCommand; */ class DeleteDowntimeCommand extends IcingaCommand { + use CommandAuthor; + /** * ID of the downtime that is to be deleted * diff --git a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php index c22424383..7c22ef549 100644 --- a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php +++ b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php @@ -247,9 +247,10 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface public function renderDeleteDowntime(DeleteDowntimeCommand $command) { $endpoint = 'actions/remove-downtime'; - $data = array( - 'downtime' => $command->getDowntimeName() - ); + $data = [ + 'author' => $command->getAuthor(), + 'downtime' => $command->getDowntimeName() + ]; return IcingaApiCommand::create($endpoint, $data); } From f6edad93361427f104007db769b1dc5b581ddae3 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 14 May 2020 13:58:19 +0200 Subject: [PATCH 5/5] Transmit the user who clears an acknowledgement --- .../forms/Command/Object/RemoveAcknowledgementCommandForm.php | 1 + .../Monitoring/Command/Object/RemoveAcknowledgementCommand.php | 2 ++ .../Monitoring/Command/Renderer/IcingaApiCommandRenderer.php | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/application/forms/Command/Object/RemoveAcknowledgementCommandForm.php b/modules/monitoring/application/forms/Command/Object/RemoveAcknowledgementCommandForm.php index 7d6672225..e45a055a8 100644 --- a/modules/monitoring/application/forms/Command/Object/RemoveAcknowledgementCommandForm.php +++ b/modules/monitoring/application/forms/Command/Object/RemoveAcknowledgementCommandForm.php @@ -107,6 +107,7 @@ class RemoveAcknowledgementCommandForm extends ObjectsCommandForm /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */ $removeAck = new RemoveAcknowledgementCommand(); $removeAck->setObject($object); + $removeAck->setAuthor($this->Auth()->getUser()->getUsername()); $this->getTransport($this->request)->send($removeAck); } Notification::success(mtp( diff --git a/modules/monitoring/library/Monitoring/Command/Object/RemoveAcknowledgementCommand.php b/modules/monitoring/library/Monitoring/Command/Object/RemoveAcknowledgementCommand.php index eb2b95ec2..31c81807d 100644 --- a/modules/monitoring/library/Monitoring/Command/Object/RemoveAcknowledgementCommand.php +++ b/modules/monitoring/library/Monitoring/Command/Object/RemoveAcknowledgementCommand.php @@ -8,6 +8,8 @@ namespace Icinga\Module\Monitoring\Command\Object; */ class RemoveAcknowledgementCommand extends ObjectCommand { + use CommandAuthor; + /** * (non-PHPDoc) * @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation. diff --git a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php index 7c22ef549..9557db3c4 100644 --- a/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php +++ b/modules/monitoring/library/Monitoring/Command/Renderer/IcingaApiCommandRenderer.php @@ -257,7 +257,7 @@ class IcingaApiCommandRenderer implements IcingaCommandRendererInterface public function renderRemoveAcknowledgement(RemoveAcknowledgementCommand $command) { $endpoint = 'actions/remove-acknowledgement'; - $data = array(); + $data = ['author' => $command->getAuthor()]; $this->applyFilter($data, $command->getObject()); return IcingaApiCommand::create($endpoint, $data); }