Objects: ship templates via REST API

fixes #1185
This commit is contained in:
Thomas Gelf 2017-09-18 10:23:36 +02:00
parent 8f1f3ec699
commit e950bb3395
2 changed files with 23 additions and 3 deletions

View File

@ -50,16 +50,21 @@ abstract class ObjectsController extends ActionController
protected function apiRequestHandler() protected function apiRequestHandler()
{ {
$request = $this->getRequest();
$table = $this->getTable(); $table = $this->getTable();
if ($this->getRequest()->getControllerName() === 'services' if ($request->getControllerName() === 'services'
&& $host = $this->params->get('host') && $host = $this->params->get('host')
) { ) {
$host = IcingaHost::load($host, $this->db()); $host = IcingaHost::load($host, $this->db());
$table->getQuery()->where('host_id = ?', $host->get('id')); $table->getQuery()->where('host_id = ?', $host->get('id'));
} }
if ($request->getActionName() === 'templates') {
$table->filterObjectType('template');
}
return (new IcingaObjectsHandler( return (new IcingaObjectsHandler(
$this->getRequest(), $request,
$this->getResponse(), $this->getResponse(),
$this->db() $this->db()
))->setTable($table); ))->setTable($table);
@ -129,6 +134,10 @@ abstract class ObjectsController extends ActionController
*/ */
public function templatesAction() public function templatesAction()
{ {
if ($this->getRequest()->isApiRequest()) {
$this->apiRequestHandler()->dispatch();
return;
}
$type = $this->getType(); $type = $this->getType();
$shortType = IcingaObject::createByType($type)->getShortTableName(); $shortType = IcingaObject::createByType($type)->getShortTableName();

View File

@ -28,6 +28,8 @@ class ObjectsTable extends ZfQueryBasedTable
protected $showColumns = ['object_name' => 'Name']; protected $showColumns = ['object_name' => 'Name'];
protected $filterObjectType = 'object';
protected $type; protected $type;
private $auth; private $auth;
@ -66,6 +68,12 @@ class ObjectsTable extends ZfQueryBasedTable
return $this; return $this;
} }
public function filterObjectType($type)
{
$this->filterObjectType = $type;
return $this;
}
public function addObjectRestriction(ObjectRestriction $restriction) public function addObjectRestriction(ObjectRestriction $restriction)
{ {
$this->objectRestrictions[$restriction->getName()] = $restriction; $this->objectRestrictions[$restriction->getName()] = $restriction;
@ -143,7 +151,10 @@ class ObjectsTable extends ZfQueryBasedTable
protected function applyObjectTypeFilter(ZfSelect $query) protected function applyObjectTypeFilter(ZfSelect $query)
{ {
return $query->where("o.object_type = 'object'"); return $query->where(
'o.object_type = ?',
$this->filterObjectType
);
} }
protected function applyRestrictions(ZfSelect $query) protected function applyRestrictions(ZfSelect $query)