From a9bd62dc436c5896444861616f97544557670cb1 Mon Sep 17 00:00:00 2001 From: Stephen Abello Date: Tue, 24 Oct 2023 11:09:12 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B06385=20-=20Allow=20to=20disable=20Linked?= =?UTF-8?q?Set=20(1:n=20&=20n:n)=20edition=20by=20XML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Molkobain --- core/attributedef.class.inc.php | 15 +++++++++ setup/compiler.class.inc.php | 32 +++++++++++++++++++ .../Links/AbstractBlockLinkSetViewTable.php | 14 +++++++- .../Direct/BlockDirectLinkSetEditTable.php | 9 ++++-- .../Direct/BlockDirectLinkSetViewTable.php | 9 ++++++ .../BlockIndirectLinkSetEditTable.php | 9 ++++-- .../BlockIndirectLinkSetViewTable.php | 9 ++++++ 7 files changed, 90 insertions(+), 7 deletions(-) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 0d18a3e93..823cfa93c 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -91,6 +91,12 @@ define('LINKSET_EDITMODE_ACTIONS', 2); // Show the usual 'Actions' popup menu define('LINKSET_EDITMODE_INPLACE', 3); // The "linked" objects can be created/modified/deleted in place define('LINKSET_EDITMODE_ADDREMOVE', 4); // The "linked" objects can be added/removed in place +define('LINKSET_EDITWHEN_NEVER', 0); // The linkset cannot be edited at all from inside this object +define('LINKSET_EDITWHEN_ON_HOST_EDITION', 1); // The only possible action is to open a new window to create a new object +define('LINKSET_EDITWHEN_ON_HOST_DISPLAY', 2); // Show the usual 'Actions' popup menu +define('LINKSET_EDITWHEN_ALWAYS', 3); // Show the usual 'Actions' popup menu + + define('LINKSET_DISPLAY_STYLE_PROPERTY', 'property'); define('LINKSET_DISPLAY_STYLE_TAB', 'tab'); @@ -1703,6 +1709,15 @@ class AttributeLinkedSet extends AttributeDefinition public function GetEditMode() { return $this->GetOptional('edit_mode', LINKSET_EDITMODE_ACTIONS); + } + + /** + * @return int see LINKSET_EDITWHEN_* constants + * @since 3.1.1 3.2.0 N°6385 + */ + public function GetEditWhen(): int + { + return $this->GetOptional('edit_when', LINKSET_EDITWHEN_ALWAYS); } /** diff --git a/setup/compiler.class.inc.php b/setup/compiler.class.inc.php index c7ae5026b..92e5a9229 100644 --- a/setup/compiler.class.inc.php +++ b/setup/compiler.class.inc.php @@ -938,6 +938,30 @@ EOF return $aXmlToPHP[$sEditMode]; } + + /** + * Helper to format the edit-when for direct linkset + * + * @param string $sEditWhen Value set from within the XML + * @return string PHP flag + * + * @throws \DOMFormatException + */ + protected function EditWhenToPHP($sEditWhen): string + { + static $aXmlToPHP = array( + 'never' => 'LINKSET_EDITWHEN_NEVER', + 'on_host_edition' => 'LINKSET_EDITWHEN_ON_HOST_EDITION', + 'on_host_display' => 'LINKSET_EDITWHEN_ON_HOST_DISPLAY', + 'always' => 'LINKSET_EDITWHEN_ALWAYS', + ); + + if (!array_key_exists($sEditWhen, $aXmlToPHP)) + { + throw new DOMFormatException("Edit mode: unknown value '$sEditWhen'"); + } + return $aXmlToPHP[$sEditWhen]; + } /** * Format a path (file or url) as an absolute path or relative to the module or the app @@ -2054,6 +2078,7 @@ EOF $this->CompileCommonProperty('duplicates', $oField, $aParameters, $sModuleRelativeDir, false); $this->CompileCommonProperty('display_style', $oField, $aParameters, $sModuleRelativeDir); $this->CompileCommonProperty('edit_mode', $oField, $aParameters, $sModuleRelativeDir); + $this->CompileCommonProperty('edit_when', $oField, $aParameters, $sModuleRelativeDir); $this->CompileCommonProperty('filter', $oField, $aParameters, $sModuleRelativeDir); $this->CompileCommonProperty('with_php_constraint', $oField, $aParameters, $sModuleRelativeDir, false); $aParameters['depends_on'] = $sDependencies; @@ -2064,6 +2089,7 @@ EOF $this->CompileCommonProperty('count_max', $oField, $aParameters, $sModuleRelativeDir, 0); $this->CompileCommonProperty('display_style', $oField, $aParameters, $sModuleRelativeDir); $this->CompileCommonProperty('edit_mode', $oField, $aParameters, $sModuleRelativeDir); + $this->CompileCommonProperty('edit_when', $oField, $aParameters, $sModuleRelativeDir); $this->CompileCommonProperty('filter', $oField, $aParameters, $sModuleRelativeDir); $this->CompileCommonProperty('with_php_constraint', $oField, $aParameters, $sModuleRelativeDir, false); $aParameters['depends_on'] = $sDependencies; @@ -2289,6 +2315,12 @@ EOF $aParameters['edit_mode'] = $this->EditModeToPHP($sEditMode); } break; + case 'edit_when': + $sEditWhen = $oField->GetChildText('edit_when'); + if(!is_null($sEditWhen)){ + $aParameters['edit_when'] = $this->EditWhenToPHP($sEditWhen); + } + break; case 'mappings': $oMappings = $oField->GetUniqueElement('mappings'); $oMappingNodes = $oMappings->getElementsByTagName('mapping'); diff --git a/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php b/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php index a7f7b3b98..10f08155a 100644 --- a/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php +++ b/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php @@ -216,8 +216,20 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock { $iFlags = $this->oDbObject->GetAttributeFlags($this->sAttCode); } + + $bEditWhen = $this->IsEditableBasedOnEditWhen(); - $this->bIsAttEditable = !($iFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE | OPT_ATT_HIDDEN)); + $this->bIsAttEditable = !($iFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE | OPT_ATT_HIDDEN)) && $bEditWhen; + } + + /** + * Compares Linkset attribute edit_when values with its usage requirements + * + * @return bool + * @since 3.1.1 3.2.0 N°6385 + */ + protected function IsEditableBasedOnEditWhen(): bool{ + return true; } /** diff --git a/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php b/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php index 633d41780..2dd105f94 100644 --- a/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php +++ b/sources/Application/UI/Links/Direct/BlockDirectLinkSetEditTable.php @@ -121,10 +121,13 @@ class BlockDirectLinkSetEditTable extends UIContentBlock { $this->oAttributeLinkedSet = MetaModel::GetAttributeDef($this->oUILinksDirectWidget->GetClass(), $this->oUILinksDirectWidget->GetAttCode()); + $sEditWhen = $this->oAttributeLinkedSet->GetEditWhen(); + $bIsEditableBasedOnEditWhen = ($sEditWhen === LINKSET_EDITWHEN_ALWAYS || $sEditWhen === LINKSET_EDITWHEN_ON_HOST_EDITION); + // User rights - $this->bIsAllowCreate = UserRights::IsActionAllowed($this->oAttributeLinkedSet->GetLinkedClass(), UR_ACTION_CREATE) == UR_ALLOWED_YES; - $this->bIsAllowModify = UserRights::IsActionAllowed($this->oAttributeLinkedSet->GetLinkedClass(), UR_ACTION_MODIFY) == UR_ALLOWED_YES; - $this->bIsAllowDelete = UserRights::IsActionAllowed($this->oAttributeLinkedSet->GetLinkedClass(), UR_ACTION_DELETE) == UR_ALLOWED_YES; + $this->bIsAllowCreate = UserRights::IsActionAllowed($this->oAttributeLinkedSet->GetLinkedClass(), UR_ACTION_CREATE) == UR_ALLOWED_YES && $bIsEditableBasedOnEditWhen; + $this->bIsAllowModify = UserRights::IsActionAllowed($this->oAttributeLinkedSet->GetLinkedClass(), UR_ACTION_MODIFY) == UR_ALLOWED_YES && $bIsEditableBasedOnEditWhen; + $this->bIsAllowDelete = UserRights::IsActionAllowed($this->oAttributeLinkedSet->GetLinkedClass(), UR_ACTION_DELETE) == UR_ALLOWED_YES && $bIsEditableBasedOnEditWhen; } /** diff --git a/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php b/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php index 831193e9b..ad431fa0a 100644 --- a/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php +++ b/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php @@ -179,4 +179,13 @@ class BlockDirectLinkSetViewTable extends AbstractBlockLinkSetViewTable return $aDefaults; } + + /** + * @inheritDoc + */ + protected function IsEditableBasedOnEditWhen(): bool + { + $sEditWhen = $this->oAttDef->GetEditWhen(); + return $sEditWhen === LINKSET_EDITWHEN_ALWAYS || $sEditWhen === LINKSET_EDITWHEN_ON_HOST_DISPLAY; + } } \ No newline at end of file diff --git a/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetEditTable.php b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetEditTable.php index 21346df70..36e6bc359 100644 --- a/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetEditTable.php +++ b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetEditTable.php @@ -107,10 +107,13 @@ class BlockIndirectLinkSetEditTable extends UIContentBlock { $this->oAttributeLinkedSetIndirect = MetaModel::GetAttributeDef($this->oUILinksWidget->GetClass(), $this->oUILinksWidget->GetAttCode()); + $sEditWhen = $this->oAttributeLinkedSetIndirect->GetEditWhen(); + $bIsEditableBasedOnEditWhen = ($sEditWhen === LINKSET_EDITWHEN_ALWAYS || $sEditWhen === LINKSET_EDITWHEN_ON_HOST_EDITION); + // User rights - $this->bIsAllowCreate = UserRights::IsActionAllowed($this->oAttributeLinkedSetIndirect->GetLinkedClass(), UR_ACTION_CREATE) == UR_ALLOWED_YES; - $this->bIsAllowModify = UserRights::IsActionAllowed($this->oAttributeLinkedSetIndirect->GetLinkedClass(), UR_ACTION_MODIFY) == UR_ALLOWED_YES; - $this->bIsAllowDelete = UserRights::IsActionAllowed($this->oAttributeLinkedSetIndirect->GetLinkedClass(), UR_ACTION_DELETE) == UR_ALLOWED_YES; + $this->bIsAllowCreate = UserRights::IsActionAllowed($this->oAttributeLinkedSetIndirect->GetLinkedClass(), UR_ACTION_CREATE) == UR_ALLOWED_YES && $bIsEditableBasedOnEditWhen; + $this->bIsAllowModify = UserRights::IsActionAllowed($this->oAttributeLinkedSetIndirect->GetLinkedClass(), UR_ACTION_MODIFY) == UR_ALLOWED_YES && $bIsEditableBasedOnEditWhen; + $this->bIsAllowDelete = UserRights::IsActionAllowed($this->oAttributeLinkedSetIndirect->GetLinkedClass(), UR_ACTION_DELETE) == UR_ALLOWED_YES && $bIsEditableBasedOnEditWhen; } /** diff --git a/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php index dbd18fa18..9447c4f26 100644 --- a/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php +++ b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php @@ -126,4 +126,13 @@ class BlockIndirectLinkSetViewTable extends AbstractBlockLinkSetViewTable return $sAttCodesToDisplay; } + + /** + * @inheritDoc + */ + protected function IsEditableBasedOnEditWhen(): bool + { + $sEditWhen = $this->oAttDef->GetEditWhen(); + return $sEditWhen === LINKSET_EDITWHEN_ALWAYS || $sEditWhen === LINKSET_EDITWHEN_ON_HOST_DISPLAY; + } } \ No newline at end of file