2020-08-07 17:10:07 -04:00
|
|
|
# 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-01-07 07:10:24 -05:00
|
|
|
description: "ID of the design to move."
|
2020-08-07 17:10:07 -04:00
|
|
|
|
|
|
|
argument :previous, DesignID, required: false, as: :previous_design,
|
2021-01-07 07:10:24 -05:00
|
|
|
description: "ID of the immediately preceding design."
|
2020-08-07 17:10:07 -04:00
|
|
|
|
|
|
|
argument :next, DesignID, required: false, as: :next_design,
|
2021-01-07 07:10:24 -05:00
|
|
|
description: "ID of the immediately following design."
|
2020-08-07 17:10:07 -04:00
|
|
|
|
|
|
|
field :design_collection, Types::DesignManagement::DesignCollectionType,
|
|
|
|
null: true,
|
2021-01-07 07:10:24 -05:00
|
|
|
description: "The current state of the collection."
|
2020-08-07 17:10:07 -04:00
|
|
|
|
|
|
|
def resolve(**args)
|
2020-10-01 14:10:20 -04:00
|
|
|
service = ::DesignManagement::MoveDesignsService.new(current_user, parameters(**args))
|
2020-08-07 17:10:07 -04:00
|
|
|
|
|
|
|
{ design_collection: service.collection, errors: service.execute.errors }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parameters(**args)
|
2020-10-01 05:09:54 -04:00
|
|
|
args.transform_values { |id| find_design(id) }.transform_values(&:sync).tap do |hash|
|
2020-08-07 17:10:07 -04:00
|
|
|
hash.each { |k, design| not_found(args[k]) unless current_user.can?(:read_design, design) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-01 05:09:54 -04:00
|
|
|
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)
|
2020-10-07 23:08:39 -04:00
|
|
|
GitlabSchema.find_by_gid(id)
|
2020-10-01 05:09:54 -04:00
|
|
|
end
|
|
|
|
|
2020-08-07 17:10:07 -04:00
|
|
|
def not_found(gid)
|
|
|
|
raise Gitlab::Graphql::Errors::ResourceNotAvailable, "Resource not available: #{gid}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|