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

update_task.rb « work_items « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d3df235f8940731acda0fbe2da9c36cc21ab562d (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

module Mutations
  module WorkItems
    class UpdateTask < BaseMutation
      graphql_name 'WorkItemUpdateTask'
      description "Updates a work item's task by Global ID."

      include Mutations::SpamProtection

      authorize :read_work_item

      argument :id, ::Types::GlobalIDType[::WorkItem],
               required: true,
               description: 'Global ID of the work item.'
      argument :task_data, ::Types::WorkItems::UpdatedTaskInputType,
               required: true,
               description: 'Arguments necessary to update a task.'

      field :task, Types::WorkItemType,
            null: true,
            description: 'Updated task.'
      field :work_item, Types::WorkItemType,
            null: true,
            description: 'Updated work item.'

      def resolve(id:, task_data:)
        task_data_hash = task_data.to_h
        work_item = authorized_find!(id: id)
        task = authorized_find_task!(task_data_hash[:id])

        ::WorkItems::UpdateService.new(
          container: task.project,
          current_user: current_user,
          params: task_data_hash.except(:id),
          perform_spam_check: true
        ).execute(task)

        check_spam_action_response!(task)

        response = { errors: errors_on_object(task) }

        if task.valid?
          work_item.expire_etag_cache

          response.merge(work_item: work_item, task: task)
        else
          response
        end
      end

      private

      def authorized_find_task!(task_id)
        task = task_id.find

        if current_user.can?(:update_work_item, task)
          task
        else
          # Fail early if user cannot update task
          raise_resource_not_available_error!
        end
      end

      def find_object(id:)
        id.find
      end
    end
  end
end