From cf47c84e9ccad19a43985d96c0614c34ac0c61b4 Mon Sep 17 00:00:00 2001 From: Frederico Camara Date: Mon, 10 May 2021 12:37:59 -0300 Subject: [PATCH] Fix query error where no issue_ids are watched or followed --- app/models/issue.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 0485cfde6..3dcc973a5 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -136,10 +136,14 @@ class Issue < ActiveRecord::Base "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))" when 'own_watch' user_ids = [user.id] + user.groups.pluck(:id).compact - "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}) OR #{table_name}.id IN (#{Watcher.where(user_id: user.id, watchable_type: 'Issue').pluck(:watchable_id).compact.join(',')}))" + text_other_ids = Watcher.where(user_id: user.id, watchable_type: 'Issue').pluck(:watchable_id).compact.join(',') + text_other_ids = "OR #{table_name}.id IN (#{text_other_ids})" if text_other_ids.present? + "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}) #{text_other_ids})" when 'own_watch_contributed' user_ids = [user.id] + user.groups.pluck(:id).compact - "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}) OR #{table_name}.id IN (#{Watcher.where(user_id: user.id, watchable_type: 'Issue').pluck(:watchable_id).compact.join(',')}) OR #{table_name}.id IN (#{Journal.where(user_id: user.id, journalized_type: 'Issue').group(:journalized_id).pluck(:journalized_id).compact.join(',')}))" + text_other_ids = (Watcher.where(user_id: user.id, watchable_type: 'Issue').pluck(:watchable_id) + Journal.where(user_id: user.id, journalized_type: 'Issue').group(:journalized_id).pluck(:journalized_id)).compact.join(',') + text_other_ids = "OR #{table_name}.id IN (#{text_other_ids})" if text_other_ids.present? + "(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}) #{text_other_ids})" else '1=0' end -- 2.25.1