mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 08:14:04 +02:00
ActionController: start to offer JSON actions
This commit is contained in:
parent
fa65e9850b
commit
21d51decb2
@ -4,6 +4,8 @@ namespace Icinga\Module\Director\Web\Controller;
|
|||||||
|
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Data\Paginatable;
|
use Icinga\Data\Paginatable;
|
||||||
|
use Icinga\Exception\AuthenticationException;
|
||||||
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Module\Director\Core\RestApiClient;
|
use Icinga\Module\Director\Core\RestApiClient;
|
||||||
use Icinga\Module\Director\Core\CoreApi;
|
use Icinga\Module\Director\Core\CoreApi;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
@ -16,6 +18,26 @@ abstract class ActionController extends Controller
|
|||||||
{
|
{
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
|
protected $isApified = false;
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
if ($this->getRequest()->isApiRequest()) {
|
||||||
|
if (! $this->hasPermission('director/api')) {
|
||||||
|
throw new AuthenticationException('You are not allowed to access this API');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->isApified()) {
|
||||||
|
throw new NotFoundError('No such API endpoint found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isApified()
|
||||||
|
{
|
||||||
|
return $this->isApified;
|
||||||
|
}
|
||||||
|
|
||||||
protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
|
protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null)
|
||||||
{
|
{
|
||||||
$limit = $this->params->get('limit', $limit);
|
$limit = $this->params->get('limit', $limit);
|
||||||
@ -28,7 +50,13 @@ abstract class ActionController extends Controller
|
|||||||
|
|
||||||
public function loadForm($name)
|
public function loadForm($name)
|
||||||
{
|
{
|
||||||
return FormLoader::load($name, $this->Module());
|
$form = FormLoader::load($name, $this->Module());
|
||||||
|
if ($this->getRequest()->isApiRequest()) {
|
||||||
|
// TODO: Ask form for API support?
|
||||||
|
$form->setApiRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadTable($name)
|
public function loadTable($name)
|
||||||
@ -36,6 +64,18 @@ abstract class ActionController extends Controller
|
|||||||
return TableLoader::load($name, $this->Module());
|
return TableLoader::load($name, $this->Module());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function sendJson($object)
|
||||||
|
{
|
||||||
|
$this->getResponse()->setHeader('Content-Type', 'application/json', true);
|
||||||
|
$this->_helper->layout()->disableLayout();
|
||||||
|
$this->_helper->viewRenderer->setNoRender(true);
|
||||||
|
if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
|
||||||
|
echo json_encode($object, JSON_PRETTY_PRINT) . "\n";
|
||||||
|
} else {
|
||||||
|
echo json_encode($object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function setConfigTabs()
|
protected function setConfigTabs()
|
||||||
{
|
{
|
||||||
$this->view->tabs = Widget::create('tabs')->add('deploymentlog', array(
|
$this->view->tabs = Widget::create('tabs')->add('deploymentlog', array(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user