summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-17 17:30:49 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-19 14:58:27 -0200
commitd3b76e832f0afc38e2d0ffdff540c708a74ac26c (patch)
tree9c7b92639ad5aaceda6ab73f5a396de256aa65fd
parent1e5ea6e7e05cd45fc56d0341ac8b5c32e57779b5 (diff)
downloadgitlab-ce-d3b76e832f0afc38e2d0ffdff540c708a74ac26c.tar.gz
Reuse LabelsFinder on Banzai::Filter::LabelReferenceFilter
-rw-r--r--app/finders/labels_finder.rb18
-rw-r--r--lib/banzai/filter/label_reference_filter.rb8
2 files changed, 15 insertions, 11 deletions
diff --git a/app/finders/labels_finder.rb b/app/finders/labels_finder.rb
index 48fd1280ed2..65db4184ecf 100644
--- a/app/finders/labels_finder.rb
+++ b/app/finders/labels_finder.rb
@@ -4,7 +4,9 @@ class LabelsFinder < UnionFinder
@params = params
end
- def execute
+ def execute(authorized_only: true)
+ @authorized_only = authorized_only
+
items = find_union(label_ids, Label)
items = with_title(items)
sort(items)
@@ -12,7 +14,7 @@ class LabelsFinder < UnionFinder
private
- attr_reader :current_user, :params
+ attr_reader :current_user, :params, :authorized_only
def label_ids
label_ids = []
@@ -57,7 +59,7 @@ class LabelsFinder < UnionFinder
return @project if defined?(@project)
if project_id
- @project = available_projects.find(project_id) rescue nil
+ @project = find_project
else
@project = nil
end
@@ -65,10 +67,18 @@ class LabelsFinder < UnionFinder
@project
end
+ def find_project
+ if authorized_only
+ available_projects.find_by(id: project_id)
+ else
+ Project.find_by(id: project_id)
+ end
+ end
+
def projects
return @projects if defined?(@projects)
- @projects = available_projects
+ @projects = authorized_only ? available_projects : Project.all
@projects = @projects.in_namespace(group_id) if group_id
@projects = @projects.where(id: projects_ids) if projects_ids
@projects = @projects.reorder(nil)
diff --git a/lib/banzai/filter/label_reference_filter.rb b/lib/banzai/filter/label_reference_filter.rb
index 21085ae6d49..c24831e68ee 100644
--- a/lib/banzai/filter/label_reference_filter.rb
+++ b/lib/banzai/filter/label_reference_filter.rb
@@ -39,13 +39,7 @@ module Banzai
end
def find_labels(project)
- label_ids = []
- label_ids << project.group.labels.select(:id) if project.group.present?
- label_ids << project.labels.select(:id)
-
- union = Gitlab::SQL::Union.new(label_ids)
-
- Label.where("labels.id IN (#{union.to_sql})")
+ LabelsFinder.new(nil, project_id: project.id).execute(authorized_only: false)
end
# Parameters to pass to `Label.find_by` based on the given arguments