From ace249388f364af5e8e11e8c96bd1753c435ef55 Mon Sep 17 00:00:00 2001 From: Situphen Date: Wed, 17 Jul 2024 23:44:49 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Reproduit=20un=20bug=20li=C3=A9e=20aux=20de?= =?UTF-8?q?mandes=20de=20mise=20en=20avant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zds/featured/tests/tests.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/zds/featured/tests/tests.py b/zds/featured/tests/tests.py index 811d0f5cc2..dda3a694cf 100644 --- a/zds/featured/tests/tests.py +++ b/zds/featured/tests/tests.py @@ -474,6 +474,31 @@ def test_filters(self): self.assertEqual(len(response.context["featured_request_list"]), 1) # it is back! + def test_success_list_with_deleted_content(self): + # create a topic + author = ProfileFactory().user + category = ForumCategoryFactory(position=1) + forum = ForumFactory(category=category, position_in_category=1) + topic = TopicFactory(forum=forum, author=author) + + # create a published content + tutorial = PublishedContentFactory(author_list=[author]) + tutorial.save() + + # request for the topic and the content to be featured + FeaturedRequested.objects.toogle_request(topic, author) + FeaturedRequested.objects.toogle_request(tutorial, author) + + # delete both this topic and this content + topic.delete() + tutorial.delete() + + # check that the page listing the requests still works + staff = StaffProfileFactory() + self.client.force_login(staff.user) + response = self.client.get(reverse("featured:resource-requests")) + self.assertEqual(200, response.status_code) + class FeaturedRequestUpdateViewTest(TestCase): def test_update(self): From 745ae7e1a7751a29f143bf6055deca7b94951143 Mon Sep 17 00:00:00 2001 From: Situphen Date: Fri, 19 Jul 2024 23:16:19 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Corrige=20un=20bug=20li=C3=A9=20aux=20deman?= =?UTF-8?q?des=20de=20mise=20en=20avant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zds/featured/apps.py | 8 ++++++++ zds/featured/receivers.py | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 zds/featured/apps.py create mode 100644 zds/featured/receivers.py diff --git a/zds/featured/apps.py b/zds/featured/apps.py new file mode 100644 index 0000000000..dd97b9ac36 --- /dev/null +++ b/zds/featured/apps.py @@ -0,0 +1,8 @@ +from django.apps import AppConfig + + +class FeaturedConfig(AppConfig): + name = "zds.featured" + + def ready(self): + from . import receivers # noqa diff --git a/zds/featured/receivers.py b/zds/featured/receivers.py new file mode 100644 index 0000000000..934c3c5548 --- /dev/null +++ b/zds/featured/receivers.py @@ -0,0 +1,18 @@ +from django.contrib.contenttypes.models import ContentType +from django.db.models.signals import pre_delete +from django.dispatch import receiver + +from zds.featured.models import FeaturedRequested +from zds.forum.models import Topic +from zds.tutorialv2.models.database import PublishableContent + + +@receiver(pre_delete, sender=PublishableContent) +@receiver(pre_delete, sender=Topic) +def remove_requested_featured_at_content_object_deletion(sender, instance, **kwargs): + try: + FeaturedRequested.objects.get( + content_type=ContentType.objects.get_for_model(sender), object_id=instance.pk + ).delete() + except FeaturedRequested.DoesNotExist: + pass From 7ff0b7f14089ba23f89ce0f431bcf82b102f940a Mon Sep 17 00:00:00 2001 From: Situphen Date: Sat, 20 Jul 2024 21:48:57 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Supprime=20les=20demandes=20de=20mise=20en?= =?UTF-8?q?=20avant=20lors=20de=20la=20d=C3=A9publication=20des=20contenus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zds/featured/receivers.py | 6 +++++- zds/featured/tests/tests.py | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/zds/featured/receivers.py b/zds/featured/receivers.py index 934c3c5548..d10fe8f71c 100644 --- a/zds/featured/receivers.py +++ b/zds/featured/receivers.py @@ -4,12 +4,16 @@ from zds.featured.models import FeaturedRequested from zds.forum.models import Topic -from zds.tutorialv2.models.database import PublishableContent +from zds.tutorialv2.models.database import PublishableContent, PublishedContent @receiver(pre_delete, sender=PublishableContent) +@receiver(pre_delete, sender=PublishedContent) @receiver(pre_delete, sender=Topic) def remove_requested_featured_at_content_object_deletion(sender, instance, **kwargs): + if isinstance(instance, PublishedContent): + sender = PublishableContent + instance = instance.content try: FeaturedRequested.objects.get( content_type=ContentType.objects.get_for_model(sender), object_id=instance.pk diff --git a/zds/featured/tests/tests.py b/zds/featured/tests/tests.py index dda3a694cf..4d75036a0f 100644 --- a/zds/featured/tests/tests.py +++ b/zds/featured/tests/tests.py @@ -9,6 +9,7 @@ from zds.featured.models import FeaturedResource, FeaturedMessage, FeaturedRequested from zds.forum.tests.factories import ForumCategoryFactory, ForumFactory, TopicFactory from zds.gallery.tests.factories import GalleryFactory, ImageFactory +from zds.tutorialv2.publication_utils import unpublish_content from zds.tutorialv2.tests.factories import PublishedContentFactory from zds.tutorialv2.tests import TutorialTestMixin, override_for_contents @@ -488,10 +489,14 @@ def test_success_list_with_deleted_content(self): # request for the topic and the content to be featured FeaturedRequested.objects.toogle_request(topic, author) FeaturedRequested.objects.toogle_request(tutorial, author) + count = FeaturedRequested.objects.count() - # delete both this topic and this content + # delete the topic and unpublish the content topic.delete() - tutorial.delete() + unpublish_content(tutorial) + + # check that the FeaturedRequested objects have been deleted + self.assertEqual(FeaturedRequested.objects.count(), count - 2) # check that the page listing the requests still works staff = StaffProfileFactory()