diff --git a/itou/templates/stats/stats.html b/itou/templates/stats/stats.html index 31c99b117e..a256e93b92 100644 --- a/itou/templates/stats/stats.html +++ b/itou/templates/stats/stats.html @@ -41,6 +41,24 @@

{{ page_title }}

{% endfor %} + {% if tally_suspension_form %} +
+ +
+
+ +
+
+

+ Ce tableau de bord pourrait disparaître : qu’en pensez-vous ? +

+

+ L’équipe de pilotage de l’inclusion fait le bilan sur l’utilisation des tableaux de bord qui vous sont proposés. Le tableau de bord que vous consultez enregistre peu de connexions de la part nos utilisateurs. En conséquence, nous envisageons de suspendre la mise à disposition de ce tableau de bord à partir d’avril 2025. Si ce tableau de bord vous est utile dans le cadre de vos missions, nous vous invitons à nous le signaler en cliquant ici ! +

+
+
+
+ {% endif %} {% endblock %} {% block content %} diff --git a/itou/utils/apis/metabase.py b/itou/utils/apis/metabase.py index 74c2a73d00..c12c10f238 100644 --- a/itou/utils/apis/metabase.py +++ b/itou/utils/apis/metabase.py @@ -304,6 +304,9 @@ } +SUSPENDED_DASHBOARD_IDS = [357, 389, 162, 298, 168] + + # Metabase private / signed URLs # See: # * https://www.metabase.com/docs/latest/enterprise-guide/full-app-embedding.html diff --git a/itou/www/stats/views.py b/itou/www/stats/views.py index 06fd8b6cb8..78cdcd8027 100644 --- a/itou/www/stats/views.py +++ b/itou/www/stats/views.py @@ -111,11 +111,15 @@ def render_stats(request, context, params=None, template_name="stats/stats.html" params = {} view_name = mb.get_view_name(request) metabase_dashboard = mb.METABASE_DASHBOARDS.get(view_name) + dashboard_id = metabase_dashboard["dashboard_id"] tally_popup_form_id = None tally_embed_form_id = None if settings.TALLY_URL and metabase_dashboard: tally_popup_form_id = metabase_dashboard.get("tally_popup_form_id") tally_embed_form_id = metabase_dashboard.get("tally_embed_form_id") + tally_suspension_form = ( + f"https://tally.so/r/wkOxRR?URLTB={dashboard_id}" if dashboard_id in mb.SUSPENDED_DASHBOARD_IDS else None + ) base_context = { "back_url": None, @@ -126,6 +130,7 @@ def render_stats(request, context, params=None, template_name="stats/stats.html" "tally_popup_form_id": tally_popup_form_id, "tally_embed_form_id": tally_embed_form_id, "PILOTAGE_HELP_CENTER_URL": global_constants.PILOTAGE_HELP_CENTER_URL, + "tally_suspension_form": tally_suspension_form, } # Key value pairs in context override preexisting pairs in base_context. diff --git a/tests/www/stats/test_views.py b/tests/www/stats/test_views.py index 1f9767b70b..f0918e26f7 100644 --- a/tests/www/stats/test_views.py +++ b/tests/www/stats/test_views.py @@ -1,11 +1,12 @@ from datetime import UTC, datetime +from unittest.mock import patch import factory import pytest from django.test import override_settings from django.urls import reverse from freezegun import freeze_time -from pytest_django.asserts import assertQuerySetEqual, assertRedirects +from pytest_django.asserts import assertContains, assertNotContains, assertQuerySetEqual, assertRedirects from itou.analytics.models import StatsDashboardVisit from itou.common_apps.address.departments import DEPARTMENT_TO_REGION @@ -422,9 +423,10 @@ def test_stats_staff(client, view_name): @override_settings(METABASE_SITE_URL="http://metabase.fake", METABASE_SECRET_KEY="foobar") def test_webinar_banner_display(client, snapshot): client.force_login(ItouStaffFactory()) + url = reverse("stats:stats_staff_service_indicators") with override_settings(PILOTAGE_SHOW_STATS_WEBINAR=True): - response = client.get(reverse("stats:stats_staff_service_indicators")) + response = client.get(url) assert response.status_code == 200 rendered_banners = [ banner | {"is_displayable": True} for banner in response.context["pilotage_webinar_banners"] @@ -432,11 +434,29 @@ def test_webinar_banner_display(client, snapshot): assert str(rendered_banners) == snapshot with override_settings(PILOTAGE_SHOW_STATS_WEBINAR=False): - response = client.get(reverse("stats:stats_staff_service_indicators")) + response = client.get(url) assert response.status_code == 200 assert response.context["pilotage_webinar_banners"] == [] +@override_settings(METABASE_SITE_URL="http://metabase.fake", METABASE_SECRET_KEY="foobar") +def test_suspended_stats_page_banner(client, snapshot): + """Test a banner appears for the user when a dashboard is marked as suspended""" + client.force_login(ItouStaffFactory()) + staff_dashboard_id = METABASE_DASHBOARDS.get("stats_staff_service_indicators")["dashboard_id"] + tally_suspension_form = f"https://tally.so/r/wkOxRR?URLTB={staff_dashboard_id}" + + with patch("itou.utils.apis.metabase.SUSPENDED_DASHBOARD_IDS", [staff_dashboard_id]): + response = client.get(reverse("stats:stats_staff_service_indicators")) + assert response.status_code == 200 + assertContains(response, tally_suspension_form) + + with patch("itou.utils.apis.metabase.SUSPENDED_DASHBOARD_IDS", []): + response = client.get(reverse("stats:stats_staff_service_indicators")) + assert response.status_code == 200 + assertNotContains(response, tally_suspension_form) + + def test_get_params_aci_asp_ids_for_department(): company = CompanyFactory(kind=CompanyKind.ACI, department=factory.fuzzy.FuzzyChoice([31, 84])) assert get_params_aci_asp_ids_for_department(company.department) == {