From d0cad4d829e27837d6141461039c052123d285f1 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Tue, 13 Jun 2023 11:42:40 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B01150=20Fix=20regression=20:=20cannot=20a?= =?UTF-8?q?dd=20caselog=20in=20the=20user=20portal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- sources/Form/Field/MultipleChoicesField.php | 8 ++++---- sources/Form/Field/SelectObjectField.php | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sources/Form/Field/MultipleChoicesField.php b/sources/Form/Field/MultipleChoicesField.php index adaf12176..f7791acb2 100644 --- a/sources/Form/Field/MultipleChoicesField.php +++ b/sources/Form/Field/MultipleChoicesField.php @@ -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)) { diff --git a/sources/Form/Field/SelectObjectField.php b/sources/Form/Field/SelectObjectField.php index 63058268b..2797bb03a 100644 --- a/sources/Form/Field/SelectObjectField.php +++ b/sources/Form/Field/SelectObjectField.php @@ -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