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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/graphql/mutations/boards')
-rw-r--r--app/graphql/mutations/boards/issues/issue_move_list.rb91
-rw-r--r--app/graphql/mutations/boards/lists/base.rb28
-rw-r--r--app/graphql/mutations/boards/lists/create.rb73
-rw-r--r--app/graphql/mutations/boards/lists/update.rb52
4 files changed, 244 insertions, 0 deletions
diff --git a/app/graphql/mutations/boards/issues/issue_move_list.rb b/app/graphql/mutations/boards/issues/issue_move_list.rb
new file mode 100644
index 00000000000..d4bf47af4cf
--- /dev/null
+++ b/app/graphql/mutations/boards/issues/issue_move_list.rb
@@ -0,0 +1,91 @@
+# frozen_string_literal: true
+
+module Mutations
+ module Boards
+ module Issues
+ class IssueMoveList < Mutations::Issues::Base
+ graphql_name 'IssueMoveList'
+
+ argument :board_id, GraphQL::ID_TYPE,
+ required: true,
+ loads: Types::BoardType,
+ description: 'Global ID of the board that the issue is in'
+
+ argument :project_path, GraphQL::ID_TYPE,
+ required: true,
+ description: 'Project the issue to mutate is in'
+
+ argument :iid, GraphQL::STRING_TYPE,
+ required: true,
+ description: 'IID of the issue to mutate'
+
+ argument :from_list_id, GraphQL::ID_TYPE,
+ required: false,
+ description: 'ID of the board list that the issue will be moved from'
+
+ argument :to_list_id, GraphQL::ID_TYPE,
+ required: false,
+ description: 'ID of the board list that the issue will be moved to'
+
+ argument :move_before_id, GraphQL::ID_TYPE,
+ required: false,
+ description: 'ID of issue before which the current issue will be positioned at'
+
+ argument :move_after_id, GraphQL::ID_TYPE,
+ required: false,
+ description: 'ID of issue after which the current issue will be positioned at'
+
+ def ready?(**args)
+ if move_arguments(args).blank?
+ raise Gitlab::Graphql::Errors::ArgumentError,
+ 'At least one of the arguments fromListId, toListId, afterId or beforeId is required'
+ end
+
+ if move_list_arguments(args).one?
+ raise Gitlab::Graphql::Errors::ArgumentError,
+ 'Both fromListId and toListId must be present'
+ end
+
+ super
+ end
+
+ def resolve(board:, **args)
+ raise_resource_not_available_error! unless board
+ authorize_board!(board)
+
+ issue = authorized_find!(project_path: args[:project_path], iid: args[:iid])
+ move_params = { id: issue.id, board_id: board.id }.merge(move_arguments(args))
+
+ move_issue(board, issue, move_params)
+
+ {
+ issue: issue.reset,
+ errors: issue.errors.full_messages
+ }
+ end
+
+ private
+
+ def move_issue(board, issue, move_params)
+ service = ::Boards::Issues::MoveService.new(board.resource_parent, current_user, move_params)
+
+ service.execute(issue)
+ end
+
+ def move_list_arguments(args)
+ args.slice(:from_list_id, :to_list_id)
+ end
+
+ def move_arguments(args)
+ args.slice(:from_list_id, :to_list_id, :move_after_id, :move_before_id)
+ end
+
+ def authorize_board!(board)
+ return if Ability.allowed?(current_user, :read_board, board.resource_parent)
+
+ raise_resource_not_available_error!
+ end
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/boards/lists/base.rb b/app/graphql/mutations/boards/lists/base.rb
new file mode 100644
index 00000000000..34b271ba3b8
--- /dev/null
+++ b/app/graphql/mutations/boards/lists/base.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module Mutations
+ module Boards
+ module Lists
+ class Base < BaseMutation
+ include Mutations::ResolvesIssuable
+
+ argument :board_id, ::Types::GlobalIDType[::Board],
+ required: true,
+ description: 'The Global ID of the issue board to mutate'
+
+ field :list,
+ Types::BoardListType,
+ null: true,
+ description: 'List of the issue board'
+
+ authorize :admin_list
+
+ private
+
+ def find_object(id:)
+ GitlabSchema.object_from_id(id, expected_type: ::Board)
+ end
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/boards/lists/create.rb b/app/graphql/mutations/boards/lists/create.rb
new file mode 100644
index 00000000000..4f545709ee9
--- /dev/null
+++ b/app/graphql/mutations/boards/lists/create.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+module Mutations
+ module Boards
+ module Lists
+ class Create < Base
+ graphql_name 'BoardListCreate'
+
+ argument :backlog, GraphQL::BOOLEAN_TYPE,
+ required: false,
+ description: 'Create the backlog list'
+
+ argument :label_id, ::Types::GlobalIDType[::Label],
+ required: false,
+ description: 'ID of an existing label'
+
+ def ready?(**args)
+ if args.slice(*mutually_exclusive_args).size != 1
+ arg_str = mutually_exclusive_args.map { |x| x.to_s.camelize(:lower) }.join(' or ')
+ raise Gitlab::Graphql::Errors::ArgumentError, "one and only one of #{arg_str} is required"
+ end
+
+ super
+ end
+
+ def resolve(**args)
+ board = authorized_find!(id: args[:board_id])
+ params = create_list_params(args)
+
+ authorize_list_type_resource!(board, params)
+
+ list = create_list(board, params)
+
+ {
+ list: list.valid? ? list : nil,
+ errors: errors_on_object(list)
+ }
+ end
+
+ private
+
+ def authorize_list_type_resource!(board, params)
+ return unless params[:label_id]
+
+ labels = ::Labels::AvailableLabelsService.new(current_user, board.resource_parent, params)
+ .filter_labels_ids_in_param(:label_id)
+
+ unless labels.present?
+ raise Gitlab::Graphql::Errors::ArgumentError, 'Label not found!'
+ end
+ end
+
+ def create_list(board, params)
+ create_list_service =
+ ::Boards::Lists::CreateService.new(board.resource_parent, current_user, params)
+
+ create_list_service.execute(board)
+ end
+
+ def create_list_params(args)
+ params = args.slice(*mutually_exclusive_args).with_indifferent_access
+ params[:label_id] = GitlabSchema.parse_gid(params[:label_id]).model_id if params[:label_id]
+
+ params
+ end
+
+ def mutually_exclusive_args
+ [:backlog, :label_id]
+ end
+ end
+ end
+ end
+end
diff --git a/app/graphql/mutations/boards/lists/update.rb b/app/graphql/mutations/boards/lists/update.rb
new file mode 100644
index 00000000000..7efed3058b3
--- /dev/null
+++ b/app/graphql/mutations/boards/lists/update.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+module Mutations
+ module Boards
+ module Lists
+ class Update < BaseMutation
+ graphql_name 'UpdateBoardList'
+
+ argument :list_id, GraphQL::ID_TYPE,
+ required: true,
+ loads: Types::BoardListType,
+ description: 'Global ID of the list.'
+
+ argument :position, GraphQL::INT_TYPE,
+ required: false,
+ description: 'Position of list within the board'
+
+ argument :collapsed, GraphQL::BOOLEAN_TYPE,
+ required: false,
+ description: 'Indicates if list is collapsed for this user'
+
+ field :list,
+ Types::BoardListType,
+ null: true,
+ description: 'Mutated list'
+
+ def resolve(list: nil, **args)
+ raise_resource_not_available_error! unless can_read_list?(list)
+ update_result = update_list(list, args)
+
+ {
+ list: update_result[:list],
+ errors: list.errors.full_messages
+ }
+ end
+
+ private
+
+ def update_list(list, args)
+ service = ::Boards::Lists::UpdateService.new(list.board, current_user, args)
+ service.execute(list)
+ end
+
+ def can_read_list?(list)
+ return false unless list.present?
+
+ Ability.allowed?(current_user, :read_list, list.board)
+ end
+ end
+ end
+ end
+end