Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ConnectionMessage] adds message for missing emails config #2474

Merged
merged 7 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/main/core/Library/RoutingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
84 changes: 69 additions & 15 deletions src/main/core/Listener/PlatformListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -71,14 +75,16 @@ public function __construct(
PlatformConfigurationHandler $config,
VersionManager $versionManager,
TempFileManager $tempManager,
LocaleManager $localeManager
LocaleManager $localeManager,
RoutingHelper $routingHelper,
) {
$this->tokenStorage = $tokenStorage;
$this->translator = $translator;
$this->config = $config;
$this->versionManager = $versionManager;
$this->tempManager = $tempManager;
$this->localeManager = $localeManager;
$this->routingHelper = $routingHelper;
}

/**
Expand Down Expand Up @@ -141,42 +147,48 @@ 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();

$locale = $this->localeManager->getLocale($user);
$content = $this->versionManager->getChangelogs($locale).'<br/>'.'<br/>';
$content .= '<em>'.$this->translator->trans('platform_changelog_display', [
'%roles%' => implode(', ', $this->config->getParameter('changelogMessage.roles')),
'%end_date%' => $endDate->format('d/m/Y'),
], 'platform').'</em>';
'%roles%' => implode(', ', $this->config->getParameter('changelogMessage.roles')),
'%end_date%' => $endDate->format('d/m/Y'),
], 'platform').'</em>';

$event->setResponse([
return [
[
'id' => 'new-version',
'title' => $this->translator->trans('platform_new_available_version', [], 'platform'),
Expand All @@ -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%' => "<a href=\"$editUrl\" target=\"_blank\"><strong>".$this->translator->trans('here', [], 'platform')."</strong></a>"], '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%' => "<a href=\"$editUrl\" target=\"_blank\"><strong>".$this->translator->trans('here', [], 'platform')."</strong></a>"], 'platform'),
'order' => 2,
]],
],
];
}

private function isAdmin()
private function isAdmin(): bool
{
$token = $this->tokenStorage->getToken();
if ($token) {
Expand Down
1 change: 1 addition & 0 deletions src/main/core/Resources/config/services/listener.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 4 additions & 0 deletions src/main/core/Resources/translations/platform.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br>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",
Expand Down Expand Up @@ -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.<br>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",
Expand Down
6 changes: 5 additions & 1 deletion src/main/core/Resources/translations/platform.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br>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",
Expand Down Expand Up @@ -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é.<br>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",
Expand Down