2020-10-24 23:57:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Boards
|
|
|
|
module Issues
|
|
|
|
class IssueMoveList < Mutations::Issues::Base
|
|
|
|
graphql_name 'IssueMoveList'
|
2021-04-17 20:07:23 +05:30
|
|
|
BoardGID = ::Types::GlobalIDType[::Board]
|
|
|
|
ListID = ::GraphQL::ID_TYPE
|
|
|
|
IssueID = ::GraphQL::ID_TYPE
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
argument :board_id, BoardGID,
|
|
|
|
required: true,
|
|
|
|
loads: Types::BoardType,
|
|
|
|
description: 'Global ID of the board that the issue is in.'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
argument :project_path, GraphQL::ID_TYPE,
|
2021-04-17 20:07:23 +05:30
|
|
|
required: true,
|
|
|
|
description: 'Project the issue to mutate is in.'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
argument :iid, GraphQL::STRING_TYPE,
|
2021-04-17 20:07:23 +05:30
|
|
|
required: true,
|
|
|
|
description: 'IID of the issue to mutate.'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
argument :from_list_id, ListID,
|
|
|
|
required: false,
|
|
|
|
description: 'ID of the board list that the issue will be moved from.'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
argument :to_list_id, ListID,
|
|
|
|
required: false,
|
|
|
|
description: 'ID of the board list that the issue will be moved to.'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
argument :move_before_id, IssueID,
|
|
|
|
required: false,
|
|
|
|
description: 'ID of issue that should be placed before the current issue.'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
argument :move_after_id, IssueID,
|
|
|
|
required: false,
|
|
|
|
description: 'ID of issue that should be placed after the current issue.'
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
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)
|
2020-11-24 15:15:51 +05:30
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab/-/issues/247861')
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
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)
|
2021-04-17 20:07:23 +05:30
|
|
|
return if Ability.allowed?(current_user, :read_issue_board, board.resource_parent)
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
raise_resource_not_available_error!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
Mutations::Boards::Issues::IssueMoveList.prepend_if_ee('EE::Mutations::Boards::Issues::IssueMoveList')
|