Example showing restriction usage in the monitoring module

fixes #4108
This commit is contained in:
Thomas Gelf 2014-01-22 13:34:39 +00:00
parent 0f565aae6a
commit 6ef87f4644
4 changed files with 30 additions and 5 deletions

View File

@ -367,11 +367,11 @@ class User
{
try {
// TODO: Config::app should gracefully handle missing files
$config = Config::app('permissions');
$config = Config::app('restrictions');
} catch (Exception $e) {
return $this;
}
$config = Config::app('restrictions');
foreach ($config as $section) {
if ($section->get('user') !== $this->username) {
continue;

View File

@ -121,6 +121,8 @@ class Monitoring_ListController extends MonitoringController
)
);
$query = $dataview->getQuery();
$this->applyRestrictions($query);
$this->setupFilterControl($dataview, 'host');
$this->setupSortControl(array(
@ -142,7 +144,9 @@ class Monitoring_ListController extends MonitoringController
public function servicesAction()
{
$this->compactView = 'services-compact';
$this->view->services = $this->fetchServices();
$query = $this->fetchServices();
$this->applyRestrictions($query);
$this->view->services = $query->paginate();
$this->setupFilterControl(ServiceStatus::fromRequest($this->getRequest()), 'service');
$this->setupSortControl(array(
@ -369,6 +373,27 @@ class Monitoring_ListController extends MonitoringController
);
}
/**
* Apply current users monitoring/filter restrictions to the given query
*
* @param $query Filterable Query that should be filtered
* @return Filterable
*/
protected function applyRestrictions(Filterable $query)
{
foreach ($this->getRestrictions('monitoring/filter') as $restriction) {
parse_str($restriction, $filter);
foreach ($filter as $k => $v) {
// if ($query->isValidFilterTarget($k)) {
// TODO: This is NOT enough. We need to fix filters and get
// applyAuthFilters back.
$query->where($k, $v);
// }
}
}
return $query;
}
/**
* Create a sort control box at the 'sortControl' view parameter
*

View File

@ -96,7 +96,7 @@ class Monitoring_ShowController extends MonitoringController
{
$params = $this->_request->getParams();
unset($params['service']);
$this->view->services = $this->fetchServices($params);
$this->view->services = $this->fetchServices($params)->paginate();
}

View File

@ -102,7 +102,7 @@ class Controller extends ActionController
)->getQuery();
}
$this->handleFormatRequest($query);
return $query->paginate();
return $query;
}
protected function handleFormatRequest($query)