From fc7d2551cdca5737e97437a05ca1b65eb2202d4f Mon Sep 17 00:00:00 2001 From: Molkobain Date: Fri, 17 Sep 2021 12:03:12 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B04302=20-=20Fix=20hard-coded=20image=20at?= =?UTF-8?q?t.=20code=20in=20UserRights::GetUserPictureAbsUrl()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/userrights.class.inc.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/userrights.class.inc.php b/core/userrights.class.inc.php index 490225f56..4987fb2fe 100644 --- a/core/userrights.class.inc.php +++ b/core/userrights.class.inc.php @@ -1214,13 +1214,15 @@ class UserRights $sContactClass = get_class($oContact); // Check that Contact object still exists and that Contact class has a picture attribute - if (!is_null($oContact) && MetaModel::IsValidAttCode($sContactClass, static::DEFAULT_CONTACT_PICTURE_ATTCODE)) { + // - Try to get the semantic image attribute, or try to fallback on the default one if none defined + $sContactPictureAttCode = MetaModel::HasImageAttributeCode($sContactClass) ? MetaModel::GetImageAttributeCode($sContactClass) : static::DEFAULT_CONTACT_PICTURE_ATTCODE; + if (!is_null($oContact) && MetaModel::IsValidAttCode($sContactClass, $sContactPictureAttCode)) { /** @var \ormDocument $oPicture */ - $oPicture = $oContact->Get(static::DEFAULT_CONTACT_PICTURE_ATTCODE); + $oPicture = $oContact->Get($sContactPictureAttCode); if ($oPicture->IsEmpty()) { if ($bAllowDefaultPicture === true) { /** @var \AttributeImage $oAttDef */ - $oAttDef = MetaModel::GetAttributeDef($sContactClass, static::DEFAULT_CONTACT_PICTURE_ATTCODE); + $oAttDef = MetaModel::GetAttributeDef($sContactClass, $sContactPictureAttCode); $sPictureUrl = $oAttDef->Get('default_image'); } else { $sPictureUrl = null; @@ -1228,9 +1230,9 @@ class UserRights } else { if (ContextTag::Check(ContextTag::TAG_PORTAL)) { $sSignature = $oPicture->GetSignature(); - $sPictureUrl = utils::GetAbsoluteUrlAppRoot().'pages/exec.php/object/document/display/'.$sContactClass.'/'.$oContact->GetKey().'/'.static::DEFAULT_CONTACT_PICTURE_ATTCODE.'?cache=86400&s='.$sSignature.'&exec_module=itop-portal-base&exec_page=index.php&portal_id='.PORTAL_ID; + $sPictureUrl = utils::GetAbsoluteUrlAppRoot().'pages/exec.php/object/document/display/'.$sContactClass.'/'.$oContact->GetKey().'/'.$sContactPictureAttCode.'?cache=86400&s='.$sSignature.'&exec_module=itop-portal-base&exec_page=index.php&portal_id='.PORTAL_ID; } else { - $sPictureUrl = $oPicture->GetDisplayURL($sContactClass, $oContact->GetKey(), static::DEFAULT_CONTACT_PICTURE_ATTCODE); + $sPictureUrl = $oPicture->GetDisplayURL($sContactClass, $oContact->GetKey(), $sContactPictureAttCode); } } }