2020-10-24 23:57:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module DesignManagement
|
|
|
|
class Move < ::Mutations::BaseMutation
|
|
|
|
graphql_name "DesignManagementMove"
|
|
|
|
|
|
|
|
DesignID = ::Types::GlobalIDType[::DesignManagement::Design]
|
|
|
|
|
|
|
|
argument :id, DesignID, required: true, as: :current_design,
|
2021-03-08 18:12:59 +05:30
|
|
|
description: "ID of the design to move."
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
argument :previous, DesignID, required: false, as: :previous_design,
|
2021-03-08 18:12:59 +05:30
|
|
|
description: "ID of the immediately preceding design."
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
argument :next, DesignID, required: false, as: :next_design,
|
2021-03-08 18:12:59 +05:30
|
|
|
description: "ID of the immediately following design."
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
field :design_collection, Types::DesignManagement::DesignCollectionType,
|
|
|
|
null: true,
|
2021-03-08 18:12:59 +05:30
|
|
|
description: "The current state of the collection."
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
def resolve(**args)
|
2021-01-03 14:25:43 +05:30
|
|
|
service = ::DesignManagement::MoveDesignsService.new(current_user, parameters(**args))
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
{ design_collection: service.collection, errors: service.execute.errors }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parameters(**args)
|
2021-01-03 14:25:43 +05:30
|
|
|
args.transform_values { |id| find_design(id) }.transform_values(&:sync).tap do |hash|
|
2020-10-24 23:57:45 +05:30
|
|
|
hash.each { |k, design| not_found(args[k]) unless current_user.can?(:read_design, design) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def find_design(id)
|
|
|
|
# TODO: remove this line when the compatibility layer is removed
|
|
|
|
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
|
|
|
|
id = DesignID.coerce_isolated_input(id)
|
|
|
|
GitlabSchema.find_by_gid(id)
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def not_found(gid)
|
|
|
|
raise Gitlab::Graphql::Errors::ResourceNotAvailable, "Resource not available: #{gid}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|