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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
# frozen_string_literal: true
module Mutations
module Notes
module AbuseReport
class Create < BaseMutation
graphql_name 'CreateAbuseReportNote'
description "Creates an abuse report Note."
authorize :create_note
field :note,
Types::Notes::AbuseReport::NoteType,
null: true, description: 'Abuse report note after mutation.'
argument :abuse_report_id, Types::GlobalIDType[::AbuseReport],
required: true, description: 'ID of the abuse report.'
argument :body,
GraphQL::Types::String,
required: true,
description: copy_field_description(Types::Notes::NoteType, :body)
argument :discussion_id,
::Types::GlobalIDType[::Discussion],
required: false,
description: 'Global ID of the abuse report discussion the note is in reply to.'
def resolve(args)
raise_resource_not_available_error! unless Feature.enabled?(:abuse_report_notes, current_user)
note = ::Notes::AbuseReport::CreateService.new(current_user, create_note_params(args)).execute
{
note: (note if note.persisted?),
errors: errors_on_object(note)
}
end
private
def create_note_params(args)
abuse_report = authorized_find!(id: args[:abuse_report_id])
discussion_id = nil
if args[:discussion_id]
discussion = GitlabSchema.find_by_gid(args[:discussion_id])
discussion_id = discussion.id
end
{
abuse_report: abuse_report,
note: args[:body],
in_reply_to_discussion_id: discussion_id
}
end
end
end
end
end
|