diff --git a/datamodels/2.x/itop-portal-base/portal/src/EventListener/UserProvider.php b/datamodels/2.x/itop-portal-base/portal/src/EventListener/UserProvider.php index 12da61a33..68ef3c2ff 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/EventListener/UserProvider.php +++ b/datamodels/2.x/itop-portal-base/portal/src/EventListener/UserProvider.php @@ -29,6 +29,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Exception\HttpException; use UserRights; +use utils; /** * Class UserProvider @@ -44,6 +45,8 @@ class UserProvider private $sPortalId; /** @var \User $oUser */ private $oUser; + /** @var bool $bUserCanLogOff Whether the current user can log off or not */ + private $bUserCanLogOff; /** @var array $aAllowedPortals */ private $aAllowedPortals; @@ -89,6 +92,9 @@ class UserProvider throw new Exception('Could not load connected user.'); } + // User allowed to log off or not + $this->bUserCanLogOff = utils::CanLogOff(); + // Allowed portals $aAllowedPortals = UserRights::GetAllowedPortals(); @@ -119,6 +125,15 @@ class UserProvider return $this->oUser; } + /** + * @return bool {@see static::$bUserCanLogOff} + * @since 3.1.2 3.2.0 + */ + public function getCurrentUserCanLogOff(): bool + { + return $this->bUserCanLogOff; + } + /** * Get allowed portals. * diff --git a/datamodels/2.x/itop-portal-base/portal/src/Twig/CurrentUserAccessor.php b/datamodels/2.x/itop-portal-base/portal/src/Twig/CurrentUserAccessor.php index d9778da35..b1b94b9af 100644 --- a/datamodels/2.x/itop-portal-base/portal/src/Twig/CurrentUserAccessor.php +++ b/datamodels/2.x/itop-portal-base/portal/src/Twig/CurrentUserAccessor.php @@ -61,4 +61,13 @@ class CurrentUserAccessor { return $this->userProvider->getCurrentUser()->Get($key); } + + /** + * @return bool + * @since 3.1.2 3.2.0 + */ + public function CanLogOff(): bool + { + return $this->userProvider->getCurrentUserCanLogOff(); + } } \ No newline at end of file diff --git a/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig b/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig index 002258658..0646a2a1b 100644 --- a/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig +++ b/datamodels/2.x/itop-portal-base/portal/templates/layout.html.twig @@ -3,11 +3,13 @@ {% if app['combodo.current_user'] is defined and app['combodo.current_user'] is not null %} {% set bUserConnected = true %} + {% set bUserCanLogOff = app['combodo.current_user'].CanLogOff() %} {% set sUserFullname = app['combodo.current_user'].Get('first_name') ~ ' ' ~ app['combodo.current_user'].Get('last_name') %} {% set sUserEmail = app['combodo.current_user'].Get('email') %} {% set sUserPhotoUrl = app['combodo.current_contact.photo_url'] %} {% else %} {% set bUserConnected = false %} + {% set bUserCanLogOff = false %} {% set sUserFullname = '' %} {% set sUserEmail = '' %} {% set sUserPhotoUrl = app['combodo.portal.base.absolute_url'] ~ 'img/user-profile-default-256px.png' %} @@ -127,15 +129,13 @@ {# - Hilighter for code snippets created with CKEditor #} - {# - Custom settings #} - {# Date-time picker for Bootstrap #} {# Typeahead files for autocomplete #} - + {# Selectize for sets #} @@ -232,11 +232,13 @@
  • {{ aPortal.label|dict_s }}
  • {% endif %} {% endfor %} - {# We display the separator only if the user has more then 1 portal. Meaning default portal + console or several portal at least #} - {% if allowed_portals|length > 1 %} - - {% endif %} -
  • {{ 'Brick:Portal:UserProfile:Navigation:Dropdown:Logout'|dict_s }}
  • + {% if bUserCanLogOff %} + {# We display the separator only if the user has more then 1 portal. Meaning default portal + console or several portal at least #} + {% if allowed_portals|length > 1 %} + + {% endif %} +
  • {{ 'Brick:Portal:UserProfile:Navigation:Dropdown:Logout'|dict_s }}
  • + {% endif %} {% endif %} @@ -271,11 +273,13 @@
  • {{ aPortal.label|dict_s }}
  • {% endif %} {% endfor %} - {# We display the separator only if the user has more then 1 portal. Meaning default portal + console or several portal at least #} - {% if allowed_portals|length > 1 %} - - {% endif %} -
  • {{ 'Brick:Portal:UserProfile:Navigation:Dropdown:Logout'|dict_s }}
  • + {% if bUserCanLogOff %} + {# We display the separator only if the user has more then 1 portal. Meaning default portal + console or several portal at least #} + {% if allowed_portals|length > 1 %} + + {% endif %} +
  • {{ 'Brick:Portal:UserProfile:Navigation:Dropdown:Logout'|dict_s }}
  • + {% endif %} @@ -539,12 +543,7 @@ }); // Initialize confirmation message handler when a form with touched fields is closed - oBodyElem.leave_handler({ - 'message': '{{ 'Portal:Form:Close:Warning'|dict_s }}', - 'extra_events': { - 'body': ['hide.bs.modal'] - } - }); + oBodyElem.portal_leave_handler({'message': '{{ 'Portal:Form:Close:Warning'|dict_s }}'}); {% endblock %} });