mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-20 15:52:24 +02:00
Refactor
+ use new function in Attachment
This commit is contained in:
@@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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
|
|
||||||
//
|
|
||||||
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);
|
$oCurrentPerson = MetaModel::GetObject('Person', UserRights::GetContactId(), false);
|
||||||
if ($oCurrentPerson)
|
if ($oCurrentPerson) {
|
||||||
{
|
$this->Set('item_org_id', $oCurrentPerson->Get($sOrgAttrCodeForPerson));
|
||||||
$this->Set('item_org_id', $oCurrentPerson->Get($sAttCodePerson));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -160,12 +160,12 @@
|
|||||||
$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);
|
$iOrgId = $oItem->Get($sAttCode);
|
||||||
if ($iOrgId > 0)
|
if ($iOrgId > 0)
|
||||||
{
|
{
|
||||||
@@ -178,8 +178,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}]]></code>
|
}]]></code>
|
||||||
</method>
|
</method>
|
||||||
<method id="SetDefaultOrgId">
|
<method id="SetDefaultOrgId">
|
||||||
|
|||||||
Reference in New Issue
Block a user