Disable subscribing to group-level labels

parent aa781489
......@@ -223,6 +223,13 @@
}
.label-subscribe-button {
.label-subscribe-button-icon {
&[disabled] {
opacity: 0.5;
pointer-events: none;
}
}
.label-subscribe-button-loading {
display: none;
}
......
class Groups::LabelsController < Groups::ApplicationController
include ToggleSubscriptionAction
before_action :label, only: [:edit, :update, :destroy, :toggle_subscription]
before_action :label, only: [:edit, :update, :destroy]
before_action :authorize_admin_labels!, only: [:new, :create, :edit, :update, :destroy]
before_action :save_previous_label_path, only: [:edit]
......@@ -71,7 +69,6 @@ class Groups::LabelsController < Groups::ApplicationController
def label
@label ||= @group.labels.find(params[:id])
end
alias_method :subscribable_resource, :label
def label_params
params.require(:label).permit(:title, :description, :color)
......
......@@ -68,11 +68,12 @@ module LabelsHelper
end
end
def toggle_subscription_label_path(label)
case label
when GroupLabel then toggle_subscription_group_label_path(label.group, label)
when ProjectLabel then toggle_subscription_namespace_project_label_path(label.project.namespace, label.project, label)
end
def toggle_subscription_data(label)
return unless label.is_a?(ProjectLabel)
{
url: toggle_subscription_namespace_project_label_path(label.project.namespace, label.project, label)
}
end
def render_colored_label(label, label_suffix = '', tooltip: true)
......@@ -148,11 +149,17 @@ module LabelsHelper
end
def label_subscription_status(label)
label.subscribed?(current_user) ? 'subscribed' : 'unsubscribed'
case label
when GroupLabel then 'Subscribing to group labels is currently not supported.'
when ProjectLabel then label.subscribed?(current_user) ? 'subscribed' : 'unsubscribed'
end
end
def label_subscription_toggle_button_text(label)
label.subscribed?(current_user) ? 'Unsubscribe' : 'Subscribe'
case label
when GroupLabel then 'Subscribing to group labels is currently not supported.'
when ProjectLabel then label.subscribed?(current_user) ? 'Unsubscribe' : 'Subscribe'
end
end
def label_deletion_confirm_text(label)
......
......@@ -18,7 +18,7 @@
= link_to_label(label, subject: @project) do
= pluralize open_issues_count, 'open issue'
- if current_user
%li.label-subscription{ data: { url: toggle_subscription_label_path(label) } }
%li.label-subscription{ data: toggle_subscription_data(label) }
%a.js-subscribe-button.label-subscribe-button.subscription-status{ role: "button", href: "#", data: { toggle: "tooltip", status: label_subscription_status(label) } }
%span= label_subscription_toggle_button_text(label)
- if can?(current_user, :admin_label, label)
......@@ -34,10 +34,10 @@
= pluralize open_issues_count, 'open issue'
- if current_user
.label-subscription.inline{ data: { url: toggle_subscription_label_path(label) } }
.label-subscription.inline{ data: toggle_subscription_data(label) }
%button.js-subscribe-button.label-subscribe-button.btn.btn-transparent.btn-action.subscription-status{ type: "button", title: label_subscription_toggle_button_text(label), data: { toggle: "tooltip", status: label_subscription_status(label) } }
%span.sr-only= label_subscription_toggle_button_text(label)
= icon('eye', class: 'label-subscribe-button-icon')
= icon('eye', class: 'label-subscribe-button-icon', disabled: label.is_a?(GroupLabel))
= icon('spinner spin', class: 'label-subscribe-button-loading')
- if can?(current_user, :admin_label, label)
......@@ -48,6 +48,6 @@
%span.sr-only Delete
= icon('trash-o')
- if current_user
- if current_user && label.is_a?(ProjectLabel)
:javascript
new Subscription('##{dom_id(label)} .label-subscription');
......@@ -29,10 +29,6 @@ resources :groups, constraints: { id: /[a-zA-Z.0-9_\-]+(?<!\.atom)/ } do
resource :avatar, only: [:destroy]
resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create]
resources :labels, except: [:show], constraints: { id: /\d+/ } do
member do
post :toggle_subscription
end
end
resources :labels, except: [:show], constraints: { id: /\d+/ }
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