summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects/labels_controller.rb7
-rw-r--r--app/helpers/labels_helper.rb16
-rw-r--r--app/views/shared/_label.html.haml12
-rw-r--r--spec/controllers/projects/labels_controller_spec.rb26
4 files changed, 34 insertions, 27 deletions
diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb
index 93cfd8a7721..a65adf13568 100644
--- a/app/controllers/projects/labels_controller.rb
+++ b/app/controllers/projects/labels_controller.rb
@@ -3,7 +3,7 @@ class Projects::LabelsController < Projects::ApplicationController
before_action :module_enabled
before_action :label, only: [:edit, :update, :destroy]
- before_action :find_labels, only: [:index, :set_priorities, :remove_priority]
+ before_action :find_labels, only: [:index, :set_priorities, :remove_priority, :toggle_subscription]
before_action :authorize_read_label!
before_action :authorize_admin_labels!, only: [:new, :create, :edit, :update,
:generate, :destroy, :remove_priority,
@@ -123,7 +123,10 @@ class Projects::LabelsController < Projects::ApplicationController
def label
@label ||= @project.labels.find(params[:id])
end
- alias_method :subscribable_resource, :label
+
+ def subscribable_resource
+ @available_labels.find(params[:id])
+ end
def subscribable_project
@project
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb
index 74f6f1b1478..a5abae7fa8e 100644
--- a/app/helpers/labels_helper.rb
+++ b/app/helpers/labels_helper.rb
@@ -68,11 +68,9 @@ module LabelsHelper
end
end
- def toggle_subscription_data(label)
- return unless label.is_a?(ProjectLabel)
-
+ def toggle_subscription_data(label, project)
{
- url: toggle_subscription_namespace_project_label_path(label.project.namespace, label.project, label)
+ url: toggle_subscription_namespace_project_label_path(project.namespace, project, label)
}
end
@@ -149,17 +147,11 @@ module LabelsHelper
end
def label_subscription_status(label, project)
- case label
- when GroupLabel then 'Subscribing to group labels is currently not supported.'
- when ProjectLabel then label.subscribed?(current_user, project) ? 'subscribed' : 'unsubscribed'
- end
+ label.subscribed?(current_user, project) ? 'subscribed' : 'unsubscribed'
end
def label_subscription_toggle_button_text(label, project)
- case label
- when GroupLabel then 'Subscribing to group labels is currently not supported.'
- when ProjectLabel then label.subscribed?(current_user, project) ? 'Unsubscribe' : 'Subscribe'
- end
+ label.subscribed?(current_user, project) ? 'Unsubscribe' : 'Subscribe'
end
def label_deletion_confirm_text(label)
diff --git a/app/views/shared/_label.html.haml b/app/views/shared/_label.html.haml
index f3c49870770..c8bc175093e 100644
--- a/app/views/shared/_label.html.haml
+++ b/app/views/shared/_label.html.haml
@@ -18,8 +18,8 @@
%li
= link_to_label(label, subject: subject) do
= pluralize open_issues_count, 'open issue'
- - if current_user
- %li.label-subscription{ data: toggle_subscription_data(label) }
+ - if current_user && defined?(@project)
+ %li.label-subscription{ data: toggle_subscription_data(label, @project) }
%a.js-subscribe-button.label-subscribe-button.subscription-status{ role: "button", href: "#", data: { toggle: "tooltip", status: label_subscription_status(label, @project) } }
%span= label_subscription_toggle_button_text(label, @project)
- if can?(current_user, :admin_label, label)
@@ -34,11 +34,11 @@
= link_to_label(label, subject: subject, css_class: 'btn btn-transparent btn-action') do
= pluralize open_issues_count, 'open issue'
- - if current_user
- .label-subscription.inline{ data: toggle_subscription_data(label) }
+ - if current_user && defined?(@project)
+ .label-subscription.inline{ data: toggle_subscription_data(label, @project) }
%button.js-subscribe-button.label-subscribe-button.btn.btn-transparent.btn-action.subscription-status{ type: "button", title: label_subscription_toggle_button_text(label, @project), data: { toggle: "tooltip", status: label_subscription_status(label, @project) } }
%span.sr-only= label_subscription_toggle_button_text(label, @project)
- = icon('eye', class: 'label-subscribe-button-icon', disabled: label.is_a?(GroupLabel))
+ = icon('eye', class: 'label-subscribe-button-icon')
= icon('spinner spin', class: 'label-subscribe-button-loading')
- if can?(current_user, :admin_label, label)
@@ -49,6 +49,6 @@
%span.sr-only Delete
= icon('trash-o')
- - if current_user && label.is_a?(ProjectLabel)
+ - if current_user && defined?(@project)
:javascript
new Subscription('##{dom_id(label)} .label-subscription');
diff --git a/spec/controllers/projects/labels_controller_spec.rb b/spec/controllers/projects/labels_controller_spec.rb
index 8faecec0063..2b51bae926b 100644
--- a/spec/controllers/projects/labels_controller_spec.rb
+++ b/spec/controllers/projects/labels_controller_spec.rb
@@ -72,14 +72,8 @@ describe Projects::LabelsController do
end
describe 'POST #generate' do
- let(:admin) { create(:admin) }
-
- before do
- sign_in(admin)
- end
-
context 'personal project' do
- let(:personal_project) { create(:empty_project) }
+ let(:personal_project) { create(:empty_project, namespace: user.namespace) }
it 'creates labels' do
post :generate, namespace_id: personal_project.namespace.to_param, project_id: personal_project.to_param
@@ -96,4 +90,22 @@ describe Projects::LabelsController do
end
end
end
+
+ describe 'POST #toggle_subscription' do
+ it 'allows user to toggle subscription on project labels' do
+ label = create(:label, project: project)
+
+ post :toggle_subscription, namespace_id: project.namespace.to_param, project_id: project.to_param, id: label.id
+
+ expect(response).to have_http_status(200)
+ end
+
+ it 'allows user to toggle subscription on group labels' do
+ group_label = create(:group_label, group: group)
+
+ post :toggle_subscription, namespace_id: project.namespace.to_param, project_id: project.to_param, id: group_label.id
+
+ expect(response).to have_http_status(200)
+ end
+ end
end