Skip to content

Commit

Permalink
Removed consent categories for features disabled by the website
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLeChat committed Aug 13, 2024
1 parent 08c1f6c commit b060010
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config/packages/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ parameters:
app.ssl_phrase: "%env(SSL_PHRASE)%"
app.dkim_domain: "%env(DKIM_DOMAIN)%"
app.dkim_selector: "%env(DKIM_SELECTOR)%"
app.analytics_tag: "%env(ANALYTICS_TAG)%"
app.dkim_private_key: "%env(DKIM_PRIVATE_KEY)%"
app.analytics_enabled: "%env(ANALYTICS_ENABLED)%"
app.recaptcha_enabled: "%env(RECAPTCHA_ENABLED)%"
app.recaptcha_private_key: "%env(RECAPTCHA_PRIVATE_KEY)%"
app.google_client_enabled: "%env(GOOGLE_CLIENT_ENABLED)%"
Expand Down
44 changes: 40 additions & 4 deletions src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,47 @@ public function translations(string $language): Response|JsonResponse
return new Response(status: Response::HTTP_NOT_FOUND);
}

// Dans ce cas, on retourne le contenu des traductions en JSON.
return new JsonResponse(
Yaml::parseFile(sprintf("%s/translations/messages.%s.yaml", $this->kernel->getProjectDir(), $language)),
JsonResponse::HTTP_OK
// On charge ensuite le contenu du fichier YAML de traduction
// pour le convertir en tableau associatif.
$translations = Yaml::parseFile(sprintf("%s/translations/messages.%s.yaml", $this->kernel->getProjectDir(), $language));

// On détermine si les services Google reCAPTCHA et Google Analytics
// sont activés pour afficher les sections correspondantes dans les
// consentements des cookies.
$isAnalyticsEnabled = $this->getParameter("app.analytics_enabled") === "true";
$isRecaptchaEnabled = $this->getParameter("app.recaptcha_enabled") === "true";

// On filtre ensuite les sections des préférences des cookies en fonction
// de l'activation des services Google reCAPTCHA et Google Analytics.
$translations["preferencesModal"]["sections"] = array_filter(
$translations["preferencesModal"]["sections"],
function ($section) use ($isAnalyticsEnabled, $isRecaptchaEnabled)
{
// Google Analytics.
$category = $section["linkedCategory"] ?? "";

if ($category === "analytics" && !$isAnalyticsEnabled)
{
return false;
}

// Google reCAPTCHA.
if ($category === "security" && !$isRecaptchaEnabled)
{
return false;
}

// Autres sections.
return true;
}
);

// On effectue par la même occasion une nouvelle indexation des sections
// pour éviter les clés manquantes dans le tableau associatif.
$translations["preferencesModal"]["sections"] = array_values($translations["preferencesModal"]["sections"]);

// On retourne enfin le contenu des traductions au format JSON.
return new JsonResponse($translations, JsonResponse::HTTP_OK);
}

//
Expand Down

0 comments on commit b060010

Please sign in to comment.