Skip to content
Snippets Groups Projects
Commit d3b76e83 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

Reuse LabelsFinder on Banzai::Filter::LabelReferenceFilter

parent 1e5ea6e7
No related branches found
No related tags found
No related merge requests found
Loading
@@ -4,7 +4,9 @@ class LabelsFinder < UnionFinder
Loading
@@ -4,7 +4,9 @@ class LabelsFinder < UnionFinder
@params = params @params = params
end end
   
def execute def execute(authorized_only: true)
@authorized_only = authorized_only
items = find_union(label_ids, Label) items = find_union(label_ids, Label)
items = with_title(items) items = with_title(items)
sort(items) sort(items)
Loading
@@ -12,7 +14,7 @@ class LabelsFinder < UnionFinder
Loading
@@ -12,7 +14,7 @@ class LabelsFinder < UnionFinder
   
private private
   
attr_reader :current_user, :params attr_reader :current_user, :params, :authorized_only
   
def label_ids def label_ids
label_ids = [] label_ids = []
Loading
@@ -57,7 +59,7 @@ class LabelsFinder < UnionFinder
Loading
@@ -57,7 +59,7 @@ class LabelsFinder < UnionFinder
return @project if defined?(@project) return @project if defined?(@project)
   
if project_id if project_id
@project = available_projects.find(project_id) rescue nil @project = find_project
else else
@project = nil @project = nil
end end
Loading
@@ -65,10 +67,18 @@ class LabelsFinder < UnionFinder
Loading
@@ -65,10 +67,18 @@ class LabelsFinder < UnionFinder
@project @project
end 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 def projects
return @projects if defined?(@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.in_namespace(group_id) if group_id
@projects = @projects.where(id: projects_ids) if projects_ids @projects = @projects.where(id: projects_ids) if projects_ids
@projects = @projects.reorder(nil) @projects = @projects.reorder(nil)
Loading
Loading
Loading
@@ -39,13 +39,7 @@ module Banzai
Loading
@@ -39,13 +39,7 @@ module Banzai
end end
   
def find_labels(project) def find_labels(project)
label_ids = [] LabelsFinder.new(nil, project_id: project.id).execute(authorized_only: false)
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})")
end end
   
# Parameters to pass to `Label.find_by` based on the given arguments # Parameters to pass to `Label.find_by` based on the given arguments
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment