mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-20 00:58:48 +02:00
N°895 Portal: Filter linkedsets on remote object scopes
This commit is contained in:
@@ -835,6 +835,8 @@ class ObjectFormManager extends FormManager
|
||||
// - LinkedSet
|
||||
if (in_array(get_class($oField), array('Combodo\\iTop\\Form\\Field\\LinkedSetField')))
|
||||
{
|
||||
/** @var \Combodo\iTop\Form\Field\LinkedSetField $oField */
|
||||
/** @var \AttributeLinkedSetIndirect $oAttDef */
|
||||
// - Overriding attributes to display
|
||||
if ($this->oContainer !== null)
|
||||
{
|
||||
@@ -856,6 +858,32 @@ class ObjectFormManager extends FormManager
|
||||
}
|
||||
$oField->SetAttributesToDisplay($aAttributesToDisplay);
|
||||
}
|
||||
// - Filtering links regarding scopes
|
||||
if ($this->oContainer !== null)
|
||||
{
|
||||
$aLimitedAccessItemIDs = array();
|
||||
|
||||
/** @var \ormLinkSet $oFieldOriginalSet */
|
||||
$oFieldOriginalSet = $oField->GetCurrentValue();
|
||||
while ($oLink = $oFieldOriginalSet->Fetch())
|
||||
{
|
||||
if ($oField->IsIndirect())
|
||||
{
|
||||
$iRemoteKey = $oLink->Get($oAttDef->GetExtKeyToRemote());
|
||||
}
|
||||
else
|
||||
{
|
||||
$iRemoteKey = $oLink->GetKey();
|
||||
}
|
||||
|
||||
if (!$this->oContainer->get('security_helper')->IsActionAllowed(UR_ACTION_READ, $oField->GetTargetClass(), $iRemoteKey))
|
||||
{
|
||||
$aLimitedAccessItemIDs[] = $iRemoteKey;
|
||||
}
|
||||
}
|
||||
$oFieldOriginalSet->rewind();
|
||||
$oField->SetLimitedAccessItemIDs($aLimitedAccessItemIDs);
|
||||
}
|
||||
// - Displaying as opened
|
||||
if (array_key_exists($sAttCode, $aFieldsExtraData) && array_key_exists('opened', $aFieldsExtraData[$sAttCode]))
|
||||
{
|
||||
|
||||
@@ -33,6 +33,8 @@ class LinkedSetField extends Field
|
||||
protected $sExtKeyToRemote;
|
||||
protected $bIndirect;
|
||||
protected $bDisplayOpened;
|
||||
/** @var array $aLimitedAccessItemIDs IDs of the items that are not visible or cannot be edited */
|
||||
protected $aLimitedAccessItemIDs;
|
||||
protected $aAttributesToDisplay;
|
||||
protected $sSearchEndpoint;
|
||||
protected $sInformationEndpoint;
|
||||
@@ -43,6 +45,7 @@ class LinkedSetField extends Field
|
||||
$this->sExtKeyToRemote = null;
|
||||
$this->bIndirect = static::DEFAULT_INDIRECT;
|
||||
$this->bDisplayOpened = static::DEFAULT_DISPLAY_OPENED;
|
||||
$this->aLimitedAccessItemIDs = array();
|
||||
$this->aAttributesToDisplay = array();
|
||||
$this->sSearchEndpoint = null;
|
||||
$this->sInformationEndpoint = null;
|
||||
@@ -132,6 +135,30 @@ class LinkedSetField extends Field
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns IDs of the linked items with a limited access (not visible or not editable)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function GetLimitedAccessItemIDs()
|
||||
{
|
||||
return $this->aLimitedAccessItemIDs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the IDs of items with a limited access (not visible ot no editable)
|
||||
*
|
||||
* @param array $aLimitedAccessItemIDs
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function SetLimitedAccessItemIDs($aLimitedAccessItemIDs)
|
||||
{
|
||||
$this->aLimitedAccessItemIDs = $aLimitedAccessItemIDs;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash array of attributes to be displayed in the linkedset in the form $sAttCode => $sAttLabel
|
||||
*
|
||||
@@ -178,4 +205,15 @@ class LinkedSetField extends Field
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the remote object with $iItemID ID has limited access
|
||||
*
|
||||
* @param int $iItemID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function IsLimitedAccessItem($iItemID)
|
||||
{
|
||||
return in_array($iItemID, $this->aLimitedAccessItemIDs, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
|
||||
namespace Combodo\iTop\Renderer\Bootstrap\FieldRenderer;
|
||||
|
||||
use Exception;
|
||||
use ApplicationContext;
|
||||
use IssueLog;
|
||||
use Dict;
|
||||
use MetaModel;
|
||||
use AttributeFriendlyName;
|
||||
use Combodo\iTop\Renderer\FieldRenderer;
|
||||
use Combodo\iTop\Renderer\RenderingOutput;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use IssueLog;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* Description of BsLinkedSetFieldRenderer
|
||||
@@ -540,6 +540,7 @@ JS
|
||||
*/
|
||||
protected function PrepareItems(&$aItems, &$aItemIds)
|
||||
{
|
||||
/** @var \ormLinkSet $oValueSet */
|
||||
$oValueSet = $this->oField->GetCurrentValue();
|
||||
$oValueSet->OptimizeColumnLoad(array($this->oField->GetTargetClass() => $this->oField->GetAttributesToDisplay(true)));
|
||||
while ($oItem = $oValueSet->Fetch())
|
||||
@@ -564,6 +565,12 @@ JS
|
||||
$oRemoteItem = $oItem;
|
||||
}
|
||||
|
||||
// Skip item if not supposed to be displayed
|
||||
if ($this->oField->IsLimitedAccessItem($oRemoteItem->GetKey()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$aItemProperties = array(
|
||||
'id' => ($this->oField->IsIndirect() && $oItem->IsNew()) ? -1*$oRemoteItem->GetKey() : $oItem->GetKey(),
|
||||
'target_id' => $oRemoteItem->GetKey(),
|
||||
@@ -615,6 +622,7 @@ JS
|
||||
$aItems[] = $aItemProperties;
|
||||
$aItemIds[$aItemProperties['id']] = array();
|
||||
}
|
||||
$oValueSet->rewind();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user