Replace label references with links for group labels

parent 7f2e29ff
...@@ -9,7 +9,7 @@ module Banzai ...@@ -9,7 +9,7 @@ module Banzai
end end
def find_object(project, id) def find_object(project, id)
project.labels.find(id) find_labels(project).find(id)
end end
def self.references_in(text, pattern = Label.reference_pattern) def self.references_in(text, pattern = Label.reference_pattern)
...@@ -35,7 +35,17 @@ module Banzai ...@@ -35,7 +35,17 @@ module Banzai
return unless project return unless project
label_params = label_params(label_id, label_name) label_params = label_params(label_id, label_name)
project.labels.find_by(label_params) find_labels(project).find_by(label_params)
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)
object_class.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
...@@ -60,7 +70,7 @@ module Banzai ...@@ -60,7 +70,7 @@ module Banzai
end end
def object_link_text(object, matches) def object_link_text(object, matches)
if context[:project] == object.project if object.project.nil? || object.project == context[:project]
LabelsHelper.render_colored_label(object) LabelsHelper.render_colored_label(object)
else else
LabelsHelper.render_colored_cross_project_label(object) LabelsHelper.render_colored_cross_project_label(object)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment