summaryrefslogtreecommitdiff
path: root/app/models/note.rb
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-06-10 11:26:47 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-06-13 19:32:00 -0300
commit149176758393c8d89d996c62c11511b3e86b3f8d (patch)
tree6e1a0cdc99e36278735db9beddb6899fb9aa64fe /app/models/note.rb
parentb56c45675019baaaf47615d51c08d5caa0734ad3 (diff)
downloadgitlab-ce-149176758393c8d89d996c62c11511b3e86b3f8d.tar.gz
Use Issue.visible_to_user in Notes.search to avoid query duplication
Diffstat (limited to 'app/models/note.rb')
-rw-r--r--app/models/note.rb19
1 files changed, 3 insertions, 16 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 8ce2b6fa538..58133f1581f 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -88,22 +88,9 @@ class Note < ActiveRecord::Base
table = arel_table
pattern = "%#{query}%"
- found_notes = joins('LEFT JOIN issues ON issues.id = noteable_id').
- where(table[:note].matches(pattern))
-
- if as_user
- found_notes.where('
- issues.confidential IS NULL
- OR issues.confidential IS FALSE
- OR (issues.confidential IS TRUE
- AND (issues.author_id = :user_id
- OR issues.assignee_id = :user_id
- OR issues.project_id IN(:project_ids)))',
- user_id: as_user.id,
- project_ids: as_user.authorized_projects(Gitlab::Access::REPORTER).select(:id))
- else
- found_notes.where('issues.confidential IS NULL OR issues.confidential IS FALSE')
- end
+ Note.joins('LEFT JOIN issues ON issues.id = noteable_id').
+ where(table[:note].matches(pattern)).
+ merge(Issue.visible_to_user(as_user))
end
end