summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-09-20 00:59:26 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-19 14:58:24 -0200
commit476c26deb22a6e958dc3251e9771560b058a34a3 (patch)
tree265b3a04032e5b0793eedb058f21205235d4ef74 /lib
parent7f2e29ff3da54c4525dc55b4447fea2963e17fd3 (diff)
downloadgitlab-ce-476c26deb22a6e958dc3251e9771560b058a34a3.tar.gz
Replace label references with links for group labels
Diffstat (limited to 'lib')
-rw-r--r--lib/banzai/filter/label_reference_filter.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/banzai/filter/label_reference_filter.rb b/lib/banzai/filter/label_reference_filter.rb
index 8f262ef3d8d..3a09912f1be 100644
--- a/lib/banzai/filter/label_reference_filter.rb
+++ b/lib/banzai/filter/label_reference_filter.rb
@@ -9,7 +9,7 @@ module Banzai
end
def find_object(project, id)
- project.labels.find(id)
+ find_labels(project).find(id)
end
def self.references_in(text, pattern = Label.reference_pattern)
@@ -35,7 +35,17 @@ module Banzai
return unless project
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
# Parameters to pass to `Label.find_by` based on the given arguments
@@ -60,7 +70,7 @@ module Banzai
end
def object_link_text(object, matches)
- if context[:project] == object.project
+ if object.project.nil? || object.project == context[:project]
LabelsHelper.render_colored_label(object)
else
LabelsHelper.render_colored_cross_project_label(object)