summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/snippets/base.rb
blob: c8cc721b2e063ab568ce9b92b7854e234f5fbd78 (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
# frozen_string_literal: true

module Mutations
  module Snippets
    class Base < BaseMutation
      field :snippet,
            Types::SnippetType,
            null: true,
            description: 'The snippet after mutation'

      private

      def find_object(id:)
        GitlabSchema.object_from_id(id)
      end

      def authorized_resource?(snippet)
        return false if snippet.nil?

        Ability.allowed?(context[:current_user], ability_for(snippet), snippet)
      end

      def ability_for(snippet)
        "#{ability_name}_#{snippet.to_ability_name}".to_sym
      end

      def ability_name
        raise NotImplementedError
      end
    end
  end
end