From c79d9e6f858d7571ec2573a14f541cac28be4089 Mon Sep 17 00:00:00 2001 From: kdeterme Date: Wed, 9 Sep 2026 22:28:22 +0200 Subject: [PATCH] feat: render system messages with HTML content and update UI styles for orange flag buttons in notifications --- .../notifications/discussion_list.html | 4 ++++ .../templates/notifications/inbox.html | 8 ++++++-- .../templates/notifications/inbox_mobile.html | 8 ++++++-- loko/notifications/tests.py | 20 +++++++++++++++++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/loko/notifications/templates/notifications/discussion_list.html b/loko/notifications/templates/notifications/discussion_list.html index b28ba8b..fd4ce49 100644 --- a/loko/notifications/templates/notifications/discussion_list.html +++ b/loko/notifications/templates/notifications/discussion_list.html @@ -136,8 +136,12 @@ {% if item.last_message %}

+ {% if item.last_message.is_system %} + {{ item.last_message.content|clean_mentions_preview|safe }} + {% else %} {{ item.last_message.author.get_full_name|default:item.last_message.author.username }} : {{ item.last_message.content|clean_mentions_preview|truncatechars:140 }} + {% endif %}

{% else %}

{% translate "Aucun message encore." %}

diff --git a/loko/notifications/templates/notifications/inbox.html b/loko/notifications/templates/notifications/inbox.html index 4b5758d..0356560 100644 --- a/loko/notifications/templates/notifications/inbox.html +++ b/loko/notifications/templates/notifications/inbox.html @@ -370,8 +370,8 @@ {% translate "Important" %} ({{ flag_counts.red|default:"0" }}) - - {% translate "En cours" %} ({{ flag_counts.orange|default:"0" }}) + + {% translate "En cours" %} ({{ flag_counts.orange|default:"0" }}) {% translate "Traité" %} ({{ flag_counts.green|default:"0" }}) @@ -441,8 +441,12 @@ {% if item.last_message %}

+ {% if item.last_message.is_system %} + {{ item.last_message.content|clean_mentions_preview|safe }} + {% else %} {{ item.last_message.author.get_full_name|default:item.last_message.author.username }} : {{ item.last_message.content|clean_mentions_preview|truncatechars:140 }} + {% endif %}

{% else %}

{% translate "Aucun message encore." %}

diff --git a/loko/notifications/templates/notifications/inbox_mobile.html b/loko/notifications/templates/notifications/inbox_mobile.html index 40823a1..1c1d5ca 100644 --- a/loko/notifications/templates/notifications/inbox_mobile.html +++ b/loko/notifications/templates/notifications/inbox_mobile.html @@ -302,8 +302,8 @@
{% translate "Important" %} ({{ flag_counts.red|default:"0" }}) - - {% translate "En cours" %} ({{ flag_counts.orange|default:"0" }}) + + {% translate "En cours" %} ({{ flag_counts.orange|default:"0" }}) {% translate "Traité" %} ({{ flag_counts.green|default:"0" }}) @@ -364,8 +364,12 @@ {% if item.last_message %}

+ {% if item.last_message.is_system %} + {{ item.last_message.content|clean_mentions_preview|safe }} + {% else %} {{ item.last_message.author.get_full_name|default:item.last_message.author.username }} : {{ item.last_message.content|clean_mentions_preview|truncatechars:90 }} + {% endif %}

{% else %}

{% translate "Aucun message encore." %}

diff --git a/loko/notifications/tests.py b/loko/notifications/tests.py index ba720b7..ba5fb16 100644 --- a/loko/notifications/tests.py +++ b/loko/notifications/tests.py @@ -622,9 +622,25 @@ class DiscussionFlagTests(TestCase): self.client.force_login(self.user) from notifications.models import Message Message.objects.create(discussion=self.discussion, author=self.user, content="Hello message") - Message.objects.create(discussion=self.discussion, author=self.user, content="🚩 System flag", is_system=True) + Message.objects.create(discussion=self.discussion, author=self.user, content=" System flag", is_system=True) url = reverse('notifications:discussion_detail', args=[self.discussion.pk]) res = self.client.get(url) self.assertEqual(res.status_code, 200) self.assertContains(res, "Hello message") - self.assertContains(res, "System flag") + self.assertContains(res, "bi-flag-fill text-danger") + + def test_inbox_renders_system_message_flag_icon_safely(self): + self.client.force_login(self.user) + from notifications.models import Message + Message.objects.create( + discussion=self.discussion, + author=self.user, + content=' Alice Smith a défini le statut : Traité / Fait', + is_system=True, + ) + url = reverse('notifications:inbox') + '?tab=discussions' + res = self.client.get(url) + self.assertEqual(res.status_code, 200) + # Icon should NOT be escaped as <i + self.assertNotContains(res, '<i class=') + self.assertContains(res, '')