Make configuration of custom user backends possible
refs Icinga/icingaweb2#2840
This commit is contained in:
parent
9270633b23
commit
1e7f700102
|
@ -37,6 +37,13 @@ class UserBackendConfigForm extends ConfigForm
|
||||||
*/
|
*/
|
||||||
protected $backendToLoad;
|
protected $backendToLoad;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The loaded custom backends list
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $customBackends;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize this form
|
* Initialize this form
|
||||||
*/
|
*/
|
||||||
|
@ -45,6 +52,7 @@ class UserBackendConfigForm extends ConfigForm
|
||||||
$this->setName('form_config_authbackend');
|
$this->setName('form_config_authbackend');
|
||||||
$this->setSubmitLabel($this->translate('Save Changes'));
|
$this->setSubmitLabel($this->translate('Save Changes'));
|
||||||
$this->setValidatePartial(true);
|
$this->setValidatePartial(true);
|
||||||
|
$this->customBackends = UserBackend::getCustomBackendConfigForms();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,6 +122,10 @@ class UserBackendConfigForm extends ConfigForm
|
||||||
$form = new ExternalBackendForm();
|
$form = new ExternalBackendForm();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
if (isset($this->customBackends[$type])) {
|
||||||
|
return new $this->customBackends[$type]();
|
||||||
|
}
|
||||||
|
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
sprintf($this->translate('Invalid backend type "%s" provided'), $type)
|
sprintf($this->translate('Invalid backend type "%s" provided'), $type)
|
||||||
);
|
);
|
||||||
|
@ -274,6 +286,9 @@ class UserBackendConfigForm extends ConfigForm
|
||||||
$backendTypes['external'] = $this->translate('External');
|
$backendTypes['external'] = $this->translate('External');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$customBackendTypes = array_keys($this->customBackends);
|
||||||
|
$backendTypes += array_combine($customBackendTypes, $customBackendTypes);
|
||||||
|
|
||||||
if ($backendType === null) {
|
if ($backendType === null) {
|
||||||
$backendType = key($backendTypes);
|
$backendType = key($backendTypes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,6 +113,22 @@ class UserBackend implements ConfigAwareFactory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get config forms of all custom user backends
|
||||||
|
*/
|
||||||
|
public static function getCustomBackendConfigForms()
|
||||||
|
{
|
||||||
|
$customBackendConfigForms = [];
|
||||||
|
static::registerCustomUserBackends();
|
||||||
|
foreach (self::$customBackends as $customBackendType => $customBackendClass) {
|
||||||
|
if (method_exists($customBackendClass, 'getConfigurationFormClass')) {
|
||||||
|
$customBackendConfigForms[$customBackendType] = $customBackendClass::getConfigurationFormClass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $customBackendConfigForms;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the class for the given custom user backend
|
* Return the class for the given custom user backend
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,4 +26,14 @@ interface UserBackendInterface extends Authenticatable
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getName();
|
public function getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return this backend's configuration form class path
|
||||||
|
*
|
||||||
|
* This is not part of the interface to not break existing implementations.
|
||||||
|
* If you need a custom backend form, implement this method.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
//public static function getConfigurationFormClass();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use Icinga\Test\BaseTestCase;
|
||||||
use Icinga\Application\Config;
|
use Icinga\Application\Config;
|
||||||
use Icinga\Forms\Config\UserBackendConfigForm;
|
use Icinga\Forms\Config\UserBackendConfigForm;
|
||||||
use Icinga\Forms\Config\UserBackendReorderForm;
|
use Icinga\Forms\Config\UserBackendReorderForm;
|
||||||
|
use Icinga\Application\Icinga;
|
||||||
|
|
||||||
class UserBackendConfigFormWithoutSave extends UserBackendConfigForm
|
class UserBackendConfigFormWithoutSave extends UserBackendConfigForm
|
||||||
{
|
{
|
||||||
|
@ -41,6 +42,7 @@ class AuthenticationBackendReorderFormTest extends BaseTestCase
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Icinga::app()->shouldReceive('getModuleManager->getLoadedModules')->andReturn([]);
|
||||||
$this->getRequestMock()->shouldReceive('getMethod')->andReturn('POST')
|
$this->getRequestMock()->shouldReceive('getMethod')->andReturn('POST')
|
||||||
->shouldReceive('isPost')->andReturn(true)
|
->shouldReceive('isPost')->andReturn(true)
|
||||||
->shouldReceive('getPost')->andReturn(array('backend_newpos' => 'test3|1'));
|
->shouldReceive('getPost')->andReturn(array('backend_newpos' => 'test3|1'));
|
||||||
|
|
Loading…
Reference in New Issue