2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Snippets
|
|
|
|
class Base < BaseMutation
|
|
|
|
field :snippet,
|
|
|
|
Types::SnippetType,
|
|
|
|
null: true,
|
2021-03-08 18:12:59 +05:30
|
|
|
description: 'The snippet after mutation.'
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_object(id:)
|
2020-09-03 11:15:55 +05:30
|
|
|
GitlabSchema.object_from_id(id, expected_type: ::Snippet)
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def authorized_resource?(snippet)
|
2020-05-24 23:13:21 +05:30
|
|
|
return false if snippet.nil?
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
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
|