From 05691b732de6f005b0ea4c721d2466fc9bb06ac9 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 8 Sep 2020 11:17:35 +0800 Subject: [PATCH] DEV: Address review comments for 5ed84d9885b. --- lib/topic_query.rb | 2 +- spec/components/topic_query_spec.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 8b183843c6..aa91b9d4e6 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -534,7 +534,7 @@ class TopicQuery if type == :group result = result .includes(:allowed_users) - .joins("INNER JOIN topic_allowed_groups tag ON tag.topic_id = topics.id AND tag.group_id IN (SELECT id FROM groups WHERE name ilike '#{sanitize_sql_array([@options[:group_name]])}')") + .joins("INNER JOIN topic_allowed_groups tag ON tag.topic_id = topics.id AND tag.group_id IN (SELECT id FROM groups WHERE LOWER(name) = '#{PG::Connection.escape_string(@options[:group_name].downcase)}')") unless user.admin? result = result.joins("INNER JOIN group_users gu ON gu.group_id = tag.group_id AND gu.user_id = #{user.id.to_i}") diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index 9ad251b93a..12c0b9638e 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -1090,7 +1090,9 @@ describe TopicQuery do end it 'should return the right list for an admin not part of the group' do - topics = TopicQuery.new(nil, group_name: group.name) + group.update!(name: group.name.capitalize) + + topics = TopicQuery.new(nil, group_name: group.name.upcase) .list_private_messages_group(Fabricate(:admin)) .topics