Use Issue.visible_to_user in Notes.search to avoid query duplication
This commit is contained in:
parent
b56c456750
commit
1491767583
3 changed files with 13 additions and 29 deletions
|
@ -51,7 +51,7 @@ class Issue < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.visible_to_user(user)
|
||||
return where(confidential: false) if user.blank?
|
||||
return where('issues.confidential IS NULL OR issues.confidential IS FALSE') if user.blank?
|
||||
return all if user.admin?
|
||||
|
||||
where('
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -825,19 +825,16 @@ class User < ActiveRecord::Base
|
|||
private
|
||||
|
||||
def projects_union(min_access_level = nil)
|
||||
relations = if min_access_level
|
||||
scope = { access_level: Gitlab::Access.values.select { |access| access >= min_access_level } }
|
||||
relations = [personal_projects.select(:id),
|
||||
groups_projects.select(:id),
|
||||
projects.select(:id),
|
||||
groups.joins(:shared_projects).select(:project_id)]
|
||||
|
||||
[personal_projects.select(:id),
|
||||
groups_projects.where(members: scope).select(:id),
|
||||
projects.where(members: scope).select(:id),
|
||||
groups.joins(:shared_projects).where(members: scope).select(:project_id)]
|
||||
else
|
||||
[personal_projects.select(:id),
|
||||
groups_projects.select(:id),
|
||||
projects.select(:id),
|
||||
groups.joins(:shared_projects).select(:project_id)]
|
||||
end
|
||||
|
||||
if min_access_level
|
||||
scope = { access_level: Gitlab::Access.values.select { |access| access >= min_access_level } }
|
||||
relations = [relations.shift] + relations.map { |relation| relation.where(members: scope) }
|
||||
end
|
||||
|
||||
Gitlab::SQL::Union.new(relations)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue