Commit 81a21c94 authored by Sean McGivern's avatar Sean McGivern Committed by Alfredo Sumaran

WIP: allow adding and removing labels in bulk

parent e42f88ca
...@@ -217,7 +217,9 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -217,7 +217,9 @@ class Projects::IssuesController < Projects::ApplicationController
:assignee_id, :assignee_id,
:milestone_id, :milestone_id,
:state_event, :state_event,
label_ids: [] label_ids: [],
add_label_ids: [],
remove_label_ids: []
) )
end end
end end
...@@ -45,6 +45,8 @@ class IssuableBaseService < BaseService ...@@ -45,6 +45,8 @@ class IssuableBaseService < BaseService
unless can?(current_user, ability, project) unless can?(current_user, ability, project)
params.delete(:milestone_id) params.delete(:milestone_id)
params.delete(:add_label_ids)
params.delete(:remove_label_ids)
params.delete(:label_ids) params.delete(:label_ids)
params.delete(:assignee_id) params.delete(:assignee_id)
end end
...@@ -67,10 +69,35 @@ class IssuableBaseService < BaseService ...@@ -67,10 +69,35 @@ class IssuableBaseService < BaseService
end end
def filter_labels def filter_labels
return if params[:label_ids].to_a.empty? if params[:add_label_ids].present? || params[:remove_label_ids].present?
params.delete(:label_ids)
filter_labels_by_name([:add_label_ids, :remove_label_ids])
else
filter_labels_by_name([:label_ids])
end
end
def filter_labels_by_name(keys)
keys.each do |key|
return if params[key].to_a.empty?
params[key] = project.labels.where(id: params[key]).pluck(:id)
end
end
def update_issuable(issuable, attributes)
issuable.with_transaction_returning_status do
add_label_ids = attributes.delete(:add_label_ids)
remove_label_ids = attributes.delete(:remove_label_ids)
params[:label_ids] = issuable.label_ids |= add_label_ids if add_label_ids
project.labels.where(id: params[:label_ids]).pluck(:id) issuable.label_ids -= remove_label_ids if remove_label_ids
issuable.assign_attributes(attributes)
issuable.save
end
end end
def update(issuable) def update(issuable)
...@@ -78,7 +105,7 @@ class IssuableBaseService < BaseService ...@@ -78,7 +105,7 @@ class IssuableBaseService < BaseService
filter_params filter_params
old_labels = issuable.labels.to_a old_labels = issuable.labels.to_a
if params.present? && issuable.update_attributes(params.merge(updated_by: current_user)) if params.present? && update_issuable(issuable, params.merge(updated_by: current_user))
issuable.reset_events_cache issuable.reset_events_cache
handle_common_system_notes(issuable, old_labels: old_labels) handle_common_system_notes(issuable, old_labels: old_labels)
handle_changes(issuable, old_labels: old_labels) handle_changes(issuable, old_labels: old_labels)
......
...@@ -4,9 +4,9 @@ module Issues ...@@ -4,9 +4,9 @@ module Issues
issues_ids = params.delete(:issues_ids).split(",") issues_ids = params.delete(:issues_ids).split(",")
issue_params = params issue_params = params
issue_params.delete(:state_event) unless issue_params[:state_event].present? [:state_event, :milestone_id, :assignee_id, :label_ids, :add_label_ids, :remove_label_ids].each do |key|
issue_params.delete(:milestone_id) unless issue_params[:milestone_id].present? issue_params.delete(key) unless issue_params[key].present?
issue_params.delete(:assignee_id) unless issue_params[:assignee_id].present? end
issues = Issue.where(id: issues_ids) issues = Issue.where(id: issues_ids)
issues.each do |issue| issues.each do |issue|
......
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