FIX: message_archived? not set correctly for groups

This commit is contained in:
Sam 2016-01-19 18:35:46 +11:00
parent 8d392066d8
commit 665fc44741
2 changed files with 18 additions and 3 deletions

View File

@ -918,8 +918,10 @@ class Topic < ActiveRecord::Base
sql = <<SQL
SELECT 1 FROM topic_allowed_groups tg
JOIN group_archived_messages gm ON gm.topic_id = tg.topic_id AND gm.group_id = tg.group_id
WHERE tg.group_id IN (SELECT g.id FROM group_users g WHERE g.user_id = :user_id)
JOIN group_archived_messages gm
ON gm.topic_id = tg.topic_id AND
gm.group_id = tg.group_id
WHERE tg.group_id IN (SELECT g.group_id FROM group_users g WHERE g.user_id = :user_id)
AND tg.topic_id = :topic_id
UNION ALL
@ -930,7 +932,6 @@ WHERE tu.user_id = :user_id AND tu.topic_id = :topic_id
SQL
User.exec_sql(sql, user_id: user.id, topic_id: id).to_a.length > 0
end
TIME_TO_FIRST_RESPONSE_SQL ||= <<-SQL

View File

@ -1568,6 +1568,20 @@ describe Topic do
expect(Guardian.new(walter).can_see?(group_private_topic)).to be_truthy
end
end
end
it "Correctly sets #message_archived?" do
topic = Fabricate(:private_message_topic)
user = topic.user
expect(topic.message_archived?(user)).to eq(false)
group = Fabricate(:group)
group.add(user)
TopicAllowedGroup.create!(topic_id: topic.id, group_id: group.id)
GroupArchivedMessage.create!(topic_id: topic.id, group_id: group.id)
expect(topic.message_archived?(user)).to eq(true)
end
end