debian-mirror-gitlab/app/graphql/mutations/notes/create/base.rb

56 lines
1.5 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
module Mutations
module Notes
module Create
# This is a Base class for the Note creation Mutations and is not
# mounted as a GraphQL mutation itself.
class Base < Mutations::Notes::Base
authorize :create_note
argument :noteable_id,
GraphQL::ID_TYPE,
required: true,
description: 'The global id of the resource to add a note to'
argument :body,
GraphQL::STRING_TYPE,
required: true,
description: copy_field_description(Types::Notes::NoteType, :body)
2020-07-28 23:09:34 +05:30
argument :confidential,
GraphQL::BOOLEAN_TYPE,
required: false,
description: 'The confidentiality flag of a note. Default is false.'
2019-09-30 21:07:59 +05:30
def resolve(args)
noteable = authorized_find!(id: args[:noteable_id])
check_object_is_noteable!(noteable)
note = ::Notes::CreateService.new(
noteable.project,
current_user,
create_note_params(noteable, args)
).execute
{
note: (note if note.persisted?),
errors: errors_on_object(note)
}
end
2019-12-04 20:38:33 +05:30
private
2019-09-30 21:07:59 +05:30
def create_note_params(noteable, args)
{
noteable: noteable,
2020-07-28 23:09:34 +05:30
note: args[:body],
confidential: args[:confidential]
2019-09-30 21:07:59 +05:30
}
end
end
end
end
end