(Retrofit from trunk) Portal : External keys OQL now intersect with scopes in forms!

SVN:2.3[4381]
This commit is contained in:
Guillaume Lajarige
2016-09-06 07:06:13 +00:00
parent 746c97818e
commit 096236cb3a
2 changed files with 28 additions and 4 deletions

View File

@@ -4365,9 +4365,13 @@ class AttributeExternalKey extends AttributeDBFieldVoid
$oTmpField = $oFormField;
$oFormField->SetOnFinalizeCallback(function() use ($oTmpField, $oTmpAttDef, $oObject)
{
$oSearch = DBSearch::FromOQL($oTmpAttDef->GetValuesDef()->GetFilterExpression());
$oSearch->SetInternalParams(array('this' => $oObject));
$oTmpField->SetSearch($oSearch);
// We set search object only if it has not already been set (overrided)
if ($oTmpField->GetSearch() === null)
{
$oSearch = DBSearch::FromOQL($oTmpAttDef->GetValuesDef()->GetFilterExpression());
$oSearch->SetInternalParams(array('this' => $oObject));
$oTmpField->SetSearch($oSearch);
}
});
}
else

View File

@@ -29,6 +29,7 @@ use \MetaModel;
use \CMDBSource;
use \DBObject;
use \DBObjectSet;
use \DBSearch;
use \DBObjectSearch;
use \DBObjectSetComparator;
use \InlineImage;
@@ -529,6 +530,25 @@ class ObjectFormManager extends FormManager
$oField->SetInformationEndpoint($this->oApp['url_generator']->generate('p_object_get_informations_json'));
}
}
// - Field that require to apply scope on its DM OQL
if (in_array(get_class($oField), array('Combodo\\iTop\\Form\\Field\\SelectObjectField')))
{
if ($this->oApp !== null)
{
$oScopeOriginal = ($oField->GetSearch() !== null) ? $oField->GetSearch() : DBSearch::FromOQL($oAttDef->GetValuesDef()->GetFilterExpression());
$oScopeSearch = $this->oApp['scope_validator']->GetScopeFilterForProfiles(UserRights::ListProfiles(), $oScopeOriginal->GetClass(), UR_ACTION_READ);
if ($oScopeSearch === null)
{
IssueLog::Info(__METHOD__ . ' at line ' . __LINE__ . ' : User #' . UserRights::GetUserId() . ' has no scope query for ' . $sTargetObjectClass . ' class.');
$this->oApp->abort(404, Dict::S('UI:ObjectDoesNotExist'));
}
$oScopeOriginal = $oScopeOriginal->Intersect($oScopeSearch);
$oScopeOriginal->SetInternalParams(array('this' => $this->oObject));
$oField->SetSearch($oScopeOriginal);
}
}
// - Field that require processing on their subfields
if (in_array(get_class($oField), array('Combodo\\iTop\\Form\\Field\\SubFormField')))
{
@@ -986,7 +1006,7 @@ class ObjectFormManager extends FormManager
else
{
$this->oObject->Set($sAttCode, $value);
}
}
}
}
$this->oObject->DoComputeValues();