ActionController: cleanup

This commit is contained in:
Thomas Gelf 2018-06-07 23:37:28 +02:00
parent 35c2c034fd
commit 885f76715a
3 changed files with 20 additions and 52 deletions

View File

@ -5,6 +5,7 @@ namespace Icinga\Module\Director\Controllers;
use Exception; use Exception;
use Icinga\Module\Director\Db\Migrations; use Icinga\Module\Director\Db\Migrations;
use Icinga\Module\Director\Forms\ApplyMigrationsForm; use Icinga\Module\Director\Forms\ApplyMigrationsForm;
use Icinga\Module\Director\Forms\KickstartForm;
class IndexController extends DashboardController class IndexController extends DashboardController
{ {
@ -44,9 +45,7 @@ class IndexController extends DashboardController
$this->addSingleTab($this->translate('Kickstart')); $this->addSingleTab($this->translate('Kickstart'));
} }
$this->content()->prepend( $this->content()->prepend(KickstartForm::load()->handleRequest());
$this->loadForm('kickstart')->handleRequest()
);
} }
protected function hasDeploymentEndpoint() protected function hasDeploymentEndpoint()

View File

@ -211,23 +211,6 @@ class ServiceController extends ObjectController
$this->content()->add($table); $this->content()->add($table);
} }
public function loadForm($name)
{
$form = parent::loadForm($name);
if ($name === 'icingaService') {
if ($this->host) {
$form->setHost($this->host);
} elseif ($this->set) {
$form->setServiceSet($this->set)->setSuccessUrl(
'director/serviceset/services',
array('name' => $this->set->object_name)
);
}
}
return $form;
}
protected function loadObject() protected function loadObject()
{ {
if ($this->object === null) { if ($this->object === null) {

View File

@ -4,18 +4,15 @@ namespace Icinga\Module\Director\Web\Controller;
use Icinga\Application\Benchmark; use Icinga\Application\Benchmark;
use Icinga\Data\Paginatable; use Icinga\Data\Paginatable;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Director\Monitoring; use Icinga\Module\Director\Monitoring;
use Icinga\Module\Director\Web\Controller\Extension\CoreApi; use Icinga\Module\Director\Web\Controller\Extension\CoreApi;
use Icinga\Module\Director\Web\Controller\Extension\DirectorDb; use Icinga\Module\Director\Web\Controller\Extension\DirectorDb;
use Icinga\Module\Director\Web\Controller\Extension\RestApi; use Icinga\Module\Director\Web\Controller\Extension\RestApi;
use Icinga\Module\Director\Web\Form\FormLoader;
use Icinga\Module\Director\Web\Form\QuickForm;
use Icinga\Module\Director\Web\Table\QuickTable;
use Icinga\Module\Director\Web\Table\TableLoader;
use Icinga\Security\SecurityException; use Icinga\Security\SecurityException;
use Icinga\Web\Controller; use Icinga\Web\Controller;
use Icinga\Web\UrlParams; use Icinga\Web\UrlParams;
use Icinga\Web\Widget; use InvalidArgumentException;
use dipl\Compat\Translator; use dipl\Compat\Translator;
use dipl\Html\Link; use dipl\Html\Link;
use dipl\Translation\TranslationHelper; use dipl\Translation\TranslationHelper;
@ -38,6 +35,10 @@ abstract class ActionController extends Controller implements ControlsAndContent
/** @var Monitoring */ /** @var Monitoring */
private $monitoring; private $monitoring;
/**
* @throws SecurityException
* @throws \Icinga\Exception\NotFoundError
*/
public function init() public function init()
{ {
$this->initializeTranslator(); $this->initializeTranslator();
@ -57,11 +58,17 @@ abstract class ActionController extends Controller implements ControlsAndContent
return $this->Auth(); return $this->Auth();
} }
/**
* @throws SecurityException
*/
protected function checkDirectorPermissions() protected function checkDirectorPermissions()
{ {
$this->assertPermission('director/admin'); $this->assertPermission('director/admin');
} }
/**
* @throws SecurityException
*/
protected function checkSpecialDirectorPermissions() protected function checkSpecialDirectorPermissions()
{ {
if ($this->params->get('format') === 'sql') { if ($this->params->get('format') === 'sql') {
@ -100,7 +107,11 @@ abstract class ActionController extends Controller implements ControlsAndContent
public function setAutorefreshInterval($interval) public function setAutorefreshInterval($interval)
{ {
if (! $this->getRequest()->isApiRequest()) { if (! $this->getRequest()->isApiRequest()) {
parent::setAutorefreshInterval($interval); try {
parent::setAutorefreshInterval($interval);
} catch (ProgrammingError $e) {
throw new InvalidArgumentException($e->getMessage());
}
} }
return $this; return $this;
@ -144,35 +155,10 @@ abstract class ActionController extends Controller implements ControlsAndContent
return $this; return $this;
} }
/**
* @param string $name
*
* @return QuickForm
*/
public function loadForm($name)
{
$form = FormLoader::load($name, $this->Module());
if ($this->getRequest()->isApiRequest()) {
// TODO: Ask form for API support?
$form->setApiRequest();
}
return $form;
}
/**
* @param string $name
*
* @return QuickTable
*/
public function loadTable($name)
{
return TableLoader::load($name, $this->Module());
}
/** /**
* @param string $permission * @param string $permission
* @return $this * @return $this
* @throws SecurityException
*/ */
public function assertPermission($permission) public function assertPermission($permission)
{ {