+ use new function in Attachment
This commit is contained in:
Anne-Cath
2024-11-25 15:22:35 +01:00
parent c2d0c310a9
commit 83f1476de4
4 changed files with 66 additions and 71 deletions

View File

@@ -938,31 +938,11 @@ class UserRightsProfile extends UserRightsAddOnAPI
* @param string $sClass * @param string $sClass
* @return string|null Find out which attribute is corresponding the dimension 'owner org' * @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) * 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) public static function GetOwnerOrganizationAttCode($sClass)
{ {
$sAttCode = null; return UserRights::GetOwnerOrganizationAttCode($sClass);
$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;
} }
/** /**

View File

@@ -140,36 +140,19 @@ class InlineImage extends DBObject
*/ */
public function SetDefaultOrgId() public function SetDefaultOrgId()
{ {
// First check that the organization CAN be fetched from the target class if (is_null(UserRights::GetOwnerOrganizationAttCode( $this->Get('item_class')))) {
// // No need for silos
$sClass = $this->Get('item_class'); return;
$aCallSpec = array($sClass, 'MapContextParam'); }
if (is_callable($aCallSpec)) $sOrgAttrCodeForPerson = UserRights::GetOwnerOrganizationAttCode('Person');
{ if (is_null($sOrgAttrCodeForPerson)) {
$sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter // No need for silos
if (MetaModel::IsValidAttCode($sClass, $sAttCode)) return;
{ }
// Second: check that the organization CAN be fetched from the current user
// $oCurrentPerson = MetaModel::GetObject('Person', UserRights::GetContactId(), false);
if (MetaModel::IsValidClass('Person')) if ($oCurrentPerson) {
{ $this->Set('item_org_id', $oCurrentPerson->Get($sOrgAttrCodeForPerson));
$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));
}
}
}
}
}
} }
} }

View File

@@ -2033,6 +2033,40 @@ class UserRights
{ {
return self::$m_sLastLoginStatus; 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;
}
} }
/** /**

View File

@@ -160,26 +160,24 @@
$this->Set('item_class', $sClass); $this->Set('item_class', $sClass);
$this->Set('item_id', $iItemId); $this->Set('item_id', $iItemId);
$aCallSpec = array($sClass, 'MapContextParam');
if (is_callable($aCallSpec)) $sAttCode = UserRights::GetOwnerOrganizationAttCode( $sClass);
{ if (is_null($sAttCode)) {
$sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter // No need for silos
if (MetaModel::IsValidAttCode($sClass, $sAttCode)) 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();
}
}
}
}
} }
$iOrgId = $oItem->Get($sAttCode);
if ($iOrgId > 0)
{
if ($iOrgId != $this->Get('item_org_id'))
{
$this->Set('item_org_id', $iOrgId);
if ($bUpdateOnChange)
{
$this->DBUpdate();
}
}
}
}]]></code> }]]></code>
</method> </method>
<method id="SetDefaultOrgId"> <method id="SetDefaultOrgId">