Commit f8860792 authored by Jan Provaznik's avatar Jan Provaznik

Fix scoped_labels feature check

Check this feature per project/group instead of globally.
Also do not show tooltip if it's disabled.
parent fec2e27f
...@@ -89,7 +89,7 @@ module LabelsHelper ...@@ -89,7 +89,7 @@ module LabelsHelper
def render_colored_label(label, label_suffix: '', tooltip: true, title: nil) def render_colored_label(label, label_suffix: '', tooltip: true, title: nil)
text_color = text_color_for_bg(label.color) text_color = text_color_for_bg(label.color)
title ||= label_tooltip_title(label) title ||= tooltip ? label_tooltip_title(label) : ''
# Intentionally not using content_tag here so that this method can be called # Intentionally not using content_tag here so that this method can be called
# by LabelReferenceFilter # by LabelReferenceFilter
...@@ -270,6 +270,12 @@ module LabelsHelper ...@@ -270,6 +270,12 @@ module LabelsHelper
}) })
end end
def label_from_hash(hash)
klass = hash[:group_id] ? GroupLabel : ProjectLabel
klass.new(hash.slice(:color, :description, :title, :group_id, :project_id))
end
# Required for Banzai::Filter::LabelReferenceFilter # Required for Banzai::Filter::LabelReferenceFilter
module_function :render_colored_label, :text_color_for_bg, :escape_once, :label_tooltip_title module_function :render_colored_label, :text_color_for_bg, :escape_once, :label_tooltip_title
end end
...@@ -106,8 +106,7 @@ ...@@ -106,8 +106,7 @@
.value.issuable-show-labels.dont-hide.hide-collapsed.qa-labels-block{ class: ("has-labels" if selected_labels.any?) } .value.issuable-show-labels.dont-hide.hide-collapsed.qa-labels-block{ class: ("has-labels" if selected_labels.any?) }
- if selected_labels.any? - if selected_labels.any?
- selected_labels.each do |label_hash| - selected_labels.each do |label_hash|
- label = Label.new(label_hash.slice(:color, :description, :title)) = render_label(label_from_hash(label_hash), link: sidebar_label_filter_path(issuable_sidebar[:project_issuables_path], label_hash[:title]))
= render_label(label, link: sidebar_label_filter_path(issuable_sidebar[:project_issuables_path], label[:title]))
- else - else
%span.no-value %span.no-value
= _('None') = _('None')
......
...@@ -51,6 +51,5 @@ ...@@ -51,6 +51,5 @@
"toggle_subscription_path": { "type": "string" }, "toggle_subscription_path": { "type": "string" },
"move_issue_path": { "type": "string" }, "move_issue_path": { "type": "string" },
"projects_autocomplete_path": { "type": "string" } "projects_autocomplete_path": { "type": "string" }
}, }
"additionalProperties": false
} }
...@@ -249,4 +249,24 @@ describe LabelsHelper do ...@@ -249,4 +249,24 @@ describe LabelsHelper do
.to match_array([label2, label4, label1, label3]) .to match_array([label2, label4, label1, label3])
end end
end end
describe 'label_from_hash' do
it 'builds a group label with whitelisted attributes' do
label = label_from_hash({ title: 'foo', color: 'bar', id: 1, group_id: 1 })
expect(label).to be_a(GroupLabel)
expect(label.id).to be_nil
expect(label.title).to eq('foo')
expect(label.color).to eq('bar')
end
it 'builds a project label with whitelisted attributes' do
label = label_from_hash({ title: 'foo', color: 'bar', id: 1, project_id: 1 })
expect(label).to be_a(ProjectLabel)
expect(label.id).to be_nil
expect(label.title).to eq('foo')
expect(label.color).to eq('bar')
end
end
end end
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