diff --git a/zds/notification/receivers.py b/zds/notification/receivers.py index 53d66c2959..4cfec65105 100644 --- a/zds/notification/receivers.py +++ b/zds/notification/receivers.py @@ -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) diff --git a/zds/notification/tests/tests_basics.py b/zds/notification/tests/tests_basics.py index a5ca8f272c..afbae68e0c 100644 --- a/zds/notification/tests/tests_basics.py +++ b/zds/notification/tests/tests_basics.py @@ -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