debian-mirror-gitlab/app/graphql/mutations/custom_emoji/create.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.3 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
module Mutations
module CustomEmoji
class Create < BaseMutation
graphql_name 'CreateCustomEmoji'
2022-04-04 11:22:00 +05:30
include Mutations::ResolvesGroup
2021-01-29 00:20:46 +05:30
authorize :create_custom_emoji
field :custom_emoji,
Types::CustomEmojiType,
null: true,
2021-10-27 15:23:28 +05:30
description: 'New custom emoji.'
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
argument :group_path, GraphQL::Types::ID,
2021-01-29 00:20:46 +05:30
required: true,
2021-03-08 18:12:59 +05:30
description: 'Namespace full path the emoji is associated with.'
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
argument :name, GraphQL::Types::String,
2021-01-29 00:20:46 +05:30
required: true,
2021-03-08 18:12:59 +05:30
description: 'Name of the emoji.'
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
argument :url, GraphQL::Types::String,
2021-01-29 00:20:46 +05:30
required: true,
as: :file,
2021-03-08 18:12:59 +05:30
description: 'Location of the emoji file.'
2021-01-29 00:20:46 +05:30
def resolve(group_path:, **args)
group = authorized_find!(group_path: group_path)
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/37911#note_444682238
args[:external] = true
2021-04-17 20:07:23 +05:30
args[:creator] = current_user
2021-01-29 00:20:46 +05:30
custom_emoji = group.custom_emoji.create(args)
{
custom_emoji: custom_emoji.valid? ? custom_emoji : nil,
errors: errors_on_object(custom_emoji)
}
end
private
def find_object(group_path:)
resolve_group(full_path: group_path)
end
end
end
end