debian-mirror-gitlab/app/graphql/mutations/snippets/mark_as_spam.rb
2021-02-22 17:27:13 +05:30

38 lines
854 B
Ruby

# frozen_string_literal: true
module Mutations
module Snippets
class MarkAsSpam < Base
graphql_name 'MarkAsSpamSnippet'
argument :id, ::Types::GlobalIDType[::Snippet],
required: true,
description: 'The global ID of the snippet to update'
def resolve(id:)
snippet = authorized_find!(id: id)
result = mark_as_spam(snippet)
errors = result ? [] : ['Error with Akismet. Please check the logs for more info.']
{
errors: errors
}
end
private
def mark_as_spam(snippet)
Spam::MarkAsSpamService.new(target: snippet).execute
end
def authorized_resource?(snippet)
super && snippet.submittable_as_spam_by?(context[:current_user])
end
def ability_name
"admin"
end
end
end
end