2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Mutations
|
|
|
|
module Notes
|
|
|
|
module Update
|
|
|
|
class ImageDiffNote < Mutations::Notes::Update::Base
|
|
|
|
graphql_name 'UpdateImageDiffNote'
|
2021-04-17 20:07:23 +05:30
|
|
|
description <<~DESC
|
|
|
|
Updates a DiffNote on an image (a `Note` where the `position.positionType` is `"image"`).
|
|
|
|
#{QUICK_ACTION_ONLY_WARNING}
|
|
|
|
DESC
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
argument :body,
|
2021-10-27 15:23:28 +05:30
|
|
|
GraphQL::Types::String,
|
2021-04-17 20:07:23 +05:30
|
|
|
required: false,
|
|
|
|
description: copy_field_description(Types::Notes::NoteType, :body)
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
argument :position,
|
2021-04-17 20:07:23 +05:30
|
|
|
Types::Notes::UpdateDiffImagePositionInputType,
|
|
|
|
required: false,
|
|
|
|
description: copy_field_description(Types::Notes::NoteType, :position)
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
def ready?(**args)
|
|
|
|
# As both arguments are optional, validate here that one of the
|
|
|
|
# arguments are present.
|
|
|
|
#
|
|
|
|
# This may be able to be done using InputUnions in the future
|
|
|
|
# if this RFC is merged:
|
|
|
|
# https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md
|
|
|
|
if args.values_at(:body, :position).compact.blank?
|
|
|
|
raise Gitlab::Graphql::Errors::ArgumentError,
|
|
|
|
'body or position arguments are required'
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
super(**args)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def pre_update_checks!(note, _args)
|
2021-04-17 20:07:23 +05:30
|
|
|
return if note.is_a?(DiffNote) && note.position.on_image?
|
|
|
|
|
|
|
|
raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Resource is not an ImageDiffNote'
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def note_params(note, args)
|
|
|
|
super(note, args).merge(
|
|
|
|
position: position_params(note, args)
|
|
|
|
).compact
|
|
|
|
end
|
|
|
|
|
|
|
|
def position_params(note, args)
|
2021-01-29 00:20:46 +05:30
|
|
|
return unless args[:position]
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
original_position = note.position.to_h
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
Gitlab::Diff::Position.new(original_position.merge(args[:position].to_h))
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|