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

Fix #4539 : problème de duplication lors de la souscription à un forum #5961

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
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
17 changes: 7 additions & 10 deletions zds/notification/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,13 @@ def get_or_create_active(self, user, content_object):
:return: subscription
"""
content_type = ContentType.objects.get_for_model(content_object)
try:
subscription = self.get(
object_id=content_object.pk,
content_type__pk=content_type.pk,
user=user)
if not subscription.is_active:
subscription.activate()
except ObjectDoesNotExist:
subscription = self.model(user=user, content_object=content_object)
subscription.save()
# boolean creation flag is useless for us. Use default method because of its robustness
subscription = self.get_or_create(
object_id=content_object.pk,
content_type=content_type,
user=user)
if not subscription.is_active:
subscription.activate()

return subscription

Expand Down
10 changes: 10 additions & 0 deletions zds/notification/tests/tests_tricky.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,13 @@ def test_no_emails_for_those_who_have_other_things_in_that_place(self):
send_message_mp(self.userOAuth2, topic, '', send_by_mail=True)

self.assertEqual(1, len(mail.outbox))

def test_follow_by_email_after_normal(self):
forum = ForumFactory(category=ForumCategoryFactory())
user = ProfileFactory().user
subsription = NewTopicSubscription.objects.toggle_follow(forum, user)
self.assertIsNotNone(subsription)
new_subsription = NewTopicSubscription.objects.toggle_follow(forum, user, by_email=True)
self.assertIsNotNone(new_subsription)
self.assertEqual(subsription.pk, new_subsription.pk)
self.assertTrue(new_subsription.by_email)