mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 19:48:49 +02:00
N°6251 - 1:n - Actions must not be proposed to user not allowed (#491)
This commit is contained in:
@@ -21,6 +21,7 @@ use Dict;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use UILinksWidget;
|
||||
use UserRights;
|
||||
use utils;
|
||||
use WebPage;
|
||||
|
||||
@@ -64,6 +65,10 @@ class BlockIndirectLinkSetEditTable extends UIContentBlock
|
||||
/** @var string */
|
||||
public string $sFormPrefix;
|
||||
|
||||
// User rights
|
||||
private bool $bIsAllowCreate;
|
||||
private bool $bIsAllowDelete;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -100,6 +105,11 @@ class BlockIndirectLinkSetEditTable extends UIContentBlock
|
||||
private function Init()
|
||||
{
|
||||
$this->oAttributeLinkedSetIndirect = MetaModel::GetAttributeDef($this->oUILinksWidget->GetClass(), $this->oUILinksWidget->GetAttCode());
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,17 +217,22 @@ EOF
|
||||
|
||||
// Toolbar and actions
|
||||
$oToolbar = ToolbarUIBlockFactory::MakeForButton();
|
||||
$oActionButtonUnlink = ButtonUIBlockFactory::MakeNeutral(Dict::S('UI:Button:Remove'));
|
||||
$oActionButtonUnlink->SetOnClickJsCode("oWidget{$this->oUILinksWidget->GetInputId()}.RemoveSelected();")
|
||||
->AddDataAttribute('action', 'detach');
|
||||
$oToolbar->AddSubBlock($oActionButtonUnlink);
|
||||
|
||||
$oActionButtonLink = ButtonUIBlockFactory::MakeNeutral(Dict::S('UI:Button:Add'));
|
||||
$oActionButtonLink->SetTooltip(Dict::Format('UI:AddLinkedObjectsOf_Class', MetaModel::GetName($this->oAttributeLinkedSetIndirect->GetLinkedClass())))
|
||||
->SetOnClickJsCode("oWidget{$this->oUILinksWidget->GetInputId()}.AddObjects();")
|
||||
->AddDataAttribute('action', 'add');
|
||||
$oToolbar->AddSubBlock($oActionButtonLink);
|
||||
|
||||
|
||||
if ($this->bIsAllowDelete) {
|
||||
$oActionButtonUnlink = ButtonUIBlockFactory::MakeNeutral(Dict::S('UI:Button:Remove'));
|
||||
$oActionButtonUnlink->SetOnClickJsCode("oWidget{$this->oUILinksWidget->GetInputId()}.RemoveSelected();")
|
||||
->AddDataAttribute('action', 'detach');
|
||||
$oToolbar->AddSubBlock($oActionButtonUnlink);
|
||||
}
|
||||
|
||||
if ($this->bIsAllowCreate) {
|
||||
$oActionButtonLink = ButtonUIBlockFactory::MakeNeutral(Dict::S('UI:Button:Add'));
|
||||
$oActionButtonLink->SetTooltip(Dict::Format('UI:AddLinkedObjectsOf_Class', MetaModel::GetName($this->oAttributeLinkedSetIndirect->GetLinkedClass())))
|
||||
->SetOnClickJsCode("oWidget{$this->oUILinksWidget->GetInputId()}.AddObjects();")
|
||||
->AddDataAttribute('action', 'add');
|
||||
$oToolbar->AddSubBlock($oActionButtonLink);
|
||||
}
|
||||
|
||||
$oTablePanel->AddToolbarBlock($oToolbar);
|
||||
$oTablePanel->AddSubBlock($oDataTable);
|
||||
|
||||
@@ -482,12 +497,14 @@ JS
|
||||
$this->oAttributeLinkedSetIndirect->GetLabel(),
|
||||
Dict::S("Class:{$this->oUILinksWidget->GetRemoteClass()}"));
|
||||
|
||||
$aRowActions[] = array(
|
||||
'label' => 'UI:Links:Remove:Button',
|
||||
'tooltip' => $sRemoveButtonTooltip,
|
||||
'icon_classes' => 'fas fa-minus',
|
||||
'js_row_action' => "oWidget{$this->oUILinksWidget->GetInputId()}.Remove(oTrElement);",
|
||||
);
|
||||
if ($this->bIsAllowDelete) {
|
||||
$aRowActions[] = array(
|
||||
'label' => 'UI:Links:Remove:Button',
|
||||
'tooltip' => $sRemoveButtonTooltip,
|
||||
'icon_classes' => 'fas fa-minus',
|
||||
'js_row_action' => "oWidget{$this->oUILinksWidget->GetInputId()}.Remove(oTrElement);",
|
||||
);
|
||||
}
|
||||
|
||||
return $aRowActions;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user