debian-mirror-gitlab/app/graphql/mutations/award_emojis/base.rb

42 lines
1.2 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
module Mutations
module AwardEmojis
class Base < BaseMutation
2021-02-22 17:27:13 +05:30
include ::Mutations::FindsByGid
NOT_EMOJI_AWARDABLE = 'You cannot award emoji to this resource.'
2019-09-30 21:07:59 +05:30
authorize :award_emoji
argument :awardable_id,
2021-01-03 14:25:43 +05:30
::Types::GlobalIDType[::Awardable],
2019-09-30 21:07:59 +05:30
required: true,
2021-10-27 15:23:28 +05:30
description: 'Global ID of the awardable resource.'
2019-09-30 21:07:59 +05:30
argument :name,
2021-10-27 15:23:28 +05:30
GraphQL::Types::String,
2019-09-30 21:07:59 +05:30
required: true,
description: copy_field_description(Types::AwardEmojis::AwardEmojiType, :name)
field :award_emoji,
Types::AwardEmojis::AwardEmojiType,
null: true,
2021-10-27 15:23:28 +05:30
description: 'Award emoji after mutation.'
2019-09-30 21:07:59 +05:30
private
2021-02-22 17:27:13 +05:30
# TODO: remove this method when the compatibility layer is removed
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
2019-09-30 21:07:59 +05:30
def find_object(id:)
2021-02-22 17:27:13 +05:30
super(id: ::Types::GlobalIDType[::Awardable].coerce_isolated_input(id))
2019-09-30 21:07:59 +05:30
end
2021-02-22 17:27:13 +05:30
def authorize!(object)
super
raise_resource_not_available_error!(NOT_EMOJI_AWARDABLE) unless object.emoji_awardable?
2019-09-30 21:07:59 +05:30
end
end
end
end