mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
Portal : new helper method to add scope to a DbSearch (moved from existing one in ManageBrick)
SVN:trunk[5822]
This commit is contained in:
@@ -156,7 +156,9 @@ class ManageBrickController extends BrickController
|
|||||||
{
|
{
|
||||||
$oQuery = DBSearch::FromOQL($oBrick->GetOql());
|
$oQuery = DBSearch::FromOQL($oBrick->GetOql());
|
||||||
$sClass = $oQuery->GetClass();
|
$sClass = $oQuery->GetClass();
|
||||||
$this->AddScopeToQuery($oQuery, $oApp, $oBrick, $sClass);
|
/** @var \Combodo\iTop\Portal\Helper\ScopeValidatorHelper $oScopeHelper */
|
||||||
|
$oScopeHelper = $oApp['scope_validator'];
|
||||||
|
$oScopeHelper->AddScopeToQuery($oQuery, $sClass);
|
||||||
$aData = array();
|
$aData = array();
|
||||||
$this->ManageSearchValue($oRequest, $aData, $oQuery, $sClass);
|
$this->ManageSearchValue($oRequest, $aData, $oQuery, $sClass);
|
||||||
|
|
||||||
@@ -304,7 +306,11 @@ class ManageBrickController extends BrickController
|
|||||||
{
|
{
|
||||||
$oConditionQuery = $oQuery->Intersect(DBSearch::FromOQL($aGroup['condition']));
|
$oConditionQuery = $oQuery->Intersect(DBSearch::FromOQL($aGroup['condition']));
|
||||||
// - Restricting query to scope
|
// - Restricting query to scope
|
||||||
if ($this->AddScopeToQuery($oConditionQuery, $oApp, $oBrick, $oConditionQuery->GetClass()))
|
|
||||||
|
/** @var \Combodo\iTop\Portal\Helper\ScopeValidatorHelper $oScopeHelper */
|
||||||
|
$oScopeHelper = $oApp['scope_validator'];
|
||||||
|
$bHasScope = $oScopeHelper->AddScopeToQuery($oConditionQuery, $oConditionQuery->GetClass());
|
||||||
|
if ($bHasScope)
|
||||||
{
|
{
|
||||||
// - Building ObjectSet
|
// - Building ObjectSet
|
||||||
$oConditionSet = new DBObjectSet($oConditionQuery);
|
$oConditionSet = new DBObjectSet($oConditionQuery);
|
||||||
@@ -421,7 +427,10 @@ class ManageBrickController extends BrickController
|
|||||||
// Restricting query to allowed scope on each classes
|
// Restricting query to allowed scope on each classes
|
||||||
// Note: Will need to moved the scope restriction on queries elsewhere when we consider grouping on something else than finalclass
|
// Note: Will need to moved the scope restriction on queries elsewhere when we consider grouping on something else than finalclass
|
||||||
// Note: We now get view scope instead of edit scope as we allowed users to view/edit objects in the brick regarding their rights
|
// Note: We now get view scope instead of edit scope as we allowed users to view/edit objects in the brick regarding their rights
|
||||||
if (!$this->AddScopeToQuery($oAreaQuery, $oApp, $oBrick, $aGroupingAreasValue['value']))
|
/** @var \Combodo\iTop\Portal\Helper\ScopeValidatorHelper $oScopeHelper */
|
||||||
|
$oScopeHelper = $oApp['scope_validator'];
|
||||||
|
$bHasScope = $oScopeHelper->AddScopeToQuery($oAreaQuery, $aGroupingAreasValue['value']);
|
||||||
|
if (!$bHasScope)
|
||||||
{
|
{
|
||||||
// if no scope apply does not allow any data
|
// if no scope apply does not allow any data
|
||||||
$oAreaQuery = null;
|
$oAreaQuery = null;
|
||||||
@@ -796,7 +805,9 @@ class ManageBrickController extends BrickController
|
|||||||
$aGroupingTabsValues = array();
|
$aGroupingTabsValues = array();
|
||||||
$aDistinctResults = array();
|
$aDistinctResults = array();
|
||||||
$oDistinctQuery = DBSearch::FromOQL($oBrick->GetOql());
|
$oDistinctQuery = DBSearch::FromOQL($oBrick->GetOql());
|
||||||
$bHasScope = $this->AddScopeToQuery($oDistinctQuery, $oApp, $oBrick, $oDistinctQuery->GetClass());
|
/** @var \Combodo\iTop\Portal\Helper\ScopeValidatorHelper $oScopeHelper */
|
||||||
|
$oScopeHelper = $oApp['scope_validator'];
|
||||||
|
$bHasScope = $oScopeHelper->AddScopeToQuery($oDistinctQuery, $oDistinctQuery->GetClass());
|
||||||
if ($bHasScope)
|
if ($bHasScope)
|
||||||
{
|
{
|
||||||
// - Adding field condition
|
// - Adding field condition
|
||||||
@@ -903,35 +914,10 @@ class ManageBrickController extends BrickController
|
|||||||
protected function GetScopedQuery(Application $oApp, ManageBrick $oBrick, $sClass)
|
protected function GetScopedQuery(Application $oApp, ManageBrick $oBrick, $sClass)
|
||||||
{
|
{
|
||||||
$oQuery = DBSearch::FromOQL($oBrick->GetOql());
|
$oQuery = DBSearch::FromOQL($oBrick->GetOql());
|
||||||
$this->AddScopeToQuery($oQuery, $oApp, $oBrick, $sClass);
|
/** @var \Combodo\iTop\Portal\Helper\ScopeValidatorHelper $oScopeHelper */
|
||||||
|
$oScopeHelper = $oApp['scope_validator'];
|
||||||
|
$oScopeHelper->AddScopeToQuery($oQuery, $sClass);
|
||||||
|
|
||||||
return $oQuery;
|
return $oQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param DBSearch $oQuery
|
|
||||||
* @param Application $oApp
|
|
||||||
* @param ManageBrick $oBrick
|
|
||||||
* @param string $sClass
|
|
||||||
*
|
|
||||||
* @return bool true if scope exists, false if scope is null
|
|
||||||
*/
|
|
||||||
protected function AddScopeToQuery(DBSearch &$oQuery, Application $oApp, ManageBrick $oBrick, $sClass)
|
|
||||||
{
|
|
||||||
$oScopeQuery = $oApp['scope_validator']->GetScopeFilterForProfiles(UserRights::ListProfiles(), $sClass,
|
|
||||||
UR_ACTION_READ);
|
|
||||||
if ($oScopeQuery !== null)
|
|
||||||
{
|
|
||||||
$oQuery = $oQuery->Intersect($oScopeQuery);
|
|
||||||
// - Allowing all data if necessary
|
|
||||||
if ($oScopeQuery->IsAllDataAllowed())
|
|
||||||
{
|
|
||||||
$oQuery->AllowAllData();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,15 +19,23 @@
|
|||||||
|
|
||||||
namespace Combodo\iTop\Portal\Helper;
|
namespace Combodo\iTop\Portal\Helper;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use DOMNodeList;
|
|
||||||
use DOMFormatException;
|
|
||||||
use utils;
|
|
||||||
use ProfilesConfig;
|
|
||||||
use MetaModel;
|
|
||||||
use DBSearch;
|
use DBSearch;
|
||||||
use DBUnionSearch;
|
use DBUnionSearch;
|
||||||
|
use DOMFormatException;
|
||||||
|
use DOMNodeList;
|
||||||
|
use Exception;
|
||||||
|
use MetaModel;
|
||||||
|
use ProfilesConfig;
|
||||||
|
use UserRights;
|
||||||
|
use utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ScopeValidatorHelper
|
||||||
|
*
|
||||||
|
* Inside the portal this service is injected, get the instance using $oApp['scope_validator']
|
||||||
|
*
|
||||||
|
* @package Combodo\iTop\Portal\Helper
|
||||||
|
*/
|
||||||
class ScopeValidatorHelper
|
class ScopeValidatorHelper
|
||||||
{
|
{
|
||||||
const ENUM_MODE_READ = 'r';
|
const ENUM_MODE_READ = 'r';
|
||||||
@@ -113,6 +121,7 @@ class ScopeValidatorHelper
|
|||||||
|
|
||||||
$this->sInstancePrefix = $sInstancePrefix;
|
$this->sInstancePrefix = $sInstancePrefix;
|
||||||
$this->sGeneratedClass = $this->sInstancePrefix . static::DEFAULT_GENERATED_CLASS;
|
$this->sGeneratedClass = $this->sInstancePrefix . static::DEFAULT_GENERATED_CLASS;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -543,6 +552,30 @@ class ScopeValidatorHelper
|
|||||||
return $oSearch;
|
return $oSearch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param DBSearch $oQuery
|
||||||
|
* @param string $sClass
|
||||||
|
*
|
||||||
|
* @return bool true if scope exists, false if scope is null
|
||||||
|
*/
|
||||||
|
public function AddScopeToQuery(DBSearch &$oQuery, $sClass)
|
||||||
|
{
|
||||||
|
$oScopeQuery = $this->GetScopeFilterForProfiles(UserRights::ListProfiles(), $sClass, UR_ACTION_READ);
|
||||||
|
if ($oScopeQuery !== null)
|
||||||
|
{
|
||||||
|
$oQuery = $oQuery->Intersect($oScopeQuery);
|
||||||
|
// - Allowing all data if necessary
|
||||||
|
if ($oScopeQuery->IsAllDataAllowed())
|
||||||
|
{
|
||||||
|
$oQuery->AllowAllData();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if at least one of the $aProfiles has the ignore_silos flag set to true for the $sClass.
|
* Returns true if at least one of the $aProfiles has the ignore_silos flag set to true for the $sClass.
|
||||||
*
|
*
|
||||||
@@ -665,6 +698,7 @@ class $sClassName
|
|||||||
}
|
}
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
return $sPHP;
|
return $sPHP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user