debian-mirror-gitlab/app/graphql/mutations/snippets/update.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
2.7 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
module Mutations
module Snippets
class Update < Base
2022-04-04 11:22:00 +05:30
graphql_name 'UpdateSnippet'
2021-03-11 19:13:27 +05:30
include ServiceCompatibility
2021-04-29 21:17:54 +05:30
include Mutations::SpamProtection
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
argument :id, ::Types::GlobalIDType[::Snippet],
2020-01-01 13:55:28 +05:30
required: true,
2021-10-27 15:23:28 +05:30
description: 'Global ID of the snippet to update.'
2020-01-01 13:55:28 +05:30
2021-10-27 15:23:28 +05:30
argument :title, GraphQL::Types::String,
2020-01-01 13:55:28 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Title of the snippet.'
2020-01-01 13:55:28 +05:30
2021-10-27 15:23:28 +05:30
argument :description, GraphQL::Types::String,
2020-01-01 13:55:28 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Description of the snippet.'
2020-01-01 13:55:28 +05:30
argument :visibility_level, Types::VisibilityLevelsEnum,
2021-10-27 15:23:28 +05:30
description: 'Visibility level of the snippet.',
2020-01-01 13:55:28 +05:30
required: false
2020-10-24 23:57:45 +05:30
argument :blob_actions, [Types::Snippets::BlobActionInputType],
2021-03-08 18:12:59 +05:30
description: 'Actions to perform over the snippet repository and blobs.',
2020-07-28 23:09:34 +05:30
required: false
2021-02-22 17:27:13 +05:30
def resolve(id:, **args)
snippet = authorized_find!(id: id)
2020-01-01 13:55:28 +05:30
2021-03-11 19:13:27 +05:30
process_args_for_params!(args)
2021-09-30 23:02:18 +05:30
spam_params = ::Spam::SpamParams.new_from_request(request: context[:request])
service = ::Snippets::UpdateService.new(project: snippet.project, current_user: current_user, params: args, spam_params: spam_params)
service_response = service.execute(snippet)
2021-03-11 19:13:27 +05:30
# TODO: DRY this up - From here down, this is all duplicated with Mutations::Snippets::Create#resolve, except for
# `snippet.reset`, which is required in order to return the object in its non-dirty, unmodified, database state
# See issue here: https://gitlab.com/gitlab-org/gitlab/-/issues/300250
2020-01-01 13:55:28 +05:30
2020-11-24 15:15:51 +05:30
# Only when the user is not an api user and the operation was successful
2021-03-11 19:13:27 +05:30
if !api_user? && service_response.success?
2020-11-24 15:15:51 +05:30
::Gitlab::UsageDataCounters::EditorUniqueCounter.track_snippet_editor_edit_action(author: current_user)
end
2021-03-11 19:13:27 +05:30
snippet = service_response.payload[:snippet]
2021-04-29 21:17:54 +05:30
check_spam_action_response!(snippet)
{
snippet: service_response.success? ? snippet : snippet.reset,
errors: errors_on_object(snippet)
}
2020-01-01 13:55:28 +05:30
end
private
2021-03-11 19:13:27 +05:30
# 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)
2020-07-28 23:09:34 +05:30
2021-03-11 19:13:27 +05:30
# 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
def ability_name
'update'
2020-01-01 13:55:28 +05:30
end
end
end
end