mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FIX: admin check missing from topic tracking state
FIX: handle muted categories correctly
This commit is contained in:
parent
0c11b4c707
commit
832cb9fdc3
2 changed files with 27 additions and 3 deletions
|
@ -148,14 +148,15 @@ class TopicTrackingState
|
||||||
((#{unread}) OR (#{new})) AND
|
((#{unread}) OR (#{new})) AND
|
||||||
(topics.visible OR u.admin OR u.moderator) AND
|
(topics.visible OR u.admin OR u.moderator) AND
|
||||||
topics.deleted_at IS NULL 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
|
SELECT c2.id FROM categories c2
|
||||||
JOIN category_groups cg ON cg.category_id = c2.id
|
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
|
JOIN group_users gu ON gu.user_id = u.id AND cg.group_id = gu.group_id
|
||||||
WHERE c2.read_restricted )
|
WHERE c2.read_restricted )
|
||||||
)
|
)
|
||||||
AND NOT EXISTS( SELECT 1 FROM category_users cu
|
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.category_id = topics.category_id AND
|
||||||
cu.notification_level = #{CategoryUser.notification_levels[:muted]})
|
cu.notification_level = #{CategoryUser.notification_levels[:muted]})
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,34 @@ describe TopicTrackingState do
|
||||||
TopicTrackingState.publish_unread(post)
|
TopicTrackingState.publish_unread(post)
|
||||||
end
|
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
|
it "correctly gets the tracking state" do
|
||||||
report = TopicTrackingState.report([user.id])
|
report = TopicTrackingState.report([user.id])
|
||||||
expect(report.length).to eq(0)
|
expect(report.length).to eq(0)
|
||||||
|
|
||||||
new_post = post
|
|
||||||
post.topic.notifier.watch_topic!(post.topic.user_id)
|
post.topic.notifier.watch_topic!(post.topic.user_id)
|
||||||
|
|
||||||
report = TopicTrackingState.report([user.id])
|
report = TopicTrackingState.report([user.id])
|
||||||
|
|
Loading…
Reference in a new issue