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

Empêche les notifications lorsqu'un nouveau topic est créé dans un forum auquel l'utilisateur n'a pas accès #6363

Merged
merged 2 commits into from
Aug 12, 2022
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
2 changes: 1 addition & 1 deletion zds/notification/receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def new_topic_event(sender, *, instance, created=True, **__):

subscriptions = NewTopicSubscription.objects.get_subscriptions(topic.forum)
for subscription in subscriptions:
if subscription.user != topic.author:
if subscription.user != topic.author and topic.forum.can_read(subscription.user):
subscription.send_notification(content=topic, sender=topic.author)


Expand Down
19 changes: 19 additions & 0 deletions zds/notification/tests/tests_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,25 @@ def test_notifications_on_a_tag_subscribed(self):
notifications = Notification.objects.filter(object_id=topic2.pk, is_read=False).all()
self.assertEqual(0, len(notifications))

def test_no_notification_on_new_topic_in_hidden_forum(self):
"""
When a user subscribes to a forum that gets hidden and a topic is created in that forum, no notification is sent
"""
# Subscribe.
user1 = ProfileFactory().user
user2 = ProfileFactory().user

group = Group.objects.create(name="Restricted")
user2.groups.add(group)
user2.save()
category, forum = create_category_and_forum(group)

NewTopicSubscription.objects.toggle_follow(forum, user1)
topic1 = TopicFactory(forum=forum, author=user2)

notifications = Notification.objects.filter(object_id=topic1.pk, is_read=False).all()
self.assertEqual(0, len(notifications))

def test_no_notification_on_a_tag_subscribed_in_hidden_forum(self):
"""
When a user subscribes to a tag and a topic is created using that tag in a hidden forum, no notification is sent
Expand Down