summaryrefslogtreecommitdiff
path: root/app/serializers/discussion_entity.rb
blob: bcf6b331192ababaabda36e51df3d056994c10a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

class DiscussionEntity < BaseDiscussionEntity
  expose :notes do |discussion, opts|
    request.note_entity.represent(discussion.notes, opts.merge(with_base_discussion: false))
  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 :resolved?, as: :resolved
  expose :resolved_by_push?, as: :resolved_by_push
  expose :resolved_by, using: NoteUserEntity
  expose :resolved_at

  private

  def current_user
    request.current_user
  end

  def display_merge_ref_discussions?(discussion)
    discussion.diff_discussion? && !discussion.legacy_diff_discussion?
  end
end