From c8f76e82d0963db4fcd547ea56a4843f4d06ca03 Mon Sep 17 00:00:00 2001
From: Arnaud-D <35631001+Arnaud-D@users.noreply.github.com>
Date: Sat, 20 Jul 2024 15:21:45 +0200
Subject: [PATCH] =?UTF-8?q?Ajoute=20l'inscription=20dans=20le=20journal=20?=
=?UTF-8?q?d'=C3=A9v=C3=A9nement?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
templates/tutorialv2/events/descriptions.part.html | 3 +++
zds/tutorialv2/models/events.py | 11 +++++++++++
zds/tutorialv2/signals.py | 4 ++++
.../tests/tests_views/tests_editthumbnailview.py | 5 ++++-
zds/tutorialv2/views/thumbnail.py | 4 ++++
5 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/templates/tutorialv2/events/descriptions.part.html b/templates/tutorialv2/events/descriptions.part.html
index 360720290a..af203e3430 100644
--- a/templates/tutorialv2/events/descriptions.part.html
+++ b/templates/tutorialv2/events/descriptions.part.html
@@ -57,6 +57,9 @@
{% endif %}
+{% elif event.type == "thumbnail_management" %}
+ {{ event.performer }} a modifié la miniature du contenu.
+
{% elif event.type == "tags_management" %}
{{ event.performer }} a modifié les tags du contenu.
diff --git a/zds/tutorialv2/models/events.py b/zds/tutorialv2/models/events.py
index 0cfa001bc8..8617d105c1 100644
--- a/zds/tutorialv2/models/events.py
+++ b/zds/tutorialv2/models/events.py
@@ -13,6 +13,7 @@
from zds.tutorialv2.views.goals import EditGoals
from zds.tutorialv2.views.labels import EditLabels
from zds.tutorialv2.views.help import ChangeHelp
+from zds.tutorialv2.views.thumbnail import EditThumbnailView
from zds.tutorialv2.views.validations_contents import (
ReserveValidation,
AskValidationForContent,
@@ -48,6 +49,7 @@
signals.contributors_management: "contributors_management",
signals.beta_management: "beta_management",
signals.validation_management: "validation_management",
+ signals.thumbnail_management: "thumbnail_management",
signals.tags_management: "tags_management",
signals.canonical_link_management: "canonical_link_management",
signals.goals_management: "goals_management",
@@ -135,6 +137,15 @@ def record_event_validation_management(sender, performer, signal, content, versi
).save()
+@receiver(signals.thumbnail_management, sender=EditThumbnailView)
+def record_event_thumbnail_management(sender, performer, signal, content, **_):
+ Event.objects.create(
+ performer=performer,
+ type=types[signal],
+ content=content,
+ )
+
+
@receiver(signals.tags_management, sender=EditTags)
def record_event_tags_management(sender, performer, signal, content, **_):
Event(
diff --git a/zds/tutorialv2/signals.py b/zds/tutorialv2/signals.py
index 5815177dd6..f47dc535c6 100644
--- a/zds/tutorialv2/signals.py
+++ b/zds/tutorialv2/signals.py
@@ -30,6 +30,10 @@
# Action is either "request", "cancel", "accept", "reject", "revoke", "reserve" or "unreserve".
validation_management = Signal()
+# Thumbnail management
+# For the signal below, the arguments "performer" and "content" shall be provided.
+thumbnail_management = Signal()
+
# Tags management
# For the signal below, the arguments "performer" and "content" shall be provided.
tags_management = Signal()
diff --git a/zds/tutorialv2/tests/tests_views/tests_editthumbnailview.py b/zds/tutorialv2/tests/tests_views/tests_editthumbnailview.py
index df3fdb9d4b..0cf1dd8d28 100644
--- a/zds/tutorialv2/tests/tests_views/tests_editthumbnailview.py
+++ b/zds/tutorialv2/tests/tests_views/tests_editthumbnailview.py
@@ -1,4 +1,5 @@
from datetime import datetime
+from unittest.mock import patch
from django.conf import settings
from django.test import TestCase
@@ -109,7 +110,8 @@ def setUp(self):
self.client.force_login(self.author.user)
- def test_normal(self):
+ @patch("zds.tutorialv2.signals.thumbnail_management")
+ def test_normal(self, thumbnail_management):
self.assertEqual(self.content.title, self.content.gallery.title)
start_date = datetime.now()
self.assertTrue(self.content.update_date < start_date)
@@ -121,3 +123,4 @@ def test_normal(self):
self.assertIsNotNone(self.content.image)
self.assertEqual(self.content.gallery.get_images().count(), 1)
+ self.assertEqual(thumbnail_management.send.call_count, 1)
diff --git a/zds/tutorialv2/views/thumbnail.py b/zds/tutorialv2/views/thumbnail.py
index 17acb49b83..d2374056fc 100644
--- a/zds/tutorialv2/views/thumbnail.py
+++ b/zds/tutorialv2/views/thumbnail.py
@@ -13,8 +13,10 @@
from zds.gallery.mixins import ImageCreateMixin, NotAnImage
from zds.gallery.models import Gallery
+from zds.tutorialv2 import signals
from zds.tutorialv2.mixins import SingleContentFormViewMixin
from zds.tutorialv2.models.database import PublishableContent
+from zds.utils import get_current_user
from zds.utils.uuslug_wrapper import slugify
from zds.utils.validators import with_svg_validator
@@ -99,4 +101,6 @@ def form_valid(self, form):
messages.success(self.request, self.success_message)
+ signals.thumbnail_management.send(sender=self.__class__, performer=get_current_user(), content=publishable)
+
return redirect(form.previous_page_url)