Merge pull request #4155 from Icinga/feature/transmit-author-when-removing-downtimes-comments-and-acks-2281

Transmit author when removing downtimes comments and acks
This commit is contained in:
Johannes Meyer 2020-05-14 14:16:58 +02:00 committed by GitHub
commit d3baedb766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 59 additions and 36 deletions

View File

@ -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());

View File

@ -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);
}

View File

@ -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());

View File

@ -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);
}

View File

@ -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(

View File

@ -0,0 +1,38 @@
<?php
/* Icinga Web 2 | (c) 2020 Icinga GmbH | GPLv2+ */
namespace Icinga\Module\Monitoring\Command\Object;
trait CommandAuthor
{
/**
* Author of the command
*
* @var string
*/
protected $author;
/**
* 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;
}
}

View File

@ -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
*

View File

@ -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
*

View File

@ -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.

View File

@ -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
*

View File

@ -237,25 +237,27 @@ 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);
}
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);
}
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);
}