ActivityLogTable: fix range/author filtering

This commit is contained in:
Thomas Gelf 2017-07-26 09:25:58 +02:00
parent f89fab2a27
commit cc01446269
2 changed files with 40 additions and 25 deletions

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Controllers; namespace Icinga\Module\Director\Controllers;
use Icinga\Data\Filter\Filter;
use Icinga\Module\Director\ConfigDiff; use Icinga\Module\Director\ConfigDiff;
use Icinga\Module\Director\Forms\DeployConfigForm; use Icinga\Module\Director\Forms\DeployConfigForm;
use Icinga\Module\Director\Forms\SettingsForm; use Icinga\Module\Director\Forms\SettingsForm;
@ -127,14 +128,28 @@ class ConfigController extends ActionController
$lastDeployedId = $this->db()->getLastDeploymentActivityLogId(); $lastDeployedId = $this->db()->getLastDeploymentActivityLogId();
$table = new ActivityLogTable($this->db()); $table = new ActivityLogTable($this->db());
$table->setLastDeployedId($lastDeployedId); $table->setLastDeployedId($lastDeployedId);
$this->actions()->add(Link::create( $filter = Filter::fromQueryString(
$this->translate('My changes'), $this->url()->without(['page', 'limit', 'q'])->getQueryString()
$this->url() );
->with('author', $this->Auth()->getUser()->getUsername()) $table->applyFilter($filter);
->without('page'), if ($this->url()->hasParam('author')) {
null, $this->actions()->add(Link::create(
array('class' => 'icon-user', 'data-base-target' => '_self') $this->translate('All changes'),
)); $this->url()
->without(['author', 'page']),
null,
['class' => 'icon-users', 'data-base-target' => '_self']
));
} else {
$this->actions()->add(Link::create(
$this->translate('My changes'),
$this->url()
->with('author', $this->Auth()->getUser()->getUsername())
->without('page'),
null,
['class' => 'icon-user', 'data-base-target' => '_self']
));
}
if ($this->hasPermission('director/deploy')) { if ($this->hasPermission('director/deploy')) {
$this->actions()->add(DeployConfigForm::load() $this->actions()->add(DeployConfigForm::load()
->setDb($this->db()) ->setDb($this->db())

View File

@ -26,10 +26,10 @@ class ActivityLogTable extends ZfQueryBasedTable
protected $currentBody; protected $currentBody;
protected $searchColumns = array( protected $searchColumns = array(
'l.author', 'author',
'l.object_name', 'object_name',
'l.object_type', 'object_type',
'l.action_name', 'action_name',
); );
public function assemble() public function assemble()
@ -61,13 +61,14 @@ class ActivityLogTable extends ZfQueryBasedTable
protected function makeLink($row) protected function makeLink($row)
{ {
$type = $row->object_type;
$name = $row->object_name;
if (substr($type, 0, 7) === 'icinga_') {
$type = substr($type, 7);
}
if (Util::hasPermission('director/showconfig')) { if (Util::hasPermission('director/showconfig')) {
// Later on replacing, service_set -> serviceset // Later on replacing, service_set -> serviceset
$type = $row->object_type;
$name = $row->object_name;
if (substr($type, 0, 7) === 'icinga_') {
$type = substr($type, 7);
}
// multi column key :( // multi column key :(
if ($type === 'service' || $this->hasObjectFilter) { if ($type === 'service' || $this->hasObjectFilter) {
@ -93,7 +94,13 @@ class ActivityLogTable extends ZfQueryBasedTable
$object $object
]; ];
} else { } else {
return $row->log_message; return sprintf(
'[%s] %s %s "%s"',
$row->author,
$row->action,
$type,
$name
);
} }
} }
@ -102,10 +109,6 @@ class ActivityLogTable extends ZfQueryBasedTable
$this->hasObjectFilter = true; $this->hasObjectFilter = true;
$this->filters[] = ['l.object_type = ?', $type]; $this->filters[] = ['l.object_type = ?', $type];
$this->filters[] = ['l.object_name = ?', $name]; $this->filters[] = ['l.object_name = ?', $name];
$this->extraParams = [
'type' => $type,
'name' => $name,
];
return $this; return $this;
} }
@ -113,9 +116,6 @@ class ActivityLogTable extends ZfQueryBasedTable
public function getColumns() public function getColumns()
{ {
return [ return [
'log_message' => "'[' || l.author || '] ' || l.action_name || ' '"
. " || REPLACE(l.object_type, 'icinga_', '')"
. " || ' \"' || l.object_name || '\"'",
'author' => 'l.author', 'author' => 'l.author',
'action' => 'l.action_name', 'action' => 'l.action_name',
'object_name' => 'l.object_name', 'object_name' => 'l.object_name',