mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-29 00:34:05 +02:00
parent
e4d35d74e3
commit
3eb3d82f44
@ -26,6 +26,20 @@ $this->provideRestriction(
|
||||
)
|
||||
);
|
||||
|
||||
$this->provideRestriction(
|
||||
'director/service/apply/filter-by-name',
|
||||
$this->translate(
|
||||
'Filter available service apply rules'
|
||||
)
|
||||
);
|
||||
|
||||
$this->provideRestriction(
|
||||
'director/notification/apply/filter-by-name',
|
||||
$this->translate(
|
||||
'Filter available notification apply rules'
|
||||
)
|
||||
);
|
||||
|
||||
$this->provideSearchUrl($this->translate('Host configs'), 'director/hosts?limit=10', 60);
|
||||
|
||||
/*
|
||||
|
@ -10,6 +10,7 @@ use Icinga\Module\Director\Forms\IcingaMultiEditForm;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Web\ActionBar\ObjectsActionBar;
|
||||
use Icinga\Module\Director\Web\ActionBar\TemplateActionBar;
|
||||
use Icinga\Module\Director\Web\Table\ApplyRulesTable;
|
||||
use Icinga\Module\Director\Web\Table\ObjectSetTable;
|
||||
use Icinga\Module\Director\Web\Table\ObjectsTable;
|
||||
use Icinga\Module\Director\Web\Table\ServiceApplyRulesTable;
|
||||
@ -113,7 +114,10 @@ abstract class ObjectsController extends ActionController
|
||||
$this
|
||||
->assertPermission('director/admin')
|
||||
->addObjectsTabs()
|
||||
->addTitle($this->translate('All your Service Apply Rules'));
|
||||
->addTitle(
|
||||
$this->translate('All your %s Apply Rules'),
|
||||
$this->translate(ucfirst($this->getType()))
|
||||
);
|
||||
$this->actions()/*->add(
|
||||
$this->getBackToDashboardLink()
|
||||
)*/->add(
|
||||
@ -129,7 +133,9 @@ abstract class ObjectsController extends ActionController
|
||||
)
|
||||
);
|
||||
|
||||
ServiceApplyRulesTable::show($this, $this->db());
|
||||
$table = new ApplyRulesTable($this->db());
|
||||
$table->setType($this->getType());
|
||||
$table->renderTo($this);
|
||||
}
|
||||
|
||||
public function setsAction()
|
||||
|
@ -2,15 +2,18 @@
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Authentication\Auth;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Module\Director\Db\IcingaObjectFilterHelper;
|
||||
use Icinga\Module\Director\IcingaConfig\AssignRenderer;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use ipl\Db\Zf1\FilterRenderer;
|
||||
use ipl\Html\Icon;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
use ipl\Web\Url;
|
||||
use Zend_Db_Select as ZfSelect;
|
||||
|
||||
class ApplyRulesTable extends ZfQueryBasedTable
|
||||
{
|
||||
@ -110,6 +113,23 @@ class ApplyRulesTable extends ZfQueryBasedTable
|
||||
return $links;
|
||||
}
|
||||
|
||||
protected function applyRestrictions(ZfSelect $query)
|
||||
{
|
||||
$auth = Auth::getInstance();
|
||||
$type = $this->type;
|
||||
$restrictions = $auth->getRestrictions("director/$type/applyrule/filter-by-name");
|
||||
if (empty($restrictions)) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
$filter = Filter::matchAny();
|
||||
foreach ($restrictions as $restriction) {
|
||||
$filter->addFilter(Filter::where('o.object_name', $restriction));
|
||||
}
|
||||
|
||||
return FilterRenderer::applyToQuery($filter, $query);
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
$type = $this->type;
|
||||
@ -129,6 +149,6 @@ class ApplyRulesTable extends ZfQueryBasedTable
|
||||
$query->where('service_set_id IS NULL');
|
||||
}
|
||||
|
||||
return $query;
|
||||
return $this->applyRestrictions($query);
|
||||
}
|
||||
}
|
||||
|
@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Module\Director\IcingaConfig\AssignRenderer;
|
||||
use ipl\Html\Icon;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Html\Table;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
use ipl\Web\Url;
|
||||
|
||||
class ServiceApplyRulesTable extends ZfQueryBasedTable
|
||||
{
|
||||
protected $searchColumns = [
|
||||
's.object_name',
|
||||
's.assign_filter',
|
||||
];
|
||||
|
||||
public function getColumnsToBeRendered()
|
||||
{
|
||||
return ['Service Name', 'assign where', 'Actions'];
|
||||
}
|
||||
|
||||
public function renderRow($row)
|
||||
{
|
||||
$url = Url::fromPath('director/service/edit', [
|
||||
'id' => $row->id,
|
||||
]);
|
||||
|
||||
return static::tr([
|
||||
Table::td(Link::create($row->service, $url)),
|
||||
Table::td($this->renderApplyFilter($row->assign_filter)),
|
||||
Table::td($this->createActionLinks($row))->setSeparator(' ')
|
||||
]);
|
||||
}
|
||||
|
||||
protected function renderApplyFilter($assignFilter)
|
||||
{
|
||||
try {
|
||||
$string = AssignRenderer::forFilter(
|
||||
Filter::fromQueryString($assignFilter)
|
||||
)->renderAssign();
|
||||
// Do not prefix it
|
||||
$string = preg_replace('/^assign where /', '', $string);
|
||||
} catch (IcingaException $e) {
|
||||
// ignore errors in filter rendering
|
||||
$string = 'Error in Filter rendering: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public function createActionLinks($row)
|
||||
{
|
||||
$links = [];
|
||||
$links[] = Link::create(
|
||||
Icon::create('sitemap'),
|
||||
'director/servicetemplate/applytargets',
|
||||
['id' => $row->id],
|
||||
['title' => $this->translate('Show affected Hosts')]
|
||||
);
|
||||
|
||||
$links[] = Link::create(
|
||||
Icon::create('edit'),
|
||||
'director/service/edit',
|
||||
['id' => $row->id],
|
||||
['title' => $this->translate('Modify this Apply Rule')]
|
||||
);
|
||||
|
||||
$links[] = Link::create(
|
||||
Icon::create('doc-text'),
|
||||
'director/service/render',
|
||||
['id' => $row->id],
|
||||
['title' => $this->translate('Apply Rule rendering preview')]
|
||||
);
|
||||
|
||||
$links[] = Link::create(
|
||||
Icon::create('history'),
|
||||
'director/service/history',
|
||||
['id' => $row->id],
|
||||
['title' => $this->translate('Apply rule history')]
|
||||
);
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
public function prepareQuery()
|
||||
{
|
||||
$columns = [
|
||||
'id' => 's.id',
|
||||
'service' => 's.object_name',
|
||||
'assign_filter' => 's.assign_filter',
|
||||
];
|
||||
$query = $this->db()->select()->from(
|
||||
['s' => 'icinga_service'],
|
||||
$columns
|
||||
)->where(
|
||||
"object_type = 'apply'"
|
||||
)->where('service_set_id IS NULL')->order('s.object_name');
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
@ -2,14 +2,18 @@
|
||||
|
||||
namespace Icinga\Module\Director\Web\Table;
|
||||
|
||||
use Icinga\Authentication\Auth;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\Db\IcingaObjectFilterHelper;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use ipl\Db\Zf1\FilterRenderer;
|
||||
use ipl\Html\Html;
|
||||
use ipl\Html\Icon;
|
||||
use ipl\Html\Link;
|
||||
use ipl\Web\Table\ZfQueryBasedTable;
|
||||
use ipl\Web\Url;
|
||||
use Zend_Db_Select as ZfSelect;
|
||||
|
||||
class TemplatesTable extends ZfQueryBasedTable
|
||||
{
|
||||
@ -72,6 +76,23 @@ class TemplatesTable extends ZfQueryBasedTable
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function applyRestrictions(ZfSelect $query)
|
||||
{
|
||||
$auth = Auth::getInstance();
|
||||
$type = $this->type;
|
||||
$restrictions = $auth->getRestrictions("director/$type/template/filter-by-name");
|
||||
if (empty($restrictions)) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
$filter = Filter::matchAny();
|
||||
foreach ($restrictions as $restriction) {
|
||||
$filter->addFilter(Filter::where('o.object_name', $restriction));
|
||||
}
|
||||
|
||||
return FilterRenderer::applyToQuery($filter, $query);
|
||||
}
|
||||
|
||||
protected function prepareQuery()
|
||||
{
|
||||
$type = $this->getType();
|
||||
@ -90,6 +111,6 @@ class TemplatesTable extends ZfQueryBasedTable
|
||||
"o.object_type = 'template'"
|
||||
)->order('o.object_name');
|
||||
|
||||
return $query;
|
||||
return $this->applyRestrictions($query);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user