Commit 00471191 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'id-expose-diff-positions' into 'master'

Expose positions of a diff note

See merge request gitlab-org/gitlab!28950
parents fcdb2633 c7a213cb
......@@ -13,6 +13,7 @@ class DiffDiscussion < Discussion
delegate :position,
:original_position,
:change_position,
:diff_note_positions,
:on_text?,
:on_image?,
......
......@@ -125,7 +125,7 @@ class Note < ApplicationRecord
scope :inc_author, -> { includes(:author) }
scope :inc_relations_for_view, -> do
includes(:project, { author: :status }, :updated_by, :resolved_by, :award_emoji,
{ system_note_metadata: :description_version }, :note_diff_file, :suggestions)
{ system_note_metadata: :description_version }, :note_diff_file, :diff_note_positions, :suggestions)
end
scope :with_notes_filter, -> (notes_filter) do
......
......@@ -20,6 +20,14 @@ class DiscussionEntity < Grape::Entity
discussion_path(discussion)
end
expose :positions, if: -> (d, _) { display_merge_ref_discussions?(d) } do |discussion|
discussion.diff_note_positions.map(&:position)
end
expose :line_codes, if: -> (d, _) { display_merge_ref_discussions?(d) } do |discussion|
discussion.diff_note_positions.map(&:line_code)
end
expose :individual_note?, as: :individual_note
expose :resolvable do |discussion|
discussion.resolvable?
......@@ -59,4 +67,11 @@ class DiscussionEntity < Grape::Entity
def current_user
request.current_user
end
def display_merge_ref_discussions?(discussion)
return unless discussion.diff_discussion?
return if discussion.legacy_diff_discussion?
Feature.enabled?(:merge_ref_head_comments, discussion.project)
end
end
......@@ -73,9 +73,19 @@ describe DiscussionEntity do
:diff_file,
:truncated_diff_lines,
:position,
:positions,
:line_codes,
:line_code,
:active
)
end
context 'diff_head_compare feature is disabled' do
it 'does not expose positions and line_codes attributes' do
stub_feature_flags(merge_ref_head_comments: false)
expect(subject.keys).not_to include(:positions, :line_codes)
end
end
end
end
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