diff --git a/addons/userrights/userrightsprofile.class.inc.php b/addons/userrights/userrightsprofile.class.inc.php index e9ead975b6..1cab75cc1c 100644 --- a/addons/userrights/userrightsprofile.class.inc.php +++ b/addons/userrights/userrightsprofile.class.inc.php @@ -938,31 +938,11 @@ class UserRightsProfile extends UserRightsAddOnAPI * @param string $sClass * @return string|null Find out which attribute is corresponding the dimension 'owner org' * returns null if no such attribute has been found (no filtering should occur) + * @deprecated 3.3.0 use @UserRights::GetOwnerOrganizationAttCode instead */ public static function GetOwnerOrganizationAttCode($sClass) { - $sAttCode = null; - - $aCallSpec = array($sClass, 'MapContextParam'); - if (($sClass == 'Organization') || is_subclass_of($sClass, 'Organization')) - { - $sAttCode = 'id'; - } - elseif (is_callable($aCallSpec)) - { - $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter - if (!MetaModel::IsValidAttCode($sClass, $sAttCode)) - { - // Skip silently. The data model checker will tell you something about this... - $sAttCode = null; - } - } - elseif(MetaModel::IsValidAttCode($sClass, 'org_id')) - { - $sAttCode = 'org_id'; - } - - return $sAttCode; + return UserRights::GetOwnerOrganizationAttCode($sClass); } /** diff --git a/core/inlineimage.class.inc.php b/core/inlineimage.class.inc.php index 1fbcdbc8fa..1f58569d18 100644 --- a/core/inlineimage.class.inc.php +++ b/core/inlineimage.class.inc.php @@ -140,36 +140,19 @@ class InlineImage extends DBObject */ public function SetDefaultOrgId() { - // First check that the organization CAN be fetched from the target class - // - $sClass = $this->Get('item_class'); - $aCallSpec = array($sClass, 'MapContextParam'); - if (is_callable($aCallSpec)) - { - $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter - if (MetaModel::IsValidAttCode($sClass, $sAttCode)) - { - // Second: check that the organization CAN be fetched from the current user - // - if (MetaModel::IsValidClass('Person')) - { - $aCallSpecPerson = array('Person', 'MapContextParam'); - if (is_callable($aCallSpecPerson)) - { - $sAttCodePerson = call_user_func($aCallSpecPerson, 'org_id'); // Returns null when there is no mapping for this parameter - if (MetaModel::IsValidAttCode('Person', $sAttCodePerson)) - { - // OK - try it - // - $oCurrentPerson = MetaModel::GetObject('Person', UserRights::GetContactId(), false); - if ($oCurrentPerson) - { - $this->Set('item_org_id', $oCurrentPerson->Get($sAttCodePerson)); - } - } - } - } - } + if (is_null(UserRights::GetOwnerOrganizationAttCode( $this->Get('item_class')))) { + // No need for silos + return; + } + $sOrgAttrCodeForPerson = UserRights::GetOwnerOrganizationAttCode('Person'); + if (is_null($sOrgAttrCodeForPerson)) { + // No need for silos + return; + } + + $oCurrentPerson = MetaModel::GetObject('Person', UserRights::GetContactId(), false); + if ($oCurrentPerson) { + $this->Set('item_org_id', $oCurrentPerson->Get($sOrgAttrCodeForPerson)); } } diff --git a/core/userrights.class.inc.php b/core/userrights.class.inc.php index 3c4ad349a5..f7ec38601d 100644 --- a/core/userrights.class.inc.php +++ b/core/userrights.class.inc.php @@ -2033,6 +2033,40 @@ class UserRights { return self::$m_sLastLoginStatus; } + + + /** + * @param string $sClass + * @return string|null Find out which attribute is corresponding the dimension 'owner org' + * returns null if no such attribute has been found (no filtering should occur) + * @since 3.3.0 + */ + public static function GetOwnerOrganizationAttCode($sClass) + { + $sAttCode = null; + + $aCallSpec = array($sClass, 'MapContextParam'); + if (($sClass == 'Organization') || is_subclass_of($sClass, 'Organization')) + { + $sAttCode = 'id'; + } + elseif (is_callable($aCallSpec)) + { + $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter + if (!MetaModel::IsValidAttCode($sClass, $sAttCode)) + { + // Skip silently. The data model checker will tell you something about this... + $sAttCode = null; + } + } + elseif(MetaModel::IsValidAttCode($sClass, 'org_id')) + { + $sAttCode = 'org_id'; + } + + return $sAttCode; + } + } /** diff --git a/datamodels/2.x/itop-attachments/datamodel.itop-attachments.xml b/datamodels/2.x/itop-attachments/datamodel.itop-attachments.xml index c661eb97f2..2e8670240c 100755 --- a/datamodels/2.x/itop-attachments/datamodel.itop-attachments.xml +++ b/datamodels/2.x/itop-attachments/datamodel.itop-attachments.xml @@ -160,26 +160,24 @@ $this->Set('item_class', $sClass); $this->Set('item_id', $iItemId); - $aCallSpec = array($sClass, 'MapContextParam'); - if (is_callable($aCallSpec)) - { - $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter - if (MetaModel::IsValidAttCode($sClass, $sAttCode)) - { - $iOrgId = $oItem->Get($sAttCode); - if ($iOrgId > 0) - { - if ($iOrgId != $this->Get('item_org_id')) - { - $this->Set('item_org_id', $iOrgId); - if ($bUpdateOnChange) - { - $this->DBUpdate(); - } - } - } - } + + $sAttCode = UserRights::GetOwnerOrganizationAttCode( $sClass); + if (is_null($sAttCode)) { + // No need for silos + return; } + $iOrgId = $oItem->Get($sAttCode); + if ($iOrgId > 0) + { + if ($iOrgId != $this->Get('item_org_id')) + { + $this->Set('item_org_id', $iOrgId); + if ($bUpdateOnChange) + { + $this->DBUpdate(); + } + } + } }]]>