Commit cefa4dc0 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix-33991' into 'master'

Allow users to subscribe to group labels on the group labels page

Closes #33991

See merge request !12402
parents 22dc7e9c 28785488
...@@ -133,21 +133,28 @@ module LabelsHelper ...@@ -133,21 +133,28 @@ module LabelsHelper
end end
end end
def can_subscribe_to_label_in_different_levels?(label)
defined?(@project) && label.is_a?(GroupLabel)
end
def label_subscription_status(label, project) def label_subscription_status(label, project)
return 'project-level' if label.subscribed?(current_user, project)
return 'group-level' if label.subscribed?(current_user) return 'group-level' if label.subscribed?(current_user)
return 'project-level' if label.subscribed?(current_user, project)
'unsubscribed' 'unsubscribed'
end end
def group_label_unsubscribe_path(label, project) def toggle_subscription_label_path(label, project)
return toggle_subscription_group_label_path(label.group, label) unless project
case label_subscription_status(label, project) case label_subscription_status(label, project)
when 'project-level' then toggle_subscription_namespace_project_label_path(@project.namespace, @project, label)
when 'group-level' then toggle_subscription_group_label_path(label.group, label) when 'group-level' then toggle_subscription_group_label_path(label.group, label)
when 'project-level' then toggle_subscription_namespace_project_label_path(project.namespace, project, label)
when 'unsubscribed' then toggle_subscription_namespace_project_label_path(project.namespace, project, label)
end end
end end
def label_subscription_toggle_button_text(label, project) def label_subscription_toggle_button_text(label, project = nil)
label.subscribed?(current_user, project) ? 'Unsubscribe' : 'Subscribe' label.subscribed?(current_user, project) ? 'Unsubscribe' : 'Subscribe'
end end
......
- label_css_id = dom_id(label) - label_css_id = dom_id(label)
- status = label_subscription_status(label, @project).inquiry if current_user - status = label_subscription_status(label, @project).inquiry if current_user
- subject = local_assigns[:subject] - subject = local_assigns[:subject]
- toggle_subscription_path = toggle_subscription_label_path(label, @project) if current_user
%li{ id: label_css_id, data: { id: label.id } } %li{ id: label_css_id, data: { id: label.id } }
= render "shared/label_row", label: label = render "shared/label_row", label: label
...@@ -17,18 +18,18 @@ ...@@ -17,18 +18,18 @@
%li %li
= link_to_label(label, subject: subject) do = link_to_label(label, subject: subject) do
view open issues view open issues
- if current_user && defined?(@project) - if current_user
%li.label-subscription %li.label-subscription
- if label.is_a?(ProjectLabel) - if can_subscribe_to_label_in_different_levels?(label)
%a.js-subscribe-button.label-subscribe-button{ role: 'button', href: '#', data: { status: status, url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } } %a.js-unsubscribe-button.label-subscribe-button{ role: 'button', href: '#', class: ('hidden' if status.unsubscribed?), data: { url: toggle_subscription_path } }
%span= label_subscription_toggle_button_text(label, @project)
- else
%a.js-unsubscribe-button.label-subscribe-button{ role: 'button', href: '#', class: ('hidden' if status.unsubscribed?), data: { url: group_label_unsubscribe_path(label, @project) } }
%span Unsubscribe %span Unsubscribe
%a.js-subscribe-button.label-subscribe-button{ role: 'button', href: '#', class: ('hidden' unless status.unsubscribed?), data: { url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } } %a.js-subscribe-button.label-subscribe-button{ role: 'button', href: '#', class: ('hidden' unless status.unsubscribed?), data: { url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } }
%span Subscribe at project level %span Subscribe at project level
%a.js-subscribe-button.label-subscribe-button{ role: 'button', href: '#', class: ('hidden' unless status.unsubscribed?), data: { url: toggle_subscription_group_label_path(label.group, label) } } %a.js-subscribe-button.label-subscribe-button{ role: 'button', href: '#', class: ('hidden' unless status.unsubscribed?), data: { url: toggle_subscription_group_label_path(label.group, label) } }
%span Subscribe at group level %span Subscribe at group level
- else
%a.js-subscribe-button.label-subscribe-button{ role: 'button', href: '#', data: { status: status, url: toggle_subscription_path } }
%span= label_subscription_toggle_button_text(label, @project)
- if can?(current_user, :admin_label, label) - if can?(current_user, :admin_label, label)
%li %li
...@@ -42,14 +43,10 @@ ...@@ -42,14 +43,10 @@
= link_to_label(label, subject: subject, css_class: 'btn btn-transparent btn-action') do = link_to_label(label, subject: subject, css_class: 'btn btn-transparent btn-action') do
view open issues view open issues
- if current_user && defined?(@project) - if current_user
.label-subscription.inline .label-subscription.inline
- if label.is_a?(ProjectLabel) - if can_subscribe_to_label_in_different_levels?(label)
%button.js-subscribe-button.label-subscribe-button.btn.btn-default{ type: 'button', data: { status: status, url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } } %button.js-unsubscribe-button.label-subscribe-button.btn.btn-default{ type: 'button', class: ('hidden' if status.unsubscribed?), data: { url: toggle_subscription_path } }
%span= label_subscription_toggle_button_text(label, @project)
= icon('spinner spin', class: 'label-subscribe-button-loading')
- else
%button.js-unsubscribe-button.label-subscribe-button.btn.btn-default{ type: 'button', class: ('hidden' if status.unsubscribed?), data: { url: group_label_unsubscribe_path(label, @project) } }
%span Unsubscribe %span Unsubscribe
= icon('spinner spin', class: 'label-subscribe-button-loading') = icon('spinner spin', class: 'label-subscribe-button-loading')
...@@ -59,10 +56,14 @@ ...@@ -59,10 +56,14 @@
= icon('chevron-down') = icon('chevron-down')
%ul.dropdown-menu %ul.dropdown-menu
%li %li
%a.js-subscribe-button{ data: { url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } } %a.js-subscribe-button{ class: ('hidden' unless status.unsubscribed?), data: { url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } }
Project level Project level
%a.js-subscribe-button{ data: { url: toggle_subscription_group_label_path(label.group, label) } } %a.js-subscribe-button{ class: ('hidden' unless status.unsubscribed?), data: { url: toggle_subscription_group_label_path(label.group, label) } }
Group level Group level
- else
%button.js-subscribe-button.label-subscribe-button.btn.btn-default{ type: 'button', data: { status: status, url: toggle_subscription_path } }
%span= label_subscription_toggle_button_text(label, @project)
= icon('spinner spin', class: 'label-subscribe-button-loading')
- if label.is_a?(ProjectLabel) && label.project.group && can?(current_user, :admin_label, label.project.group) - if label.is_a?(ProjectLabel) && label.project.group && can?(current_user, :admin_label, label.project.group)
= link_to promote_namespace_project_label_path(label.project.namespace, label.project, label), title: "Promote to Group Label", class: 'btn btn-transparent btn-action', data: {confirm: "Promoting this label will make this label available to all projects inside this group. Existing project labels with the same name will be merged. Are you sure?", toggle: "tooltip"}, method: :post do = link_to promote_namespace_project_label_path(label.project.namespace, label.project, label), title: "Promote to Group Label", class: 'btn btn-transparent btn-action', data: {confirm: "Promoting this label will make this label available to all projects inside this group. Existing project labels with the same name will be merged. Are you sure?", toggle: "tooltip"}, method: :post do
...@@ -76,10 +77,10 @@ ...@@ -76,10 +77,10 @@
%span.sr-only Delete %span.sr-only Delete
= icon('trash-o') = icon('trash-o')
- if current_user && defined?(@project) - if current_user
- if label.is_a?(ProjectLabel) - if can_subscribe_to_label_in_different_levels?(label)
:javascript :javascript
new gl.ProjectLabelSubscription('##{dom_id(label)} .label-subscription'); new gl.GroupLabelSubscription('##{dom_id(label)} .label-subscription');
- else - else
:javascript :javascript
new gl.GroupLabelSubscription('##{dom_id(label)} .label-subscription'); new gl.ProjectLabelSubscription('##{dom_id(label)} .label-subscription');
---
title: Users can subscribe to group labels on the group labels page
merge_request:
author:
require 'spec_helper'
feature 'Labels subscription', feature: true do
let(:user) { create(:user) }
let(:group) { create(:group) }
let!(:feature) { create(:group_label, group: group, title: 'feature') }
context 'when signed in' do
before do
group.add_developer(user)
gitlab_sign_in user
end
scenario 'users can subscribe/unsubscribe to group labels', js: true do
visit group_labels_path(group)
expect(page).to have_content('feature')
within "#group_label_#{feature.id}" do
expect(page).not_to have_button 'Unsubscribe'
click_button 'Subscribe'
expect(page).not_to have_button 'Subscribe'
expect(page).to have_button 'Unsubscribe'
click_button 'Unsubscribe'
expect(page).to have_button 'Subscribe'
expect(page).not_to have_button 'Unsubscribe'
end
end
end
context 'when not signed in' do
it 'users can not subscribe/unsubscribe to labels' do
visit group_labels_path(group)
expect(page).to have_content 'feature'
expect(page).not_to have_button('Subscribe')
end
end
def click_link_on_dropdown(text)
find('.dropdown-group-label').click
page.within('.dropdown-group-label') do
find('a.js-subscribe-button', text: text).click
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