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

Corrige un bug lié aux demandes de mise en avant #6626

Merged
merged 3 commits into from
Jul 21, 2024
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
8 changes: 8 additions & 0 deletions zds/featured/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.apps import AppConfig


class FeaturedConfig(AppConfig):
name = "zds.featured"

def ready(self):
from . import receivers # noqa
22 changes: 22 additions & 0 deletions zds/featured/receivers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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, 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
).delete()
except FeaturedRequested.DoesNotExist:
pass
30 changes: 30 additions & 0 deletions zds/featured/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -474,6 +475,35 @@ 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)
count = FeaturedRequested.objects.count()

# delete the topic and unpublish the content
topic.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()
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):
Expand Down