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

Pilotage: Ajouter un bandeau sur les tableaux de bord en sursis #5392

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions itou/templates/stats/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ <h1>{{ page_title }}</h1>
</div>
</div>
{% endfor %}
{% if tally_suspension_form %}
<div class="alert alert-info alert-dismissible fade show" role="status">
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Fermer"></button>
<div class="row">
<div class="col-auto pe-0">
<i class="ri-information-line ri-xl text-info" aria-hidden="true"></i>
</div>
<div class="col">
<p class="mb-2">
<strong>Ce tableau de bord pourrait disparaître : qu’en pensez-vous ?</strong>
</p>
<p class="mb-0">
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 <a href="{{ tally_suspension_form }}" target="_blank" rel="noopener">ici</a> !
</p>
</div>
</div>
</div>
{% endif %}
{% endblock %}

{% block content %}
Expand Down
3 changes: 3 additions & 0 deletions itou/utils/apis/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions itou/www/stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
26 changes: 23 additions & 3 deletions tests/www/stats/test_views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -422,21 +423,40 @@ 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"]
]
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) == {
Expand Down
Loading