mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
N°2847 - ActivityPanel: Fix entry's author info for CMDBChangeOp
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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 <guillaume.lajarige@combodo.com>
|
||||
* @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;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user