N°1150 Fix regression : cannot add caselog in the user portal

Was caused by field value check added in MultipleChoicesField and SelectObjectField in b71cd218

With this commit the checks are now only done if we have a ContextTag::TAG_REST
This commit is contained in:
Pierre Goiffon
2023-06-13 11:42:40 +02:00
parent b3ef634d21
commit d0cad4d829
2 changed files with 11 additions and 5 deletions

View File

@@ -20,6 +20,7 @@
namespace Combodo\iTop\Form\Field;
use Closure;
use ContextTag;
use utils;
/**
@@ -211,14 +212,13 @@ abstract class MultipleChoicesField extends Field
return $this;
}
/**
* @inheritDoc
*/
public function Validate() {
$this->SetValid(true);
$this->EmptyErrorMessages();
if ($this->GetReadOnly() === false) {
if ((ContextTag::Check(ContextTag::TAG_REST)) && ($this->GetReadOnly() === false)) {
// Only doing the check when coming from the REST API, as the user portal might send invalid values (see VerifyCurrentValue() method below)
// Also do not check read only fields, are they are send with a null value when submitting request template from the console
if (count($this->currentValue) > 0) {
foreach ($this->currentValue as $sCode => $value) {
if (utils::IsNullOrEmptyString($value)) {

View File

@@ -23,6 +23,7 @@ namespace Combodo\iTop\Form\Field;
use BinaryExpression;
use Closure;
use Combodo\iTop\Form\Validator\NotEmptyExtKeyValidator;
use ContextTag;
use DBObjectSet;
use DBSearch;
use FieldExpression;
@@ -250,7 +251,9 @@ class SelectObjectField extends Field
}
public function Validate() {
if ($this->GetReadOnly() === false) {
if ((ContextTag::Check(ContextTag::TAG_REST)) && ($this->GetReadOnly() === false)) {
// Only doing the check when coming from the REST API, as the user portal might send invalid values (see VerifyCurrentValue() method below)
// Also do not check read only fields, are they are send with a null value when submitting request template from the console
$sCurrentValueForExtKey = $this->currentValue;
if (utils::IsNotNullOrEmptyString($sCurrentValueForExtKey) && ($sCurrentValueForExtKey !== 0)) {
$oSetForExistingCurrentValue = $this->GetObjectsSet();
@@ -272,6 +275,9 @@ class SelectObjectField extends Field
* Resets current value if not among allowed ones.
* By default, reset is done ONLY when the field is not read-only.
*
* Called conditionally from {@see \Combodo\iTop\Portal\Form\ObjectFormManager::Build}
* This check isn't in the Validate method as we don't want to check for untouched and invalid values (value was set in the past, it is now invalid, but the user didn't change it)
*
* @param boolean $bAlways Set to true to verify even when the field is read-only.
*
* @throws \CoreException