2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module Notes
|
|
|
|
class BuildService < ::BaseService
|
|
|
|
def execute
|
|
|
|
in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id)
|
2021-04-17 20:07:23 +05:30
|
|
|
discussion = nil
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
if in_reply_to_discussion_id.present?
|
|
|
|
discussion = find_discussion(in_reply_to_discussion_id)
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
return discussion_not_found unless discussion && can?(current_user, :create_note, discussion.noteable)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
discussion = discussion.convert_to_discussion! if discussion.can_convert_to_discussion?
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
params.merge!(discussion.reply_attributes)
|
|
|
|
end
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
# The `confidential` param for notes is deprecated with 15.3
|
|
|
|
# and renamed to `internal`.
|
|
|
|
# We still accept `confidential` until the param gets removed from the API.
|
|
|
|
# Until we have not migrated the database column to `internal` we need to rename
|
|
|
|
# the parameter. Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/367923.
|
|
|
|
params[:confidential] = params[:internal] || params[:confidential]
|
|
|
|
params.delete(:internal)
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
new_note(params, discussion)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def new_note(params, discussion)
|
2017-08-17 22:00:37 +05:30
|
|
|
note = Note.new(params)
|
|
|
|
note.project = project
|
|
|
|
note.author = current_user
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
parent_confidential = discussion&.confidential?
|
|
|
|
can_set_confidential = can?(current_user, :mark_note_as_confidential, note)
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
return discussion_not_found if parent_confidential && !can_set_confidential
|
|
|
|
|
|
|
|
note.confidential = (parent_confidential.nil? && can_set_confidential ? params.delete(:confidential) : parent_confidential)
|
|
|
|
note.resolve_without_save(current_user) if discussion&.resolved?
|
2017-08-17 22:00:37 +05:30
|
|
|
note
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_discussion(discussion_id)
|
|
|
|
if project
|
|
|
|
project.notes.find_discussion(discussion_id)
|
|
|
|
else
|
2019-02-02 18:00:53 +05:30
|
|
|
Note.find_discussion(discussion_id)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
def discussion_not_found
|
|
|
|
note = Note.new
|
|
|
|
note.errors.add(:base, _('Discussion to reply to cannot be found'))
|
|
|
|
note
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|