diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2019-04-04 15:34:55 +0200 |
---|---|---|
committer | Jan Provaznik <jprovaznik@gitlab.com> | 2019-04-04 19:34:14 +0200 |
commit | f88607923afd5a2adfb7a28df297528cbb27885b (patch) | |
tree | 3415bd1d40ae6bd92c37ac434473c2066dea5f2e | |
parent | fec2e27f1dcbb806247d6f78ebae628622c02d52 (diff) | |
download | gitlab-ce-f88607923afd5a2adfb7a28df297528cbb27885b.tar.gz |
Fix scoped_labels feature check
Check this feature per project/group instead of globally.
Also do not show tooltip if it's disabled.
-rw-r--r-- | app/helpers/labels_helper.rb | 8 | ||||
-rw-r--r-- | app/views/shared/issuable/_sidebar.html.haml | 3 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/entities/merge_request_sidebar.json | 3 | ||||
-rw-r--r-- | spec/helpers/labels_helper_spec.rb | 20 |
4 files changed, 29 insertions, 5 deletions
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb index 5f78219cebb..16f2e51136a 100644 --- a/app/helpers/labels_helper.rb +++ b/app/helpers/labels_helper.rb @@ -89,7 +89,7 @@ module LabelsHelper def render_colored_label(label, label_suffix: '', tooltip: true, title: nil) 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 # by LabelReferenceFilter @@ -270,6 +270,12 @@ module LabelsHelper }) 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 module_function :render_colored_label, :text_color_for_bg, :escape_once, :label_tooltip_title end diff --git a/app/views/shared/issuable/_sidebar.html.haml b/app/views/shared/issuable/_sidebar.html.haml index 3c205c0b5a1..0798b1da4b7 100644 --- a/app/views/shared/issuable/_sidebar.html.haml +++ b/app/views/shared/issuable/_sidebar.html.haml @@ -106,8 +106,7 @@ .value.issuable-show-labels.dont-hide.hide-collapsed.qa-labels-block{ class: ("has-labels" if selected_labels.any?) } - if selected_labels.any? - selected_labels.each do |label_hash| - - label = Label.new(label_hash.slice(:color, :description, :title)) - = render_label(label, link: sidebar_label_filter_path(issuable_sidebar[:project_issuables_path], label[:title])) + = render_label(label_from_hash(label_hash), link: sidebar_label_filter_path(issuable_sidebar[:project_issuables_path], label_hash[:title])) - else %span.no-value = _('None') diff --git a/spec/fixtures/api/schemas/entities/merge_request_sidebar.json b/spec/fixtures/api/schemas/entities/merge_request_sidebar.json index 7e9e048a9fd..214b67a9a0f 100644 --- a/spec/fixtures/api/schemas/entities/merge_request_sidebar.json +++ b/spec/fixtures/api/schemas/entities/merge_request_sidebar.json @@ -51,6 +51,5 @@ "toggle_subscription_path": { "type": "string" }, "move_issue_path": { "type": "string" }, "projects_autocomplete_path": { "type": "string" } - }, - "additionalProperties": false + } } diff --git a/spec/helpers/labels_helper_spec.rb b/spec/helpers/labels_helper_spec.rb index 012678db9c2..a049b5a6133 100644 --- a/spec/helpers/labels_helper_spec.rb +++ b/spec/helpers/labels_helper_spec.rb @@ -249,4 +249,24 @@ describe LabelsHelper do .to match_array([label2, label4, label1, label3]) 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 |