From 09ccde9d114e82c0411c495a835dbcd8429b7ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9becca=20Tinchon?= Date: Tue, 9 May 2023 15:11:22 +0200 Subject: [PATCH 1/6] connection message if DPO email or support email is not set --- src/main/core/Listener/PlatformListener.php | 84 +++++++++++++++---- .../Resources/config/services/listener.yml | 1 + .../Resources/translations/platform.en.json | 4 + .../Resources/translations/platform.fr.json | 6 +- 4 files changed, 79 insertions(+), 16 deletions(-) diff --git a/src/main/core/Listener/PlatformListener.php b/src/main/core/Listener/PlatformListener.php index 3f7a3f113dc..81248874d18 100644 --- a/src/main/core/Listener/PlatformListener.php +++ b/src/main/core/Listener/PlatformListener.php @@ -17,6 +17,7 @@ use Claroline\CoreBundle\Library\Configuration\PlatformConfigurationHandler; use Claroline\CoreBundle\Library\Maintenance\MaintenanceHandler; use Claroline\CoreBundle\Library\Normalizer\DateNormalizer; +use Claroline\CoreBundle\Library\RoutingHelper; use Claroline\CoreBundle\Manager\LocaleManager; use Claroline\CoreBundle\Manager\VersionManager; use Claroline\CoreBundle\Security\PlatformRoles; @@ -44,6 +45,9 @@ class PlatformListener /** @var LocaleManager */ private $localeManager; + /** @var RoutingHelper */ + private $routingHelper; + /** * The list of public routes of the application. * NB. This is not the best place to declare it. @@ -71,7 +75,8 @@ public function __construct( PlatformConfigurationHandler $config, VersionManager $versionManager, TempFileManager $tempManager, - LocaleManager $localeManager + LocaleManager $localeManager, + RoutingHelper $routingHelper, ) { $this->tokenStorage = $tokenStorage; $this->translator = $translator; @@ -79,6 +84,7 @@ public function __construct( $this->versionManager = $versionManager; $this->tempManager = $tempManager; $this->localeManager = $localeManager; + $this->routingHelper = $routingHelper; } /** @@ -141,30 +147,36 @@ public function clearTemp() /** * Display new version changelogs to administrators. */ - public function displayVersionChangeLogs(GenericDataEvent $event) + public function displayVersionChangeLogs(GenericDataEvent $event): void + { + $event->setResponse(array_merge( + $this->getChangelogs(), + $this->getDPOMessages(), + $this->getSupportMessages(), + )); + } + + private function getChangelogs(): array { if (!$this->config->getParameter('changelogMessage.enabled')) { - // connection message is disabled, nothing to do - return; + return []; } $roles = $this->config->getParameter('changelogMessage.roles'); if (empty(array_intersect($this->tokenStorage->getToken()->getRoleNames(), $roles))) { - // current user cannot see the changelog with its current roles - return; + return []; } - // check if we still are in the display period $installationDate = $this->versionManager->getInstallationDate($this->versionManager->getCurrentMinor()); if (empty($installationDate)) { - return; + return []; } $period = new \DateInterval($this->config->getParameter('changelogMessage.duration')); $endDate = $installationDate->add($period); $now = new \DateTime(); if ($now > $endDate) { - return; + return []; } $user = $this->tokenStorage->getToken()->getUser(); @@ -172,11 +184,11 @@ public function displayVersionChangeLogs(GenericDataEvent $event) $locale = $this->localeManager->getLocale($user); $content = $this->versionManager->getChangelogs($locale).'
'.'
'; $content .= ''.$this->translator->trans('platform_changelog_display', [ - '%roles%' => implode(', ', $this->config->getParameter('changelogMessage.roles')), - '%end_date%' => $endDate->format('d/m/Y'), - ], 'platform').''; + '%roles%' => implode(', ', $this->config->getParameter('changelogMessage.roles')), + '%end_date%' => $endDate->format('d/m/Y'), + ], 'platform').''; - $event->setResponse([ + return [ [ 'id' => 'new-version', 'title' => $this->translator->trans('platform_new_available_version', [], 'platform'), @@ -188,10 +200,52 @@ public function displayVersionChangeLogs(GenericDataEvent $event) 'order' => 0, ]], ], - ]); + ]; + } + + private function getDPOMessages(): array + { + if (!$this->isAdmin() || $this->config->getParameter('privacy.dpo.email')) { + return []; + } + $editUrl = $this->routingHelper->indexPath().'#/admin/main_settings/privacy'; + return [ + [ + 'id' => 'dpo-email-missing', + 'title' => $this->translator->trans('dpo_email_missing_title', [], 'platform'), + 'type' => ConnectionMessage::TYPE_ALWAYS, + 'slides' => [[ + 'id' => 'dpo-email-missing-message', + 'title' => $this->translator->trans('dpo_email_missing_title', [], 'platform'), + 'content' => $this->translator->trans('dpo_email_missing_content', ['%link%' => "".$this->translator->trans('here', [], 'platform').""], 'platform'), + 'order' => 1, + ]], + ], + ]; + } + + private function getSupportMessages(): array + { + if (!$this->isAdmin() || $this->config->getParameter('help.support_email')) { + return []; + } + $editUrl = $this->routingHelper->indexPath() . '#/admin/main_settings'; + return [ + [ + 'id' => 'support-email-missing', + 'title' => $this->translator->trans('support_email_missing_title', [], 'platform'), + 'type' => ConnectionMessage::TYPE_ALWAYS, + 'slides' => [[ + 'id' => 'support-email-missing-message', + 'title' => $this->translator->trans('support_email_missing_title', [], 'platform'), + 'content' => $this->translator->trans('support_email_missing_content', ['%link%' => "".$this->translator->trans('here', [], 'platform').""], 'platform'), + 'order' => 2, + ]], + ], + ]; } - private function isAdmin() + private function isAdmin(): bool { $token = $this->tokenStorage->getToken(); if ($token) { diff --git a/src/main/core/Resources/config/services/listener.yml b/src/main/core/Resources/config/services/listener.yml index 13abb74e0dd..03612bde3ad 100644 --- a/src/main/core/Resources/config/services/listener.yml +++ b/src/main/core/Resources/config/services/listener.yml @@ -155,6 +155,7 @@ services: - '@Claroline\CoreBundle\Manager\VersionManager' - '@Claroline\AppBundle\Manager\File\TempFileManager' - '@Claroline\CoreBundle\Manager\LocaleManager' + - '@Claroline\CoreBundle\Library\RoutingHelper' tags: - { name: kernel.event_listener, event: kernel.request, method: setLocale, priority: 17 } - { name: kernel.event_listener, event: kernel.request, method: checkAvailability } diff --git a/src/main/core/Resources/translations/platform.en.json b/src/main/core/Resources/translations/platform.en.json index db4f05d9584..d18c1f9ecd0 100644 --- a/src/main/core/Resources/translations/platform.en.json +++ b/src/main/core/Resources/translations/platform.en.json @@ -162,6 +162,8 @@ "domain_name": "Domain name", "down": "Down", "download": "Download", + "dpo_email_missing_title": "Data Protection Officer (DPO) email address is missing", + "dpo_email_missing_content": "Data Protection Officer (DPO) email is not set.
Please set it up by clicking %link%, in Privacy -> Data Protection Officer.", "drag_file_here": "Drag the file here", "drop_file": "Drop the file", "duration": "Duration", @@ -595,6 +597,8 @@ "street_number": "Street number", "subject": "Subject", "support_email": "Support email", + "support_email_missing_title": "Support email missing", + "support_email_missing_content": "The support email is missing.
Please set it up by clicking %link%, in general information, support section -> support email.", "switch": "Switch", "switch_to_admin_tabs": "Switch to admin tabs", "switch_to_user_tabs": "Switch to personal tabs", diff --git a/src/main/core/Resources/translations/platform.fr.json b/src/main/core/Resources/translations/platform.fr.json index a86ea897a65..65676f467a1 100644 --- a/src/main/core/Resources/translations/platform.fr.json +++ b/src/main/core/Resources/translations/platform.fr.json @@ -168,6 +168,8 @@ "domain_name": "Nom de domaine", "down": "Descendre", "download": "Télécharger", + "dpo_email_missing_title": "Adresse e-mail du DPO manquante", + "dpo_email_missing_content": "L'adresse e-mail du DPO n'est pas renseignée.
Veuillez la configurer en cliquant %link%, rubrique Vie privée -> Délégué à la protection des données.", "drag_file_here": "Déplacez le fichier ici", "drop_file": "Déposez le fichier", "duration": "Durée", @@ -613,9 +615,11 @@ "subject": "Sujet", "success": "Succès", "support_email": "Courriel du support", + "support_email_missing_title": "Le courriel du support manquant", + "support_email_missing_content": "Le courriel du support n'a pas été renseigné.
Veuillez le configurer en cliquant %link%, dans informations générales, rubrique assistance -> courriel du support.", "switch": "Echanger", "switch_to_admin_tabs": "Basculer vers les onglets communs", - "switch_to_user_tabs": "Basculer vers les onglers personnels", + "switch_to_user_tabs": "Basculer vers les onglets personnels", "tab": "Onglet", "tab_position": "Position de l'onglet", "tabs": "Onglets", From fc6134c0826b060bdcf8e35fe71e50578476c868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9becca=20Tinchon?= Date: Tue, 9 May 2023 15:15:04 +0200 Subject: [PATCH 2/6] typing RoutingHelper --- src/main/core/Library/RoutingHelper.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/core/Library/RoutingHelper.php b/src/main/core/Library/RoutingHelper.php index e89f0391d42..dd83f7c9c69 100644 --- a/src/main/core/Library/RoutingHelper.php +++ b/src/main/core/Library/RoutingHelper.php @@ -9,44 +9,44 @@ class RoutingHelper { - private $router; + private RouterInterface $router; public function __construct(RouterInterface $router) { $this->router = $router; } - public function indexUrl() + public function indexUrl(): string { return $this->router->generate('claro_index', [], UrlGeneratorInterface::ABSOLUTE_URL); } - public function indexPath() + public function indexPath(): string { return $this->router->generate('claro_index'); } - public function desktopUrl($toolName = null) + public function desktopUrl($toolName = null): string { return $this->indexUrl().'#/desktop/'.$toolName; } - public function desktopPath($toolName = null) + public function desktopPath($toolName = null): string { return $this->indexPath().'#/desktop/'.$toolName; } - public function resourceUrl($resource) + public function resourceUrl($resource): string { return $this->indexUrl().'#'.$this->resourceFragment($resource); } - public function resourcePath($resource) + public function resourcePath($resource): string { return $this->indexPath().'#'.$this->resourceFragment($resource); } - public function resourceFragment($resource) + public function resourceFragment($resource): string { $slug = null; $wsSlug = null; @@ -75,17 +75,17 @@ public function resourceFragment($resource) } } - public function workspaceUrl($workspace, $toolName = null) + public function workspaceUrl($workspace, $toolName = null): string { return $this->indexUrl().'#'.$this->workspaceFragment($workspace, $toolName); } - public function workspacePath($workspace, $toolName = null) + public function workspacePath($workspace, $toolName = null): string { return $this->indexPath().'#'.$this->workspaceFragment($workspace, $toolName); } - public function workspaceFragment($workspace, $toolName = null) + public function workspaceFragment($workspace, $toolName = null): string { $slug = null; if ($workspace instanceof Workspace) { From a24fe0717acafc8353123015a4ad4bbd2dfbc9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9becca=20Tinchon?= Date: Wed, 10 May 2023 09:59:14 +0200 Subject: [PATCH 3/6] Added 2 utilities adminPath and adminUrl and typing for method params in RoutingHelper. --- src/main/core/Library/RoutingHelper.php | 26 ++++++++++++++------- src/main/core/Listener/PlatformListener.php | 4 ++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/core/Library/RoutingHelper.php b/src/main/core/Library/RoutingHelper.php index dd83f7c9c69..00eb25e6460 100644 --- a/src/main/core/Library/RoutingHelper.php +++ b/src/main/core/Library/RoutingHelper.php @@ -26,27 +26,37 @@ public function indexPath(): string return $this->router->generate('claro_index'); } - public function desktopUrl($toolName = null): string + public function desktopUrl(string $toolName = null): string { return $this->indexUrl().'#/desktop/'.$toolName; } - public function desktopPath($toolName = null): string + public function desktopPath(string $toolName = null): string { return $this->indexPath().'#/desktop/'.$toolName; } - public function resourceUrl($resource): string + public function resourceUrl(ResourceNode|array|string $resource): string { return $this->indexUrl().'#'.$this->resourceFragment($resource); } - public function resourcePath($resource): string + public function resourcePath(ResourceNode|array|string $resource): string { return $this->indexPath().'#'.$this->resourceFragment($resource); } - public function resourceFragment($resource): string + public function adminUrl(string $adminToolName = null): string + { + return $this->indexUrl().'#/admin/'.$adminToolName; + } + + public function adminPath(string $adminToolName = null): string + { + return $this->indexPath().'#/admin/'.$adminToolName; + } + + public function resourceFragment(ResourceNode|array|string $resource): string { $slug = null; $wsSlug = null; @@ -75,17 +85,17 @@ public function resourceFragment($resource): string } } - public function workspaceUrl($workspace, $toolName = null): string + public function workspaceUrl(Workspace|array|string $workspace, string $toolName = null): string { return $this->indexUrl().'#'.$this->workspaceFragment($workspace, $toolName); } - public function workspacePath($workspace, $toolName = null): string + public function workspacePath(Workspace|array|string $workspace, string $toolName = null): string { return $this->indexPath().'#'.$this->workspaceFragment($workspace, $toolName); } - public function workspaceFragment($workspace, $toolName = null): string + public function workspaceFragment(Workspace|array|string $workspace, string $toolName = null): string { $slug = null; if ($workspace instanceof Workspace) { diff --git a/src/main/core/Listener/PlatformListener.php b/src/main/core/Listener/PlatformListener.php index 81248874d18..3a190d02073 100644 --- a/src/main/core/Listener/PlatformListener.php +++ b/src/main/core/Listener/PlatformListener.php @@ -208,7 +208,7 @@ private function getDPOMessages(): array if (!$this->isAdmin() || $this->config->getParameter('privacy.dpo.email')) { return []; } - $editUrl = $this->routingHelper->indexPath().'#/admin/main_settings/privacy'; + $editUrl = $this->routingHelper->adminPath('main_settings/privacy'); return [ [ 'id' => 'dpo-email-missing', @@ -229,7 +229,7 @@ private function getSupportMessages(): array if (!$this->isAdmin() || $this->config->getParameter('help.support_email')) { return []; } - $editUrl = $this->routingHelper->indexPath() . '#/admin/main_settings'; + $editUrl = $this->routingHelper->adminPath('main_settings'); return [ [ 'id' => 'support-email-missing', From 3976059a5c4616633d545b82e197a6fd19e1964d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9becca=20Tinchon?= Date: Wed, 10 May 2023 10:16:57 +0200 Subject: [PATCH 4/6] PHP CS Fixer changes --- src/main/core/Listener/PlatformListener.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/core/Listener/PlatformListener.php b/src/main/core/Listener/PlatformListener.php index 3a190d02073..d24a8792e40 100644 --- a/src/main/core/Listener/PlatformListener.php +++ b/src/main/core/Listener/PlatformListener.php @@ -208,7 +208,9 @@ private function getDPOMessages(): array if (!$this->isAdmin() || $this->config->getParameter('privacy.dpo.email')) { return []; } + $editUrl = $this->routingHelper->adminPath('main_settings/privacy'); + return [ [ 'id' => 'dpo-email-missing', @@ -217,7 +219,7 @@ private function getDPOMessages(): array 'slides' => [[ 'id' => 'dpo-email-missing-message', 'title' => $this->translator->trans('dpo_email_missing_title', [], 'platform'), - 'content' => $this->translator->trans('dpo_email_missing_content', ['%link%' => "".$this->translator->trans('here', [], 'platform').""], 'platform'), + 'content' => $this->translator->trans('dpo_email_missing_content', ['%link%' => '' . $this->translator->trans('here', [], 'platform') . ''], 'platform'), 'order' => 1, ]], ], @@ -229,7 +231,9 @@ private function getSupportMessages(): array if (!$this->isAdmin() || $this->config->getParameter('help.support_email')) { return []; } + $editUrl = $this->routingHelper->adminPath('main_settings'); + return [ [ 'id' => 'support-email-missing', @@ -238,7 +242,7 @@ private function getSupportMessages(): array 'slides' => [[ 'id' => 'support-email-missing-message', 'title' => $this->translator->trans('support_email_missing_title', [], 'platform'), - 'content' => $this->translator->trans('support_email_missing_content', ['%link%' => "".$this->translator->trans('here', [], 'platform').""], 'platform'), + 'content' => $this->translator->trans('support_email_missing_content', ['%link%' => '' . $this->translator->trans('here', [], 'platform') . ''], 'platform'), 'order' => 2, ]], ], From 7d5980a16aaf1ab387273cb5902aafba0c65b7a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9becca=20Tinchon?= Date: Wed, 10 May 2023 10:28:27 +0200 Subject: [PATCH 5/6] add '?' optional parameter --- src/main/core/Library/RoutingHelper.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/core/Library/RoutingHelper.php b/src/main/core/Library/RoutingHelper.php index 00eb25e6460..e7a9fc82112 100644 --- a/src/main/core/Library/RoutingHelper.php +++ b/src/main/core/Library/RoutingHelper.php @@ -26,12 +26,12 @@ public function indexPath(): string return $this->router->generate('claro_index'); } - public function desktopUrl(string $toolName = null): string + public function desktopUrl(?string $toolName = null): string { return $this->indexUrl().'#/desktop/'.$toolName; } - public function desktopPath(string $toolName = null): string + public function desktopPath(?string $toolName = null): string { return $this->indexPath().'#/desktop/'.$toolName; } @@ -46,12 +46,12 @@ public function resourcePath(ResourceNode|array|string $resource): string return $this->indexPath().'#'.$this->resourceFragment($resource); } - public function adminUrl(string $adminToolName = null): string + public function adminUrl(?string $adminToolName = null): string { return $this->indexUrl().'#/admin/'.$adminToolName; } - public function adminPath(string $adminToolName = null): string + public function adminPath(?string $adminToolName = null): string { return $this->indexPath().'#/admin/'.$adminToolName; } @@ -85,17 +85,17 @@ public function resourceFragment(ResourceNode|array|string $resource): string } } - public function workspaceUrl(Workspace|array|string $workspace, string $toolName = null): string + public function workspaceUrl(Workspace|array|string $workspace, ?string $toolName = null): string { return $this->indexUrl().'#'.$this->workspaceFragment($workspace, $toolName); } - public function workspacePath(Workspace|array|string $workspace, string $toolName = null): string + public function workspacePath(Workspace|array|string $workspace, ?string $toolName = null): string { return $this->indexPath().'#'.$this->workspaceFragment($workspace, $toolName); } - public function workspaceFragment(Workspace|array|string $workspace, string $toolName = null): string + public function workspaceFragment(Workspace|array|string $workspace, ?string $toolName = null): string { $slug = null; if ($workspace instanceof Workspace) { From a71ff9f5ea43d2dcca2879cef60d91d3fc7e9cfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9becca=20Tinchon?= Date: Wed, 10 May 2023 10:34:34 +0200 Subject: [PATCH 6/6] error fixed --- src/main/core/Listener/PlatformListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/core/Listener/PlatformListener.php b/src/main/core/Listener/PlatformListener.php index 85e393cb7ab..94abd828793 100644 --- a/src/main/core/Listener/PlatformListener.php +++ b/src/main/core/Listener/PlatformListener.php @@ -219,7 +219,7 @@ private function getDPOMessages(): array 'slides' => [[ 'id' => 'dpo-email-missing-message', 'title' => $this->translator->trans('dpo_email_missing_title', [], 'platform'), - 'content' => $this->translator->trans('dpo_email_missing_content', ['%link%' => '' . $this->translator->trans('here', [], 'platform') . ''], 'platform'), + 'content' => $this->translator->trans('dpo_email_missing_content', ['%link%' => ''.$this->translator->trans('here', [], 'platform').''], 'platform'), 'order' => 1, ]], ], @@ -242,7 +242,7 @@ private function getSupportMessages(): array 'slides' => [[ 'id' => 'support-email-missing-message', 'title' => $this->translator->trans('support_email_missing_title', [], 'platform'), - 'content' => $this->translator->trans('support_email_missing_content', ['%link%' => '' . $this->translator->trans('here', [], 'platform') . ''], 'platform'), + 'content' => $this->translator->trans('support_email_missing_content', ['%link%' => ''.$this->translator->trans('here', [], 'platform').''], 'platform'), 'order' => 2, ]], ],