Welcome to mirror list, hosted at ThFree Co, Russian Federation.

issuable_bulk_update.rb « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5ac6c252d964c1759da570f9910364e47cebc835 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

module API
  class IssuableBulkUpdate < Grape::API
    params do
      requires :id, type: String, desc: 'The ID of a project'
    end
    resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
      %w(issue merge_request).each do |issuable|
        desc "Updates a list of #{issuable.pluralize}" do
          detail 'This feature was introduced in 11.9'
        end
        params do
          requires :issuable_ids, type: Array[Integer], desc: "Array of #{issuable.pluralize} IDs to be updated"
          optional :state_event, type: String, values: %w(reopen close), desc: 'Reopens or closes a resource'
          optional :milestone_id, type: Integer, desc: 'The milestone ID number'
          optional :add_label_ids, type: Array[Integer], desc: 'IDs of labels to be added'
          optional :remove_label_ids, type: Array[Integer], desc: 'IDs of labels to be removed'
          optional :subscription_event, type: String, values: %w(subscribe unsubscribe),
                                        desc: 'Subscribes or unsubscribes from a resource'

          if issuable == 'issue'
            optional :assignee_ids, type: Array[Integer], desc: 'List of assignee IDs'
            at_least_one_of :state_event, :milestone_id, :add_label_ids, :remove_label_ids,
                            :subscription_event, :assignee_ids
          else
            optional :assignee_id, type: Integer, desc: 'ID of the assignee'
            at_least_one_of :state_event, :milestone_id, :add_label_ids, :remove_label_ids,
                            :subscription_event, :assignee_id
          end
        end
        put ":id/#{issuable.pluralize}/bulk_update" do
          authorize! :"admin_#{issuable}", user_project

          update_params = declared_params(include_missing: false)

          result = Issuable::BulkUpdateService.new(user_project, current_user, update_params)
            .execute(issuable)

          if result[:success]
            status 200
            quantity = result[:count]
            { message: "#{quantity} #{issuable.pluralize(quantity)} updated" }
          else
            render_api_error!('Bulk update failed', 400)
          end
        end
      end
    end
  end
end