N°4142 - Add config. param. to hide user avatars in the GUIs -mostly in logs- (backoffice, end-users portal, ...)

This commit is contained in:
Molkobain
2021-07-15 17:35:47 +02:00
parent 4843545171
commit dfbbee2a1c
3 changed files with 28 additions and 6 deletions

View File

@@ -1253,6 +1253,14 @@ class Config
'source_of_value' => '',
'show_in_conf_sample' => false,
],
'activity_panel.hide_avatars' => [
'type' => 'array',
'description' => 'GUIs IDs ("backoffice", "itop-portal" for the standard end-users portal, ...) in which the user avatars should be hidden and replaced if possible by their initials (eg. array("backoffice", "itop-portal", "another-portal-id"))',
'default' => [],
'value' => [],
'source_of_value' => '',
'show_in_conf_sample' => false,
],
'activity_panel.show_author_name_below_entries' => [
'type' => 'bool',
'description' => 'Whether or not to show the author friendlyname next to the date on the last entry.',

View File

@@ -577,6 +577,8 @@ HTML
// Caching profile picture url as it is resource consuming
$aContactPicturesCache = array();
$aPeerColorClassCache = array();
// Note: Yes, the config. param. is named after the backoffice element but we hope that we will "soon" have some kind of "light" activity panel in the portal too, so we keep this name.
$bHideContactPicture = in_array(PORTAL_ID, utils::GetConfig()->Get('activity_panel.hide_avatars'));
// Current user
$iCurrentUserId = UserRights::GetUserId();
@@ -590,13 +592,21 @@ HTML
// Retrieve (and cache) profile picture if available (standard datamodel)
// Note: Here the cache is more about nor retrieving the User object several times rather than computing the picture URL
if (!array_key_exists($iEntryUserId, $aContactPicturesCache)) {
$oEntryUser = MetaModel::GetObject('User', $iEntryUserId, false /* Necessary in case user has been deleted */, true);
if(is_null($oEntryUser)) {
// First, check if we should display the picture
if ($bHideContactPicture === true) {
$sEntryContactPictureAbsoluteUrl = null;
}
// Otherwise try to retrieve one for the current contact
else {
$sEntryContactPictureAbsoluteUrl = UserRights::GetUserPictureAbsUrl($oEntryUser->Get('login'), false);
$oEntryUser = MetaModel::GetObject('User', $iEntryUserId, false /* Necessary in case user has been deleted */, true);
if(is_null($oEntryUser)) {
$sEntryContactPictureAbsoluteUrl = null;
}
else {
$sEntryContactPictureAbsoluteUrl = UserRights::GetUserPictureAbsUrl($oEntryUser->Get('login'), false);
}
}
$aContactPicturesCache[$iEntryUserId] = $sEntryContactPictureAbsoluteUrl;
}

View File

@@ -221,9 +221,13 @@ class ActivityEntry extends UIBlock
// - Initials
$this->sAuthorInitials = UserRights::GetUserInitials($this->sAuthorLogin);
// - Picture
$this->sAuthorPictureAbsUrl = UserRights::GetUserPictureAbsUrl($this->sAuthorLogin, false);
if ((null === $this->sAuthorPictureAbsUrl) && (ITOP_APPLICATION_SHORT === $this->sAuthorLogin)) {
$this->sAuthorPictureAbsUrl = utils::GetAbsoluteUrlAppRoot().static::DEFAULT_AUTHOR_PICTURE_REL_URL;
if (in_array('backoffice', utils::GetConfig()->Get('activity_panel.hide_avatars'))) {
$this->sAuthorPictureAbsUrl = null;
} else {
$this->sAuthorPictureAbsUrl = UserRights::GetUserPictureAbsUrl($this->sAuthorLogin, false);
if ((null === $this->sAuthorPictureAbsUrl) && (ITOP_APPLICATION_SHORT === $this->sAuthorLogin)) {
$this->sAuthorPictureAbsUrl = utils::GetAbsoluteUrlAppRoot().static::DEFAULT_AUTHOR_PICTURE_REL_URL;
}
}
$this->bIsFromCurrentUser = UserRights::GetUserId($this->sAuthorLogin) === UserRights::GetUserId();