FIX: admin check missing from topic tracking state

FIX: handle muted categories correctly
This commit is contained in:
Sam 2015-04-17 14:03:08 +10:00
parent 0c11b4c707
commit 832cb9fdc3
2 changed files with 27 additions and 3 deletions

View file

@ -148,14 +148,15 @@ class TopicTrackingState
((#{unread}) OR (#{new})) AND
(topics.visible OR u.admin OR u.moderator) AND
topics.deleted_at IS NULL AND
( category_id IS NULL OR NOT c.read_restricted OR category_id IN (
( category_id IS NULL OR NOT c.read_restricted OR u.admin OR category_id IN (
SELECT c2.id FROM categories c2
JOIN category_groups cg ON cg.category_id = c2.id
JOIN group_users gu ON gu.user_id = u.id AND cg.group_id = gu.group_id
WHERE c2.read_restricted )
)
AND NOT EXISTS( SELECT 1 FROM category_users cu
WHERE cu.user_id = u.id AND
WHERE last_read_post_number IS NULL AND
cu.user_id = u.id AND
cu.category_id = topics.category_id AND
cu.notification_level = #{CategoryUser.notification_levels[:muted]})

View file

@ -15,11 +15,34 @@ describe TopicTrackingState do
TopicTrackingState.publish_unread(post)
end
it "correctly handles muted categories" do
user = Fabricate(:user)
post
report = TopicTrackingState.report([user.id])
expect(report.length).to eq(1)
CategoryUser.create!(user_id: user.id,
notification_level: CategoryUser.notification_levels[:muted],
category_id: post.topic.category_id
)
create_post(topic_id: post.topic_id)
report = TopicTrackingState.report([user.id])
expect(report.length).to eq(0)
TopicUser.create!(user_id: user.id, topic_id: post.topic_id, last_read_post_number: 1, notification_level: 3)
report = TopicTrackingState.report([user.id])
expect(report.length).to eq(1)
end
it "correctly gets the tracking state" do
report = TopicTrackingState.report([user.id])
expect(report.length).to eq(0)
new_post = post
post.topic.notifier.watch_topic!(post.topic.user_id)
report = TopicTrackingState.report([user.id])