diff --git a/core/cmdbchangeop.class.inc.php b/core/cmdbchangeop.class.inc.php index ae1f6a154c..c87d6c739e 100644 --- a/core/cmdbchangeop.class.inc.php +++ b/core/cmdbchangeop.class.inc.php @@ -175,22 +175,12 @@ class CMDBChangeOpDelete extends CMDBChangeOp } } -/** - * Interface iCMDBChangeOpSetAttribute - * - * @since 2.8.0 - */ -interface iCMDBChangeOpSetAttribute -{ - -} - /** * Record the modification of an attribute (abstract) * * @package iTopORM */ -class CMDBChangeOpSetAttribute extends CMDBChangeOp implements iCMDBChangeOpSetAttribute +class CMDBChangeOpSetAttribute extends CMDBChangeOp { /** * @inheritDoc diff --git a/core/userrights.class.inc.php b/core/userrights.class.inc.php index 283f6cc688..5757ec353d 100644 --- a/core/userrights.class.inc.php +++ b/core/userrights.class.inc.php @@ -1291,7 +1291,20 @@ class UserRights } if (is_null($oUser)) { - return ''; + $sInitials = ''; + $aLoginParts = explode(' ', $sLogin); + foreach($aLoginParts as $sLoginPart) + { + // Keep only upper case first letters + // eg. "My first name My last name" => "MM" + // eg. "Carrie Anne Moss" => "CAM" + if(preg_match('/^\p{Lu}/u', $sLoginPart) > 0) + { + $sInitials .= mb_substr($sLoginPart, 0, 1); + } + } + + return $sInitials; } return $oUser->GetInitials(); } diff --git a/sources/application/UI/Layout/ActivityPanel/ActivityEntry/ActivityEntry.php b/sources/application/UI/Layout/ActivityPanel/ActivityEntry/ActivityEntry.php index b342fc204c..d12ca2eca7 100644 --- a/sources/application/UI/Layout/ActivityPanel/ActivityEntry/ActivityEntry.php +++ b/sources/application/UI/Layout/ActivityPanel/ActivityEntry/ActivityEntry.php @@ -51,7 +51,7 @@ class ActivityEntry extends UIBlock protected $sType; /** @var string $sDecorationClasses CSS classes to use to decorate the entry */ protected $sDecorationClasses; - /** @var string $sContent Raw content of the entry itself (should not have been processed / escaped) */ + /** @var string|null $sContent Raw content of the entry itself (should not have been processed / escaped) */ protected $sContent; /** @var \DateTime $oDateTime Date / time the entry occurred */ protected $oDateTime; @@ -72,7 +72,7 @@ class ActivityEntry extends UIBlock * ActivityEntry constructor. * * @param \DateTime $oDateTime - * @param \User $sAuthorLogin + * @param string $sAuthorLogin * @param string|null $sContent * @param string|null $sId * @@ -141,11 +141,11 @@ class ActivityEntry extends UIBlock /** * Set the content without any filtering / escaping * - * @param string $sContent + * @param string|null $sContent * * @return $this */ - public function SetContent(string $sContent) + public function SetContent(?string $sContent) { $this->sContent = $sContent; @@ -206,8 +206,18 @@ class ActivityEntry extends UIBlock public function SetAuthor(string $sAuthorLogin) { $this->sAuthorLogin = $sAuthorLogin; - // TODO 2.8.0: Check that this does not return '' when author is the CRON or an extension. - $this->sAuthorFriendlyname = UserRights::GetUserFriendlyName($this->sAuthorLogin); + + // Set friendlyname to whatever we have in case $sAuthorLogin is not a valid login (deleted user, cron, ...) + $iAuthorId = UserRights::GetUserId($this->sAuthorLogin); + if(empty($iAuthorId) === true) + { + $this->sAuthorFriendlyname = $this->sAuthorLogin; + } + else + { + // TODO 2.8.0: Check that this does not return '' when author is the CRON or an extension. + $this->sAuthorFriendlyname = UserRights::GetUserFriendlyName($this->sAuthorLogin); + } $this->sAuthorInitials = UserRights::GetUserInitials($this->sAuthorLogin); $this->sAuthorPictureAbsUrl = UserRights::GetContactPictureAbsUrl($this->sAuthorLogin, false); $this->bIsFromCurrentUser = UserRights::GetUserId($this->sAuthorLogin) === UserRights::GetUserId(); diff --git a/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpFactory.php b/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpFactory.php index 9852ff82f3..53c0d0e203 100644 --- a/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpFactory.php +++ b/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpFactory.php @@ -25,6 +25,7 @@ use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\ActivityEntry use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\EditsEntry; use DateTime; use iCMDBChangeOp; +use MetaModel; /** * Class CMDBChangeOpFactory @@ -52,13 +53,42 @@ class CMDBChangeOpFactory public static function MakeFromCmdbChangeOp(iCMDBChangeOp $oChangeOp) { $oDateTime = DateTime::createFromFormat(AttributeDateTime::GetInternalFormat(), $oChangeOp->Get('date')); - $sAuthorFriendlyname = $oChangeOp->Get('userinfo'); $sContent = $oChangeOp->GetDescription(); - $oEntry = new ActivityEntry($oDateTime, $sAuthorFriendlyname, $sContent); + // Retrieve author login + $sAuthorLogin = static::GetUserLoginFromChangeOp($oChangeOp); + + $oEntry = new ActivityEntry($oDateTime, $sAuthorLogin, $sContent); $oEntry->SetType(static::DEFAULT_TYPE) ->SetDecorationClasses(static::DEFAULT_DECORATION_CLASSES); return $oEntry; } + + /** + * Return the login of the $oChangeOp author or its friendlyname if the user cannot be retrieved. + * + * @param \iCMDBChangeOp $oChangeOp + * + * @return string|null + * @throws \ArchivedObjectException + * @throws \CoreException + */ + public static function GetUserLoginFromChangeOp(iCMDBChangeOp $oChangeOp) + { + $iAuthorId = $oChangeOp->Get('user_id'); + // - Set login in the friendlyname as a fallback + $sAuthorLogin = $oChangeOp->Get('userinfo'); + // - Try to find user login from its ID if present (since iTop 2.8.0) + if(empty($iAuthorId) === false) + { + $oAuthor = MetaModel::GetObject('User', $iAuthorId, false, true); + if(empty($oAuthor) === false) + { + $sAuthorLogin = $oAuthor->Get('login'); + } + } + + return $sAuthorLogin; + } } \ No newline at end of file diff --git a/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpSetAttributeFactory.php b/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpSetAttributeFactory.php index 3866751570..40dadf7f83 100644 --- a/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpSetAttributeFactory.php +++ b/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpSetAttributeFactory.php @@ -23,7 +23,7 @@ namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBCha use AttributeDateTime; use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\EditsEntry; use DateTime; -use iCMDBChangeOpSetAttribute; +use iCMDBChangeOp; /** * Class CMDBChangeOpSetAttributeFactory @@ -33,25 +33,27 @@ use iCMDBChangeOpSetAttribute; * @author Guillaume Lajarige * @package Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBChangeOp */ -class CMDBChangeOpSetAttributeFactory +class CMDBChangeOpSetAttributeFactory extends CMDBChangeOpFactory { /** * Make an EditsEntry from the iCMDBChangeOpSetAttribute $oChangeOp * - * @param \iCMDBChangeOpSetAttribute $oChangeOp + * @param \iCMDBChangeOp $oChangeOp * * @return \Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\EditsEntry * @throws \OQLException * @throws \Exception */ - public static function MakeFromCmdbChangeOp(iCMDBChangeOpSetAttribute $oChangeOp) + public static function MakeFromCmdbChangeOp(iCMDBChangeOp $oChangeOp) { $sHostObjectClass = $oChangeOp->Get('objclass'); $sAttCode = $oChangeOp->Get('attcode'); $oDateTime = DateTime::createFromFormat(AttributeDateTime::GetInternalFormat(), $oChangeOp->Get('date')); - $sAuthorFriendlyname = $oChangeOp->Get('userinfo'); - $oEntry = new EditsEntry($oDateTime, $sAuthorFriendlyname, $sHostObjectClass); + // Retrieve author login + $sAuthorLogin = static::GetUserLoginFromChangeOp($oChangeOp); + + $oEntry = new EditsEntry($oDateTime, $sAuthorLogin, $sHostObjectClass); $oEntry->AddAttribute($sAttCode, $oChangeOp->GetDescription()); return $oEntry; diff --git a/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpSetAttributeScalarFactory.php b/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpSetAttributeScalarFactory.php index e50a32b0c9..1ec8e875d2 100644 --- a/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpSetAttributeScalarFactory.php +++ b/sources/application/UI/Layout/ActivityPanel/ActivityEntry/CMDBChangeOp/CMDBChangeOpSetAttributeScalarFactory.php @@ -21,7 +21,7 @@ namespace Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\CMDBCha use AttributeDateTime; -use iCMDBChangeOpSetAttribute; +use iCMDBChangeOp; use Combodo\iTop\Application\UI\Layout\ActivityPanel\ActivityEntry\TransitionEntry; use DateTime; use MetaModel; @@ -39,7 +39,7 @@ class CMDBChangeOpSetAttributeScalarFactory extends CMDBChangeOpSetAttributeFact * @inheritDoc * @throws \CoreException */ - public static function MakeFromCmdbChangeOp(iCMDBChangeOpSetAttribute $oChangeOp) + public static function MakeFromCmdbChangeOp(iCMDBChangeOp $oChangeOp) { $sHostObjectClass = $oChangeOp->Get('objclass'); $sAttCode = $oChangeOp->Get('attcode'); @@ -48,12 +48,14 @@ class CMDBChangeOpSetAttributeScalarFactory extends CMDBChangeOpSetAttributeFact if($sAttCode === MetaModel::GetStateAttributeCode($sHostObjectClass)) { $oDateTime = DateTime::createFromFormat(AttributeDateTime::GetInternalFormat(), $oChangeOp->Get('date')); - $sAuthorFriendlyname = $oChangeOp->Get('userinfo'); + + // Retrieve author login + $sAuthorLogin = static::GetUserLoginFromChangeOp($oChangeOp); $sOriginStateLabel = MetaModel::GetStateLabel($sHostObjectClass, $oChangeOp->Get('oldvalue')); $sTargetStateLabel = MetaModel::GetStateLabel($sHostObjectClass, $oChangeOp->Get('newvalue')); - $oEntry = new TransitionEntry($oDateTime, $sAuthorFriendlyname, $sHostObjectClass, $sOriginStateLabel, $sTargetStateLabel); + $oEntry = new TransitionEntry($oDateTime, $sAuthorLogin, $sHostObjectClass, $sOriginStateLabel, $sTargetStateLabel); } else {