From b08b5297cfac5f193cd40694a7fe742ef7123914 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Mon, 11 Mar 2024 21:57:37 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B07122=20N=C2=B04164=20-=20Adjustment=20to?= =?UTF-8?q?=20Symfony=205.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../portal/src/EventListener/UserProvider.php | 13 ++++++++++++- .../portal/src/Twig/CurrentUserAccessor.php | 9 +++++++++ .../portal/templates/layout.html.twig | 13 +++---------- 3 files changed, 24 insertions(+), 11 deletions(-) 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 5499dec4b..0eea210ff 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 @@ -47,6 +47,8 @@ class UserProvider implements ContainerAwareInterface private $oContainer; /** @var \User $oUser */ private $oUser; + /** @var bool $bUserCanLogOff Whether the current user can log off or not */ + private $bUserCanLogOff; /** @var array $aAllowedPortals */ private $aAllowedPortals; @@ -93,7 +95,7 @@ class UserProvider implements ContainerAwareInterface } // User allowed to log off or not - $this->oContainer->set('combodo.current_user.can_logoff', utils::CanLogOff()); + $this->bUserCanLogOff = utils::CanLogOff(); // Allowed portals $aAllowedPortals = UserRights::GetAllowedPortals(); @@ -125,6 +127,15 @@ class UserProvider implements ContainerAwareInterface 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 03a2ec48e..0263ebfff 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,7 +3,7 @@ {% if app['combodo.current_user'] is defined and app['combodo.current_user'] is not null %} {% set bUserConnected = true %} - {% set bUserCanLogOff = app['combodo.current_user.can_logoff'] %} + {% 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'] %} @@ -129,15 +129,13 @@ {# - Hilighter for code snippets created with CKEditor #} - {# - Custom settings #} - {# Date-time picker for Bootstrap #} {# Typeahead files for autocomplete #} - + {# Selectize for sets #} @@ -545,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 %} });