diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /app/graphql/mutations/snippets/create.rb | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'app/graphql/mutations/snippets/create.rb')
-rw-r--r-- | app/graphql/mutations/snippets/create.rb | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/app/graphql/mutations/snippets/create.rb b/app/graphql/mutations/snippets/create.rb index b4485e28c5a..73eac9f0f3b 100644 --- a/app/graphql/mutations/snippets/create.rb +++ b/app/graphql/mutations/snippets/create.rb @@ -3,7 +3,8 @@ module Mutations module Snippets class Create < BaseMutation - include SpammableMutationFields + include ServiceCompatibility + include CanMutateSpammable authorize :create_snippet @@ -45,18 +46,17 @@ module Mutations authorize!(:global) end - service_response = ::Snippets::CreateService.new(project, - current_user, - create_params(args)).execute + process_args_for_params!(args) - snippet = service_response.payload[:snippet] + service_response = ::Snippets::CreateService.new(project, current_user, args).execute # Only when the user is not an api user and the operation was successful if !api_user? && service_response.success? ::Gitlab::UsageDataCounters::EditorUniqueCounter.track_snippet_editor_edit_action(author: current_user) end - with_spam_fields(snippet) do + snippet = service_response.payload[:snippet] + with_spam_action_fields(snippet) do { snippet: service_response.success? ? snippet : nil, errors: errors_on_object(snippet) @@ -70,18 +70,25 @@ module Mutations Project.find_by_full_path(full_path) end - def create_params(args) - with_spam_params do - args.tap do |create_args| - # We need to rename `blob_actions` into `snippet_actions` because - # it's the expected key param - create_args[:snippet_actions] = create_args.delete(:blob_actions)&.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 + # process_args_for_params!(args) -> nil + # + # Modifies/adds/deletes mutation resolve args as necessary to be passed as params to service layer. + def process_args_for_params!(args) + convert_blob_actions_to_snippet_actions!(args) + + # We need to rename `uploaded_files` into `files` because + # it's the expected key param + args[:files] = args.delete(:uploaded_files) + + if Feature.enabled?(:snippet_spam) + args.merge!(additional_spam_params) + else + args[:disable_spam_action_service] = true end + + # Return nil to make it explicit that this method is mutating the args parameter, and that + # the return value is not relevant and is not to be used. + nil end end end |