2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-31 15:31:33 -04:00
|
|
|
module Discussions
|
|
|
|
class UpdateDiffPositionService < BaseService
|
|
|
|
def execute(discussion)
|
2019-07-05 07:03:47 -04:00
|
|
|
old_position = discussion.position
|
|
|
|
result = tracer.trace(old_position)
|
2017-05-31 15:31:33 -04:00
|
|
|
return unless result
|
|
|
|
|
|
|
|
position = result[:position]
|
|
|
|
outdated = result[:outdated]
|
|
|
|
|
|
|
|
discussion.notes.each do |note|
|
|
|
|
if outdated
|
|
|
|
note.change_position = position
|
2017-09-05 11:49:05 -04:00
|
|
|
|
|
|
|
if project.resolve_outdated_diff_discussions?
|
|
|
|
note.resolve_without_save(current_user, resolved_by_push: true)
|
|
|
|
end
|
2017-05-31 15:31:33 -04:00
|
|
|
else
|
|
|
|
note.position = position
|
|
|
|
note.change_position = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Note.transaction do
|
|
|
|
discussion.notes.each do |note|
|
|
|
|
Gitlab::Timeless.timeless(note, &:save)
|
|
|
|
end
|
|
|
|
|
|
|
|
if outdated && current_user
|
|
|
|
SystemNoteService.diff_discussion_outdated(discussion, project, current_user, position)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def tracer
|
|
|
|
@tracer ||= Gitlab::Diff::PositionTracer.new(
|
|
|
|
project: project,
|
|
|
|
old_diff_refs: params[:old_diff_refs],
|
|
|
|
new_diff_refs: params[:new_diff_refs],
|
|
|
|
paths: params[:paths]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|