Skip to content

Commit

Permalink
N'affiche pas de lien vers un commentaire signalé inaccessible sur la…
Browse files Browse the repository at this point in the history
… page des alertes

S'il y avait une alerte sur un contenu dépublié, l'alerte était toujours
listée sur la page des alertes, mais avec un lien vers le commentaire
signalé mal formé, puisqu'il était de la forme
pages/alertes/?page=1&#p123.
  • Loading branch information
philippemilink committed Oct 20, 2024
1 parent 1315206 commit cd4d9c5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
12 changes: 10 additions & 2 deletions templates/pages/alerts.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h1>{% trans "Liste des alertes en cours" %}</h1>
{% elif alert.scope == 'PROFILE' %}
<a href="{{ alert.profile.get_absolute_url }}">{{ alert.text }}</a>
{% else %}
{# This an alert about a comment on something (any kind of content or forum post) #}
<a href="{{ alert.get_comment_subclass.get_absolute_url }}">{{ alert.text }}</a>
{% endif %}
</td>
Expand Down Expand Up @@ -94,9 +95,16 @@ <h1>{% trans "Liste des alertes récemment résolues" %}</h1>
{% elif alert.scope == 'PROFILE' %}
<a href="{{ alert.profile.get_absolute_url }}">{{ alert.text }}</a>
{% else %}
{# This an alert about a comment on something (any kind of content or forum post) #}

{% url "member-detail" alert.comment.author.username as url_member_detail %}
<a href="{{ alert.get_comment_subclass.get_absolute_url }}">{{ alert.text }}</a> par
<a href="{{ url_member_detail }}">{{ alert.comment.author.username }}</a>

{% if alert.is_on_comment_on_unpublished_content %}
<em>{{ alert.text }}</em>
{% else %}
<a href="{{ alert.get_comment_subclass.get_absolute_url }}">{{ alert.text }}</a>
{% endif %}
par <a href="{{ url_member_detail }}">{{ alert.comment.author.username }}</a>
{% endif %}
</td>
<td>
Expand Down
26 changes: 22 additions & 4 deletions zds/tutorialv2/tests/tests_views/tests_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,8 @@ def test_save_no_redirect(self):
def test_remove_unpublished_opinion_with_alerted_comments(self):
"""Test the page showing alerts with an alerted comment on a removed opinion"""

alert_page_url = reverse("pages-alerts")

# 1. Publish opinion
opinion = PublishedContentFactory(type="OPINION", author_list=[self.user_author])

Expand All @@ -2111,7 +2113,14 @@ def test_remove_unpublished_opinion_with_alerted_comments(self):
)
self.assertEqual(result.status_code, 302)

# 4. Unpublish the opinion
# 4. Display the page listing alerts
resp = self.client.get(alert_page_url)
self.assertEqual(200, resp.status_code)
self.assertContains(resp, comment.get_absolute_url()) # We have a link to the alerted comment
self.assertEqual(len(resp.context["alerts"]), 1)
self.assertEqual(len(resp.context["solved"]), 0)

# 5. Unpublish the opinion
result = self.client.post(
reverse("validation:ignore-opinion", kwargs={"pk": opinion.pk, "slug": opinion.slug}),
{
Expand All @@ -2121,12 +2130,21 @@ def test_remove_unpublished_opinion_with_alerted_comments(self):
)
self.assertEqual(result.status_code, 200)

# 5. Remove the opinion
# 6. Display the page listing alerts
resp = self.client.get(alert_page_url)
self.assertEqual(200, resp.status_code)
self.assertNotContains(resp, 'href="?page=1#p') # We don't have wrong links
self.assertEqual(len(resp.context["alerts"]), 0)
self.assertEqual(len(resp.context["solved"]), 1)

# 7. Remove the opinion
self.client.force_login(self.user_author)
result = self.client.post(reverse("content:delete", args=[opinion.pk, opinion.slug]), follow=False)
self.assertEqual(result.status_code, 302)

# 6. Display the page listing alerts
# 8. Display the page listing alerts
self.client.force_login(self.user_staff)
resp = self.client.get(reverse("pages-alerts"))
resp = self.client.get(alert_page_url)
self.assertEqual(200, resp.status_code)
self.assertEqual(len(resp.context["alerts"]), 0)
self.assertEqual(len(resp.context["solved"]), 0)
8 changes: 7 additions & 1 deletion zds/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,10 @@ class Alert(models.Model):
def get_type(self):
if self.scope in TYPE_CHOICES_DICT:
assert self.comment is not None
return _(f"Commentaire sur un {self.SCOPE_CHOICES_DICT[self.scope].lower()}")
if self.is_on_comment_on_unpublished_content():
return _(f"Commentaire sur un {self.SCOPE_CHOICES_DICT[self.scope].lower()} dépublié")
else:
return _(f"Commentaire sur un {self.SCOPE_CHOICES_DICT[self.scope].lower()}")
elif self.scope == "FORUM":
assert self.comment is not None
return _("Message de forum")
Expand All @@ -701,6 +704,9 @@ def get_type(self):
assert self.content is not None
return self.SCOPE_CHOICES_DICT[self.content.type]

def is_on_comment_on_unpublished_content(self):
return self.scope in TYPE_CHOICES_DICT and not self.get_comment_subclass().related_content.in_public()

def is_automated(self):
"""Returns true if this alert was opened automatically."""
return self.author.username == settings.ZDS_APP["member"]["bot_account"]
Expand Down

0 comments on commit cd4d9c5

Please sign in to comment.