mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
comments: Support automated removal
This commit is contained in:
parent
ed4072221f
commit
c78d664f79
4 changed files with 50 additions and 32 deletions
|
|
@ -5,6 +5,7 @@
|
|||
namespace Icinga\Module\Icingadb\Controllers;
|
||||
|
||||
use GuzzleHttp\Psr7\ServerRequest;
|
||||
use Icinga\Module\Icingadb\Common\CommandActions;
|
||||
use Icinga\Module\Icingadb\Common\Links;
|
||||
use Icinga\Module\Icingadb\Forms\Command\Object\DeleteCommentForm;
|
||||
use Icinga\Module\Icingadb\Model\Comment;
|
||||
|
|
@ -13,12 +14,17 @@ use Icinga\Module\Icingadb\Web\Controller;
|
|||
use Icinga\Module\Icingadb\Web\Control\ViewModeSwitcher;
|
||||
use Icinga\Module\Icingadb\Widget\ItemList\ObjectList;
|
||||
use Icinga\Module\Icingadb\Widget\ShowMore;
|
||||
use ipl\Orm\Model;
|
||||
use ipl\Orm\Query;
|
||||
use ipl\Stdlib\Filter;
|
||||
use ipl\Web\Control\LimitControl;
|
||||
use ipl\Web\Control\SortControl;
|
||||
use ipl\Web\Url;
|
||||
|
||||
class CommentsController extends Controller
|
||||
{
|
||||
use CommandActions;
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$this->addTitleTab(t('Comments'));
|
||||
|
|
@ -107,34 +113,9 @@ class CommentsController extends Controller
|
|||
|
||||
public function deleteAction()
|
||||
{
|
||||
$this->assertIsGrantedOnCommandTargets('icingadb/command/comment/delete');
|
||||
$this->setTitle(t('Remove Comments'));
|
||||
|
||||
$db = $this->getDb();
|
||||
|
||||
$comments = Comment::on($db)->with([
|
||||
'host',
|
||||
'host.state',
|
||||
'service',
|
||||
'service.host',
|
||||
'service.host.state',
|
||||
'service.state'
|
||||
]);
|
||||
|
||||
$this->filter($comments);
|
||||
|
||||
$form = (new DeleteCommentForm())
|
||||
->setObjects($comments)
|
||||
->setRedirectUrl(Links::comments()->getAbsoluteUrl())
|
||||
->on(DeleteCommentForm::ON_SUCCESS, function ($form) {
|
||||
// This forces the column to reload nearly instantly after the redirect
|
||||
// and ensures the effect of the command is visible to the user asap
|
||||
$this->getResponse()->setAutoRefreshInterval(1);
|
||||
|
||||
$this->redirectNow($form->getRedirectUrl());
|
||||
})
|
||||
->handleRequest(ServerRequest::fromGlobals());
|
||||
|
||||
$this->addContent($form);
|
||||
$this->handleCommandForm(DeleteCommentForm::class);
|
||||
}
|
||||
|
||||
public function detailsAction()
|
||||
|
|
@ -202,4 +183,36 @@ class CommentsController extends Controller
|
|||
$this->getDocument()->add($editor);
|
||||
$this->setTitle(t('Adjust Filter'));
|
||||
}
|
||||
|
||||
protected function getCommandTargetsUrl(): Url
|
||||
{
|
||||
return Url::fromPath('__CLOSE__');
|
||||
}
|
||||
|
||||
protected function fetchCommandTargets(): Query
|
||||
{
|
||||
$comments = Comment::on($this->getDb())->with([
|
||||
'host',
|
||||
'host.state',
|
||||
'service',
|
||||
'service.host',
|
||||
'service.host.state',
|
||||
'service.state'
|
||||
]);
|
||||
|
||||
$this->filter($comments);
|
||||
|
||||
return $comments;
|
||||
}
|
||||
|
||||
public function isGrantedOn(string $permission, Model $object): bool
|
||||
{
|
||||
return parent::isGrantedOn($permission, $object->{$object->object_type});
|
||||
}
|
||||
|
||||
public function isGrantedOnType(string $permission, string $type, Filter\Rule $filter, bool $cache = true): bool
|
||||
{
|
||||
return parent::isGrantedOnType($permission, 'host', $filter, $cache)
|
||||
|| parent::isGrantedOnType($permission, 'service', $filter, $cache);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,15 +9,12 @@ 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
|
||||
{
|
||||
use RedirectOption;
|
||||
|
||||
protected $defaultAttributes = ['class' => 'inline'];
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -38,7 +35,6 @@ class DeleteCommentForm extends CommandForm
|
|||
|
||||
protected function assembleElements()
|
||||
{
|
||||
$this->addElement($this->createRedirectOption());
|
||||
}
|
||||
|
||||
protected function assembleSubmitButton()
|
||||
|
|
|
|||
|
|
@ -131,6 +131,16 @@ Please have a look at the [Monitoring Plugins Development Guidelines](https://ww
|
|||
| expire | n | BoolEnum | - |
|
||||
| expire_time | y | DateTime | expire |
|
||||
|
||||
### Delete Comments
|
||||
|
||||
#### Routes
|
||||
|
||||
* icingadb/comments/delete
|
||||
|
||||
#### Options
|
||||
|
||||
None.
|
||||
|
||||
### Check Now
|
||||
|
||||
#### Routes
|
||||
|
|
|
|||
|
|
@ -114,7 +114,6 @@ class CommentDetail extends BaseHtmlElement
|
|||
|
||||
return (new DeleteCommentForm())
|
||||
->setObjects([$this->comment])
|
||||
->populate(['redirect' => '__BACK__'])
|
||||
->setAction($action->getAbsoluteUrl());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue