Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mark_as_spam.rb « snippets « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d6b96c699c051d80ce5ba75b2c1c29be9e871892 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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(spammable: 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