2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Notes
|
|
|
|
module Create
|
|
|
|
class Note < Base
|
|
|
|
graphql_name 'CreateNote'
|
2022-05-07 20:08:51 +05:30
|
|
|
description "Creates a Note.\n#{QUICK_ACTION_ONLY_WARNING}"
|
2019-09-30 21:07:59 +05:30
|
|
|
|
|
|
|
argument :discussion_id,
|
2021-01-03 14:25:43 +05:30
|
|
|
::Types::GlobalIDType[::Discussion],
|
2019-09-30 21:07:59 +05:30
|
|
|
required: false,
|
2021-10-27 15:23:28 +05:30
|
|
|
description: 'Global ID of the discussion this note is in reply to.'
|
2019-09-30 21:07:59 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
argument :merge_request_diff_head_sha,
|
|
|
|
GraphQL::Types::String,
|
|
|
|
required: false,
|
|
|
|
description: 'SHA of the head commit which is used to ensure that the merge request has not been updated since the request was sent.'
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def create_note_params(noteable, args)
|
|
|
|
discussion_id = nil
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
if gid = args[:discussion_id]
|
|
|
|
discussion = GitlabSchema.find_by_gid(gid)
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
authorize_discussion!(discussion)
|
|
|
|
|
|
|
|
discussion_id = discussion.id
|
|
|
|
end
|
|
|
|
|
|
|
|
super(noteable, args).merge({
|
2022-05-07 20:08:51 +05:30
|
|
|
in_reply_to_discussion_id: discussion_id,
|
|
|
|
merge_request_diff_head_sha: args[:merge_request_diff_head_sha]
|
2019-09-30 21:07:59 +05:30
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_discussion!(discussion)
|
|
|
|
unless Ability.allowed?(current_user, :read_note, discussion, scope: :user)
|
|
|
|
raise Gitlab::Graphql::Errors::ResourceNotAvailable,
|
|
|
|
"The discussion does not exist or you don't have permission to perform this action"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|