Skip to content

Commit

Permalink
Empêche les notifications lorsqu'un nouveau topic est créé dans un fo…
Browse files Browse the repository at this point in the history
…rum auquel l'utilisateur n'a pas accès (#6363)
  • Loading branch information
Migwel authored Aug 12, 2022
1 parent b6576ca commit 85ad533
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit 85ad533

Please sign in to comment.