diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /app/graphql/mutations/snippets/create.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'app/graphql/mutations/snippets/create.rb')
-rw-r--r-- | app/graphql/mutations/snippets/create.rb | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/app/graphql/mutations/snippets/create.rb b/app/graphql/mutations/snippets/create.rb index e1022358c09..89c21486a74 100644 --- a/app/graphql/mutations/snippets/create.rb +++ b/app/graphql/mutations/snippets/create.rb @@ -21,7 +21,7 @@ module Mutations description: 'File name of the snippet' argument :content, GraphQL::STRING_TYPE, - required: true, + required: false, description: 'Content of the snippet' argument :description, GraphQL::STRING_TYPE, @@ -40,6 +40,10 @@ module Mutations required: false, description: 'The paths to files uploaded in the snippet description' + argument :files, [Types::Snippets::FileInputType], + description: "The snippet files to create", + required: false + def resolve(args) project_path = args.delete(:project_path) @@ -49,13 +53,9 @@ module Mutations raise_resource_not_available_error! end - # We need to rename `uploaded_files` into `files` because - # it's the expected key param - args[:files] = args.delete(:uploaded_files) - service_response = ::Snippets::CreateService.new(project, - context[:current_user], - args).execute + context[:current_user], + create_params(args)).execute snippet = service_response.payload[:snippet] @@ -82,6 +82,18 @@ module Mutations def can_create_personal_snippet? Ability.allowed?(context[:current_user], :create_snippet) end + + def create_params(args) + args.tap do |create_args| + # We need to rename `files` into `snippet_actions` because + # it's the expected key param + create_args[:snippet_actions] = create_args.delete(:files)&.map(&:to_h) + + # We need to rename `uploaded_files` into `files` because + # it's the expected key param + create_args[:files] = create_args.delete(:uploaded_files) + end + end end end end |