Commit 8d4de663 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 6dbb970f
...@@ -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
......
...@@ -104,3 +104,5 @@ class IssuableSidebarBasicEntity < Grape::Entity ...@@ -104,3 +104,5 @@ class IssuableSidebarBasicEntity < Grape::Entity
request.current_user request.current_user
end end
end end
IssuableSidebarBasicEntity.prepend(EE::IssuableSidebarBasicEntity)
...@@ -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')
......
...@@ -12,7 +12,7 @@ In GitLab, you can create project and group labels: ...@@ -12,7 +12,7 @@ In GitLab, you can create project and group labels:
- **Group labels** can be assigned to any issue or merge request of any project in that group or any subgroups of the group. - **Group labels** can be assigned to any issue or merge request of any project in that group or any subgroups of the group.
## Scoped labels ## Scoped labels
A scoped label is a specific kind of label defined only by a special colon syntax in the label’s title, namely `key::value`. There is no different way to create and otherwise manage scoped labels. A label is a scoped label when its title follow the syntax. A scoped label is a specific kind of label defined only by a special colon syntax in the label’s title, namely `key::value`. There is no different way to create and otherwise manage scoped labels. A label is a scoped label when its title follows the syntax.
![A sample scoped label](img/key_value_labels.png) ![A sample scoped label](img/key_value_labels.png)
......
...@@ -32,7 +32,7 @@ module EE ...@@ -32,7 +32,7 @@ module EE
focus_mode_available: parent.feature_available?(:issue_board_focus_mode), focus_mode_available: parent.feature_available?(:issue_board_focus_mode),
weight_feature_available: parent.feature_available?(:issue_weights).to_s, weight_feature_available: parent.feature_available?(:issue_weights).to_s,
show_promotion: show_feature_promotion, show_promotion: show_feature_promotion,
scoped_labels: License.feature_available?(:scoped_labels), scoped_labels: parent.feature_available?(:scoped_labels),
scoped_labels_documentation_link: help_page_path('user/project/labels.md', anchor: 'scoped-labels') scoped_labels_documentation_link: help_page_path('user/project/labels.md', anchor: 'scoped-labels')
} }
......
...@@ -32,11 +32,17 @@ module EE ...@@ -32,11 +32,17 @@ module EE
def label_dropdown_data(project, opts = {}) def label_dropdown_data(project, opts = {})
super.merge({ super.merge({
scoped_labels: License.feature_available?(:scoped_labels)&.to_s, scoped_labels: project&.feature_available?(:scoped_labels)&.to_s,
scoped_labels_documentation_link: help_page_path('user/project/labels.md', anchor: 'scoped-labels') scoped_labels_documentation_link: help_page_path('user/project/labels.md', anchor: 'scoped-labels')
}) })
end end
def sidebar_label_dropdown_data(issuable_type, issuable_sidebar)
super.merge({
scoped_labels: issuable_sidebar[:scoped_labels_available].to_s
})
end
module_function :scoped_label_wrapper, :scoped_labels_doc_link, :label_tooltip_title module_function :scoped_label_wrapper, :scoped_labels_doc_link, :label_tooltip_title
end end
end end
...@@ -41,7 +41,7 @@ module EpicsHelper ...@@ -41,7 +41,7 @@ module EpicsHelper
toggle_subscription_path: toggle_subscription_group_epic_path(group, epic), toggle_subscription_path: toggle_subscription_group_epic_path(group, epic),
labels_web_url: group_labels_path(group), labels_web_url: group_labels_path(group),
epics_web_url: group_epics_path(group), epics_web_url: group_epics_path(group),
scoped_labels: License.feature_available?(:scoped_labels), scoped_labels: group.feature_available?(:scoped_labels),
scoped_labels_documentation_link: help_page_path('user/project/labels.md', anchor: 'scoped-labels') scoped_labels_documentation_link: help_page_path('user/project/labels.md', anchor: 'scoped-labels')
} }
......
...@@ -7,7 +7,7 @@ module EE ...@@ -7,7 +7,7 @@ module EE
SCOPED_LABEL_PATTERN = /^.*::/.freeze SCOPED_LABEL_PATTERN = /^.*::/.freeze
def scoped_label? def scoped_label?
SCOPED_LABEL_PATTERN.match?(name) && ::License.feature_available?(:scoped_labels) SCOPED_LABEL_PATTERN.match?(name) && subject.feature_available?(:scoped_labels)
end end
def scoped_label_key def scoped_label_key
......
# frozen_string_literal: true
module EE
module IssuableSidebarBasicEntity
extend ActiveSupport::Concern
prepended do
expose :scoped_labels_available do |issuable|
issuable.project&.feature_available?(:scoped_labels)
end
end
end
end
...@@ -44,7 +44,7 @@ module EE ...@@ -44,7 +44,7 @@ module EE
end end
def filter_mutually_exclusive_labels(ids, added_label_ids) def filter_mutually_exclusive_labels(ids, added_label_ids)
return ids if added_label_ids.empty? || !::License.feature_available?(:scoped_labels) return ids if added_label_ids.empty? || !parent.feature_available?(:scoped_labels)
label_sets = ScopedLabelSet.from_label_ids(ids) label_sets = ScopedLabelSet.from_label_ids(ids)
......
{
"allOf": [
{ "$ref": "../../../../../../spec/fixtures/api/schemas/entities/merge_request_sidebar.json" },
{
"properties": {
"scoped_labels_available": { "type": "boolean" }
},
"required": [
"scoped_labels_available"
]
}
]
}
...@@ -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