diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index d871105da..3277edc9d 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -746,7 +746,9 @@ HTML $aArgs = array('this' => $this); $sEditWhen = $oAttDef->GetEditWhen(); - $bIsEditableBasedOnEditWhen = ($sEditWhen === LINKSET_EDITWHEN_ALWAYS || $sEditWhen === LINKSET_EDITWHEN_ON_HOST_EDITION); + // Calculate if edit_when allows to edit based on current $bEditMode + $bIsEditableBasedOnEditWhen = ($sEditWhen === LINKSET_EDITWHEN_ALWAYS) || + ($bEditMode ? $sEditWhen === LINKSET_EDITWHEN_ON_HOST_EDITION : $sEditWhen === LINKSET_EDITWHEN_ON_HOST_DISPLAY); $bReadOnly = ($iFlags & (OPT_ATT_READONLY | OPT_ATT_SLAVE)) || !$bIsEditableBasedOnEditWhen; if ($bEditMode && (!$bReadOnly)) { @@ -758,9 +760,9 @@ HTML $oPage->add($sHTMLValue); } else { if ($oAttDef->IsIndirect()) { - $oBlockLinkSetViewTable = new BlockIndirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef); + $oBlockLinkSetViewTable = new BlockIndirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef, $bReadOnly); } else { - $oBlockLinkSetViewTable = new BlockDirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef); + $oBlockLinkSetViewTable = new BlockDirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef, $bReadOnly); } $oPage->AddUiBlock($oBlockLinkSetViewTable); } diff --git a/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php b/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php index 53081b659..d406c3c25 100644 --- a/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php +++ b/sources/Application/UI/Links/AbstractBlockLinkSetViewTable.php @@ -91,11 +91,11 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock * @param string $sObjectClass * @param string $sAttCode * @param AttributeLinkedSet $oAttDef + * @param bool $bIsReadOnly * - * @throws CoreException - * @throws Exception + * @throws \CoreException */ - public function __construct(WebPage $oPage, DBObject $oDbObject, string $sObjectClass, string $sAttCode, AttributeLinkedSet $oAttDef) + public function __construct(WebPage $oPage, DBObject $oDbObject, string $sObjectClass, string $sAttCode, AttributeLinkedSet $oAttDef, bool $bIsReadOnly = false) { parent::__construct("links_view_table_$sAttCode", ["ibo-block-links-table"]); @@ -105,6 +105,7 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock $this->sObjectClass = $sObjectClass; $this->oDbObject = $oDbObject; $this->sTableId = 'rel_'.$this->sAttCode; + $this->bIsAttEditable = !$bIsReadOnly; $this->SetDataAttributes(['role' => 'ibo-block-links-table', 'link-attcode' => $sAttCode, 'link-class' => $this->oAttDef->GetLinkedClass()]); // Initialization $this->Init(); @@ -122,7 +123,6 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock private function Init() { $this->sTargetClass = $this->GetTargetClass(); - $this->InitIsAttEditable(); // User rights $this->bIsAllowCreate = $this->bIsAttEditable && UserRights::IsActionAllowed($this->oAttDef->GetLinkedClass(), UR_ACTION_CREATE) == UR_ALLOWED_YES; @@ -199,38 +199,8 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock $oBlock = new DisplayBlock($oLinkSet->GetFilter(), DisplayBlock::ENUM_STYLE_LIST_IN_OBJECT, false); $this->AddSubBlock($oBlock->GetRenderContent($oPage, $this->GetExtraParam(), $this->sTableId)); } - - /** - * @return void - * @throws \CoreException - */ - private function InitIsAttEditable(): void - { - $iFlags = OPT_ATT_NORMAL; - - if ($this->oDbObject->IsNew()) - { - $iFlags = $this->oDbObject->GetInitialStateAttributeFlags($this->sAttCode); - } - else - { - $iFlags = $this->oDbObject->GetAttributeFlags($this->sAttCode); - } - - $bEditWhen = $this->IsEditableBasedOnEditWhen(); - - $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; - } + + /** * GetTableId. diff --git a/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php b/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php index ad431fa0a..831193e9b 100644 --- a/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php +++ b/sources/Application/UI/Links/Direct/BlockDirectLinkSetViewTable.php @@ -179,13 +179,4 @@ 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/BlockIndirectLinkSetViewTable.php b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php index 9447c4f26..dbd18fa18 100644 --- a/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php +++ b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php @@ -126,13 +126,4 @@ 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