Commit dd8ee395 authored by Phil Hughes's avatar Phil Hughes

Fix error with loading outdated diff lines

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/346758
parent 439b2200
......@@ -57,7 +57,7 @@ class Projects::NotesController < Projects::ApplicationController
def outdated_line_change
diff_lines = Rails.cache.fetch(['note', note.id, 'oudated_line_change'], expires_in: 7.days) do
::MergeRequests::OutdatedDiscussionDiffLinesService.new(project: @project, note: note).execute.to_json
::MergeRequests::OutdatedDiscussionDiffLinesService.new(project: note.noteable.source_project, note: note).execute.to_json
end
render json: diff_lines
......
......@@ -603,6 +603,15 @@ class Note < ApplicationRecord
})
end
def show_outdated_changes?
return false unless for_merge_request?
return false unless Feature.enabled?(:display_outdated_line_diff, noteable.source_project, default_enabled: :yaml)
return false unless system?
return false unless change_position&.line_range
change_position.line_range["end"] || change_position.line_range["start"]
end
private
def system_note_viewable_by?(user)
......
......@@ -51,7 +51,7 @@ class NoteEntity < API::Entities::Note
SystemNoteHelper.system_note_icon_name(note)
end
expose :outdated_line_change_path, if: -> (note, _) { note.system? && note.change_position&.line_range && Feature.enabled?(:display_outdated_line_diff, note.project, default_enabled: :yaml) } do |note|
expose :outdated_line_change_path, if: -> (note, _) { note.show_outdated_changes? } do |note|
outdated_line_change_namespace_project_note_path(namespace_id: note.project.namespace, project_id: note.project, id: note)
end
......
......@@ -14,12 +14,12 @@ module MergeRequests
end
def execute
end_position = position.line_range["end"]
line_position = position.line_range["end"] || position.line_range["start"]
diff_line_index = diff_lines.find_index do |l|
if end_position["new_line"]
l.new_line == end_position["new_line"]
elsif end_position["old_line"]
l.old_line == end_position["old_line"]
if line_position["new_line"]
l.new_line == line_position["new_line"]
elsif line_position["old_line"]
l.old_line == line_position["old_line"]
end
end
initial_line_index = [diff_line_index - OVERFLOW_LINES_COUNT, 0].max
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment