mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 17:24:18 +02:00
parent
c12f5876ad
commit
5c8a12da38
@ -79,17 +79,23 @@ class SelfServiceController extends ActionController
|
|||||||
} else {
|
} else {
|
||||||
$error = implode('; ', $form->getErrorMessages());
|
$error = implode('; ', $form->getErrorMessages());
|
||||||
if ($error === '') {
|
if ($error === '') {
|
||||||
foreach ($form->getErrors() as $elName => $errors) {
|
if ($form->isMissingRequiredFields()) {
|
||||||
if (in_array('isEmpty', $errors)) {
|
$fields = $form->listMissingRequiredFields();
|
||||||
|
if (count($fields) === 1) {
|
||||||
$this->sendPowerShellError(
|
$this->sendPowerShellError(
|
||||||
sprintf("%s is required", $elName),
|
sprintf("%s is required", $fields[0]),
|
||||||
400
|
400
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$this->sendPowerShellError(
|
||||||
|
sprintf("Missing parameters: %s", implode(', ', $fields)),
|
||||||
|
400
|
||||||
|
);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
$this->sendPowerShellError('An unknown error ocurred', 500);
|
$this->sendPowerShellError('An unknown error ocurred', 500);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$this->sendPowerShellError($error, 400);
|
$this->sendPowerShellError($error, 400);
|
||||||
}
|
}
|
||||||
@ -171,13 +177,12 @@ class SelfServiceController extends ActionController
|
|||||||
*/
|
*/
|
||||||
protected function sendPowerShellError($error, $code)
|
protected function sendPowerShellError($error, $code)
|
||||||
{
|
{
|
||||||
$this->getResponse()->setHttpResponseCode($code);
|
|
||||||
if ($this->getRequest()->getHeader('X-Director-Accept') === 'text/plain') {
|
if ($this->getRequest()->getHeader('X-Director-Accept') === 'text/plain') {
|
||||||
|
$this->getResponse()->setHttpResponseCode($code);
|
||||||
echo "ERROR: $error";
|
echo "ERROR: $error";
|
||||||
} else {
|
} else {
|
||||||
$this->sendJsonError($this->getResponse(), $error);
|
$this->sendJsonError($this->getResponse(), $error, $code);
|
||||||
}
|
}
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,6 +83,23 @@ class IcingaHostSelfServiceForm extends DirectorForm
|
|||||||
return $this->template;
|
return $this->template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function listMissingRequiredFields()
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
foreach ($this->getElements() as $element) {
|
||||||
|
if (in_array('isEmpty', $element->getErrors())) {
|
||||||
|
$result[] = $element->getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isMissingRequiredFields()
|
||||||
|
{
|
||||||
|
return count($this->listMissingRequiredFields()) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public function onSuccess()
|
public function onSuccess()
|
||||||
{
|
{
|
||||||
$db = $this->getDb();
|
$db = $this->getDb();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user