2019-12-17 10:08:15 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Snippets
|
|
|
|
class MarkAsSpam < Base
|
|
|
|
graphql_name 'MarkAsSpamSnippet'
|
|
|
|
|
2020-11-09 16:08:48 -05:00
|
|
|
argument :id, ::Types::GlobalIDType[::Snippet],
|
2019-12-17 10:08:15 -05:00
|
|
|
required: true,
|
2021-01-07 07:10:24 -05:00
|
|
|
description: 'The global ID of the snippet to update.'
|
2019-12-17 10:08:15 -05:00
|
|
|
|
|
|
|
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)
|
2020-12-16 01:10:11 -05:00
|
|
|
Spam::MarkAsSpamService.new(target: snippet).execute
|
2019-12-17 10:08:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def authorized_resource?(snippet)
|
|
|
|
super && snippet.submittable_as_spam_by?(context[:current_user])
|
|
|
|
end
|
|
|
|
|
|
|
|
def ability_name
|
|
|
|
"admin"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|