From 4038d4d925630a308230dd3cd493a45f683182b1 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Tue, 16 May 2023 17:34:50 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B06314=20N=C2=B01150=20Fix=20cannot=20reop?= =?UTF-8?q?en=20or=20close=20a=20UR=20in=20the=20user=20portal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since introduction of MultipleChoicesField and SelectObjectField value checks with b71cd218, when a portal user was trying to do an action on a resolved UR the agent_id field was rejected. The reason for the rejection is the corresponding SelectObjectField query is containing the portal user scopes (query generated in ObjectFormManager::Build), and of course the agent_id set isn't in this scope... As a workaround we are disabling those checks for read only fields (values are set server side and possibly in a different context than the portal user) --- sources/Form/Field/MultipleChoicesField.php | 18 +++++++------ sources/Form/Field/SelectObjectField.php | 30 +++++++++++---------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/sources/Form/Field/MultipleChoicesField.php b/sources/Form/Field/MultipleChoicesField.php index 20ab99749..adaf12176 100644 --- a/sources/Form/Field/MultipleChoicesField.php +++ b/sources/Form/Field/MultipleChoicesField.php @@ -218,14 +218,16 @@ abstract class MultipleChoicesField extends Field $this->SetValid(true); $this->EmptyErrorMessages(); - if (count($this->currentValue) > 0) { - foreach ($this->currentValue as $sCode => $value) { - if (utils::IsNullOrEmptyString($value)) { - continue; - } - if (false === array_key_exists($value, $this->aChoices)) { - $this->SetValid(false); - $this->AddErrorMessage("Value ({$value}) is not part of the field possible values list"); + if ($this->GetReadOnly() === false) { + if (count($this->currentValue) > 0) { + foreach ($this->currentValue as $sCode => $value) { + if (utils::IsNullOrEmptyString($value)) { + continue; + } + if (false === array_key_exists($value, $this->aChoices)) { + $this->SetValid(false); + $this->AddErrorMessage("Value ({$value}) is not part of the field possible values list"); + } } } } diff --git a/sources/Form/Field/SelectObjectField.php b/sources/Form/Field/SelectObjectField.php index df547f977..1d70a437d 100644 --- a/sources/Form/Field/SelectObjectField.php +++ b/sources/Form/Field/SelectObjectField.php @@ -250,22 +250,24 @@ class SelectObjectField extends Field } public function Validate() { - $sCurrentValueForExtKey = $this->currentValue; - if (utils::IsNotNullOrEmptyString($sCurrentValueForExtKey) && ($sCurrentValueForExtKey !== 0)) { - $oSearchForExistingCurrentValue = $this->oSearch->DeepClone(); - $oSearchForExistingCurrentValue->AddCondition('id', $sCurrentValueForExtKey, '='); - $oCheckIdAgainstCurrentValueExpression = new BinaryExpression( - new FieldExpression('id', $oSearchForExistingCurrentValue->GetClassAlias()), '=', new ScalarExpression($sCurrentValueForExtKey) - ); - $oSearchForExistingCurrentValue->AddConditionExpression($oCheckIdAgainstCurrentValueExpression); - $oSetForExistingCurrentValue = new DBObjectSet($oSearchForExistingCurrentValue); - $iObjectsCount = $oSetForExistingCurrentValue->CountWithLimit(1); + if ($this->GetReadOnly() === false) { + $sCurrentValueForExtKey = $this->currentValue; + if (utils::IsNotNullOrEmptyString($sCurrentValueForExtKey) && ($sCurrentValueForExtKey !== 0)) { + $oSearchForExistingCurrentValue = $this->oSearch->DeepClone(); + $oSearchForExistingCurrentValue->AddCondition('id', $sCurrentValueForExtKey, '='); + $oCheckIdAgainstCurrentValueExpression = new BinaryExpression( + new FieldExpression('id', $oSearchForExistingCurrentValue->GetClassAlias()), '=', new ScalarExpression($sCurrentValueForExtKey) + ); + $oSearchForExistingCurrentValue->AddConditionExpression($oCheckIdAgainstCurrentValueExpression); + $oSetForExistingCurrentValue = new DBObjectSet($oSearchForExistingCurrentValue); + $iObjectsCount = $oSetForExistingCurrentValue->CountWithLimit(1); - if ($iObjectsCount === 0) { - $this->SetValid(false); - $this->AddErrorMessage("Value $sCurrentValueForExtKey does not match the corresponding filter set"); + if ($iObjectsCount === 0) { + $this->SetValid(false); + $this->AddErrorMessage("Value $sCurrentValueForExtKey does not match the corresponding filter set"); - return $this->GetValid(); + return $this->GetValid(); + } } }