Allow users to subscribe to group labels on group labels page

parent b7ea3ce4
......@@ -134,20 +134,21 @@ module LabelsHelper
end
def label_subscription_status(label, project)
return 'project-level' if label.subscribed?(current_user, project)
return 'group-level' if label.subscribed?(current_user)
return 'project-level' if label.subscribed?(current_user, project)
'unsubscribed'
end
def group_label_unsubscribe_path(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)
def toggle_subscription_label_path(label, project)
if label.is_a?(GroupLabel)
toggle_subscription_group_label_path(label.group, label)
else
toggle_subscription_namespace_project_label_path(project.namespace, project, label)
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'
end
......
......@@ -17,13 +17,13 @@
%li
= link_to_label(label, subject: subject) do
view open issues
- if current_user && defined?(@project)
- if current_user
%li.label-subscription
- if label.is_a?(ProjectLabel)
%a.js-subscribe-button.label-subscribe-button{ role: 'button', href: '#', data: { status: status, url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } }
- if defined?(@group) || label.is_a?(ProjectLabel)
%a.js-subscribe-button.label-subscribe-button{ role: 'button', href: '#', data: { status: status, url: toggle_subscription_label_path(label, @project) } }
%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) } }
%a.js-unsubscribe-button.label-subscribe-button{ role: 'button', href: '#', class: ('hidden' if status.unsubscribed?), data: { url: toggle_subscription_label_path(label, @project) } }
%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) } }
%span Subscribe at project level
......@@ -42,14 +42,14 @@
= link_to_label(label, subject: subject, css_class: 'btn btn-transparent btn-action') do
view open issues
- if current_user && defined?(@project)
- if current_user
.label-subscription.inline
- if label.is_a?(ProjectLabel)
%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) } }
- if defined?(@group) || label.is_a?(ProjectLabel)
%button.js-subscribe-button.label-subscribe-button.btn.btn-default{ type: 'button', data: { status: status, url: toggle_subscription_label_path(label, @project) } }
%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) } }
%button.js-unsubscribe-button.label-subscribe-button.btn.btn-default{ type: 'button', class: ('hidden' if status.unsubscribed?), data: { url: toggle_subscription_label_path(label, @project) } }
%span Unsubscribe
= icon('spinner spin', class: 'label-subscribe-button-loading')
......@@ -76,8 +76,8 @@
%span.sr-only Delete
= icon('trash-o')
- if current_user && defined?(@project)
- if label.is_a?(ProjectLabel)
- if current_user
- if defined?(@group) || label.is_a?(ProjectLabel)
:javascript
new gl.ProjectLabelSubscription('##{dom_id(label)} .label-subscription');
- else
......
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 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