Add ConfigFormEventsHook to UserForm.php

Add ConfigFormEventsHook to UserGroupForm.php

Add check in getValues for UserForm.php
This commit is contained in:
Valentina Da Rold 2020-04-22 16:36:34 +02:00 committed by Johannes Meyer
parent 9a29d8f3d4
commit 0520ed348d
2 changed files with 66 additions and 1 deletions

View File

@ -3,8 +3,10 @@
namespace Icinga\Forms\Config\User;
use Icinga\Application\Hook\ConfigFormEventsHook;
use Icinga\Data\Filter\Filter;
use Icinga\Forms\RepositoryForm;
use Icinga\Web\Notification;
class UserForm extends RepositoryForm
{
@ -97,7 +99,10 @@ class UserForm extends RepositoryForm
public function getValues($suppressArrayNotation = false)
{
$values = parent::getValues($suppressArrayNotation);
if (! $values['password']) {
// before checking if password values is empty
// we have to check that the password field is set
// otherwise an error is thrown
if (isset($values['password']) && ! $values['password']) {
unset($values['password']);
}
@ -173,4 +178,33 @@ class UserForm extends RepositoryForm
return sprintf($this->translate('Failed to remove user "%s"'), $this->getIdentifier());
}
}
public function isValid($formData)
{
$valid = parent::isValid($formData);
if ($valid && ConfigFormEventsHook::runIsValid($this) === false) {
foreach (ConfigFormEventsHook::getLastErrors() as $msg) {
$this->error($msg);
}
$valid = false;
}
return $valid;
}
public function onSuccess()
{
if (parent::onSuccess() === false) {
return false;
}
if (ConfigFormEventsHook::runOnSuccess($this) === false) {
Notification::error($this->translate(
'Configuration successfully stored. Though, one or more module hooks failed to run.'
. ' See logs for details'
));
}
}
}

View File

@ -3,8 +3,10 @@
namespace Icinga\Forms\Config\UserGroup;
use Icinga\Application\Hook\ConfigFormEventsHook;
use Icinga\Data\Filter\Filter;
use Icinga\Forms\RepositoryForm;
use Icinga\Web\Notification;
class UserGroupForm extends RepositoryForm
{
@ -124,4 +126,33 @@ class UserGroupForm extends RepositoryForm
return sprintf($this->translate('Failed to remove group "%s"'), $this->getIdentifier());
}
}
public function isValid($formData)
{
$valid = parent::isValid($formData);
if ($valid && ConfigFormEventsHook::runIsValid($this) === false) {
foreach (ConfigFormEventsHook::getLastErrors() as $msg) {
$this->error($msg);
}
$valid = false;
}
return $valid;
}
public function onSuccess()
{
if (parent::onSuccess() === false) {
return false;
}
if (ConfigFormEventsHook::runOnSuccess($this) === false) {
Notification::error($this->translate(
'Configuration successfully stored. Though, one or more module hooks failed to run.'
. ' See logs for details'
));
}
}
}