Settings: use ipl, clean up, fix array handling

This commit is contained in:
Thomas Gelf 2017-07-13 15:23:28 +02:00
parent fbfa2c935c
commit fe249a18be
5 changed files with 57 additions and 21 deletions

View File

@ -3,6 +3,7 @@
namespace Icinga\Module\Director\Controllers; namespace Icinga\Module\Director\Controllers;
use Icinga\Module\Director\ConfigDiff; use Icinga\Module\Director\ConfigDiff;
use Icinga\Module\Director\Forms\SettingsForm;
use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\IcingaConfig\IcingaConfig;
use Icinga\Module\Director\Settings; use Icinga\Module\Director\Settings;
use Icinga\Module\Director\Util; use Icinga\Module\Director\Util;
@ -144,14 +145,13 @@ class ConfigController extends ActionController
{ {
$this->assertPermission('director/admin'); $this->assertPermission('director/admin');
$this->overviewTabs()->activate('settings'); $this->addSingleTab($this->translate('Settings'))
$this->view->title = $this->translate('Settings'); ->addTitle($this->translate('Global Director Settings'));
$this->view->form = $this $this->content()->add(
->loadForm('Settings') SettingsForm::load()
->setSettings(new Settings($this->db())) ->setSettings(new Settings($this->db()))
->handleRequest(); ->handleRequest()
);
$this->setViewScript('object/form');
} }
// Show all files for a given config // Show all files for a given config
@ -346,15 +346,7 @@ class ConfigController extends ActionController
) )
); );
} }
if ($this->hasPermission('director/admin')) {
$tabs->add(
'settings',
array(
'label' => $this->translate('Settings'),
'url' => 'director/config/settings'
)
);
}
return $this->view->tabs; return $this->view->tabs;
} }

View File

@ -4,9 +4,9 @@ namespace Icinga\Module\Director\Forms;
use Exception; use Exception;
use Icinga\Module\Director\Settings; use Icinga\Module\Director\Settings;
use Icinga\Module\Director\Web\Form\QuickForm; use Icinga\Module\Director\Web\Form\DirectorForm;
class SettingsForm extends QuickForm class SettingsForm extends DirectorForm
{ {
/** @var Settings */ /** @var Settings */
protected $settings; protected $settings;

View File

@ -0,0 +1,30 @@
<?php
namespace Icinga\Module\Director\Dashboard\Dashlet;
class SettingsDashlet extends Dashlet
{
protected $icon = 'edit';
public function getTitle()
{
return $this->translate('Director Settings');
}
public function getSummary()
{
return $this->translate(
'Tweak some global Director settings'
);
}
public function getUrl()
{
return 'director/config/settings';
}
public function listRequiredPermissions()
{
return array('director/admin');
}
}

View File

@ -10,6 +10,7 @@ class InfrastructureDashboard extends Dashboard
'ApiUserObject', 'ApiUserObject',
'EndpointObject', 'EndpointObject',
'ZoneObject', 'ZoneObject',
'Settings',
); );
public function getTitle() public function getTitle()

View File

@ -10,7 +10,7 @@ class Settings
protected $cache; protected $cache;
protected $defaults = array( protected $defaults = [
'default_global_zone' => 'director-global', 'default_global_zone' => 'director-global',
'magic_apply_for' => '_director_apply_for', 'magic_apply_for' => '_director_apply_for',
'config_format' => 'v2', 'config_format' => 'v2',
@ -22,10 +22,16 @@ class Settings
'deployment_path_v1' => null, 'deployment_path_v1' => null,
'activation_script_v1' => null, 'activation_script_v1' => null,
'self-service/agent_name' => 'fqdn', 'self-service/agent_name' => 'fqdn',
'self-service/transform_hostname' => '0' 'self-service/transform_hostname' => '0',
'self-service/global_zones' => ['director_global'],
// 'experimental_features' => null, // 'allow' // 'experimental_features' => null, // 'allow'
// 'master_zone' => null, // 'master_zone' => null,
); ];
protected $jsonEncode = [
'self-service/global_zones',
'self-service/installer_hashes',
];
public function __construct(Db $connection) public function __construct(Db $connection)
{ {
@ -47,6 +53,9 @@ class Settings
if (null === ($value = $this->getSetting($key))) { if (null === ($value = $this->getSetting($key))) {
return $default; return $default;
} else { } else {
if (in_array($key, $this->jsonEncode)) {
$value = json_decode($value);
}
return $value; return $value;
} }
} }
@ -85,6 +94,10 @@ class Settings
return $this; return $this;
} }
if (in_array($name, $this->jsonEncode)) {
$value = json_encode(array_values($value));
}
if ($this->getSetting($name) === $value) { if ($this->getSetting($name) === $value) {
return $this; return $this;
} }