2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Snippets
|
|
|
|
class MarkAsSpam < Base
|
|
|
|
graphql_name 'MarkAsSpamSnippet'
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
argument :id, ::Types::GlobalIDType[::Snippet],
|
2020-01-01 13:55:28 +05:30
|
|
|
required: true,
|
2021-03-08 18:12:59 +05:30
|
|
|
description: 'The global ID of the snippet to update.'
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
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)
|
2021-02-22 17:27:13 +05:30
|
|
|
Spam::MarkAsSpamService.new(target: snippet).execute
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def authorized_resource?(snippet)
|
|
|
|
super && snippet.submittable_as_spam_by?(context[:current_user])
|
|
|
|
end
|
|
|
|
|
|
|
|
def ability_name
|
|
|
|
"admin"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|