summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/design_management
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /app/graphql/mutations/design_management
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
downloadgitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'app/graphql/mutations/design_management')
-rw-r--r--app/graphql/mutations/design_management/move.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/app/graphql/mutations/design_management/move.rb b/app/graphql/mutations/design_management/move.rb
new file mode 100644
index 00000000000..0b654447844
--- /dev/null
+++ b/app/graphql/mutations/design_management/move.rb
@@ -0,0 +1,46 @@
+# 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,
+ description: "ID of the design to move"
+
+ argument :previous, DesignID, required: false, as: :previous_design,
+ description: "ID of the immediately preceding design"
+
+ argument :next, DesignID, required: false, as: :next_design,
+ description: "ID of the immediately following design"
+
+ field :design_collection, Types::DesignManagement::DesignCollectionType,
+ null: true,
+ description: "The current state of the collection"
+
+ def ready(*)
+ raise ::Gitlab::Graphql::Errors::ResourceNotAvailable unless ::Feature.enabled?(:reorder_designs, default_enabled: true)
+ end
+
+ def resolve(**args)
+ service = ::DesignManagement::MoveDesignsService.new(current_user, parameters(args))
+
+ { design_collection: service.collection, errors: service.execute.errors }
+ end
+
+ private
+
+ def parameters(**args)
+ args.transform_values { |id| GitlabSchema.find_by_gid(id) }.transform_values(&:sync).tap do |hash|
+ hash.each { |k, design| not_found(args[k]) unless current_user.can?(:read_design, design) }
+ end
+ end
+
+ def not_found(gid)
+ raise Gitlab::Graphql::Errors::ResourceNotAvailable, "Resource not available: #{gid}"
+ end
+ end
+ end
+end