diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /app/services/issuable | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'app/services/issuable')
-rw-r--r-- | app/services/issuable/bulk_update_service.rb | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/app/services/issuable/bulk_update_service.rb b/app/services/issuable/bulk_update_service.rb index 2902385da4a..79be771b3fb 100644 --- a/app/services/issuable/bulk_update_service.rb +++ b/app/services/issuable/bulk_update_service.rb @@ -11,40 +11,29 @@ module Issuable end def execute(type) - model_class = type.classify.constantize - update_class = type.classify.pluralize.constantize::UpdateService - ids = params.delete(:issuable_ids).split(",") - items = find_issuables(parent, model_class, ids) + set_update_params(type) + items = update_issuables(type, ids) + response_success(payload: { count: items.count }) + rescue ArgumentError => e + response_error(e.message, 422) + end + + private + + def set_update_params(type) params.slice!(*permitted_attrs(type)) params.delete_if { |k, v| v.blank? } if params[:assignee_ids] == [IssuableFinder::Params::NONE.to_s] params[:assignee_ids] = [] end - - items.each do |issuable| - next unless can?(current_user, :"update_#{type}", issuable) - - update_class.new(issuable.issuing_parent, current_user, params).execute(issuable) - end - - { - count: items.count, - success: !items.count.zero? - } end - private - def permitted_attrs(type) attrs = %i(state_event milestone_id add_label_ids remove_label_ids subscription_event) - issuable_specific_attrs(type, attrs) - end - - def issuable_specific_attrs(type, attrs) if type == 'issue' || type == 'merge_request' attrs.push(:assignee_ids) else @@ -52,6 +41,20 @@ module Issuable end end + def update_issuables(type, ids) + model_class = type.classify.constantize + update_class = type.classify.pluralize.constantize::UpdateService + items = find_issuables(parent, model_class, ids) + + items.each do |issuable| + next unless can?(current_user, :"update_#{type}", issuable) + + update_class.new(issuable.issuing_parent, current_user, params).execute(issuable) + end + + items + end + def find_issuables(parent, model_class, ids) if parent.is_a?(Project) model_class.id_in(ids).of_projects(parent) @@ -59,6 +62,14 @@ module Issuable model_class.id_in(ids).of_projects(parent.all_projects) end end + + def response_success(message: nil, payload: nil) + ServiceResponse.success(message: message, payload: payload) + end + + def response_error(message, http_status) + ServiceResponse.error(message: message, http_status: http_status) + end end end |