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 via les tags auxquels on est abonné pour les sujets inaccessibles #6325

Merged
merged 2 commits into from
Jun 16, 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 @@ -266,7 +266,7 @@ def _handle_added_tags(tag_content_type, topic):
for subscription in subscriptions:
notification = Notification.objects.filter(object_id=topic.id, subscription=subscription)
if not notification:
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
31 changes: 30 additions & 1 deletion zds/notification/tests/tests_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
from django.db import IntegrityError

from django.conf import settings
from zds.forum.tests.factories import ForumCategoryFactory, ForumFactory, TopicFactory, PostFactory, TagFactory
from zds.forum.tests.factories import (
ForumCategoryFactory,
ForumFactory,
TopicFactory,
PostFactory,
TagFactory,
create_category_and_forum,
)
from zds.forum.models import Topic
from zds.gallery.tests.factories import UserGalleryFactory
from zds.member.tests.factories import ProfileFactory, StaffProfileFactory, UserFactory
Expand Down Expand Up @@ -414,6 +421,28 @@ 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_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
"""
# 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)

tag1 = TagFactory(title="MyTagInHiddenForum")
NewTopicSubscription.objects.toggle_follow(tag1, user1)

topic1 = TopicFactory(forum=forum, author=user2)
topic1.add_tags([tag1.title])

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

def test_mark_read_a_topic_of_a_tag_subscribed(self):
"""
When a user has a notification on a topic, the notification should be marked as read.
Expand Down