debian-mirror-gitlab/app/serializers/discussion_entity.rb

78 lines
2.6 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
class DiscussionEntity < Grape::Entity
include RequestAwareEntity
2018-11-08 19:23:39 +05:30
include NotesHelper
2018-03-17 18:26:18 +05:30
expose :id, :reply_id
2018-11-08 19:23:39 +05:30
expose :position, if: -> (d, _) { d.diff_discussion? && !d.legacy_diff_discussion? }
2018-11-20 20:47:30 +05:30
expose :original_position, if: -> (d, _) { d.diff_discussion? && !d.legacy_diff_discussion? }
2018-11-08 19:23:39 +05:30
expose :line_code, if: -> (d, _) { d.diff_discussion? }
2018-03-17 18:26:18 +05:30
expose :expanded?, as: :expanded
2018-11-08 19:23:39 +05:30
expose :active?, as: :active, if: -> (d, _) { d.diff_discussion? }
expose :project_id
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
expose :notes do |discussion, opts|
request.note_entity.represent(discussion.notes, opts)
end
2018-03-17 18:26:18 +05:30
2018-11-08 19:23:39 +05:30
expose :discussion_path do |discussion|
discussion_path(discussion)
end
2020-04-22 19:07:51 +05:30
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
2018-03-17 18:26:18 +05:30
expose :individual_note?, as: :individual_note
2018-11-08 19:23:39 +05:30
expose :resolvable do |discussion|
discussion.resolvable?
end
2018-03-27 19:54:05 +05:30
expose :resolved?, as: :resolved
2018-11-08 19:23:39 +05:30
expose :resolved_by_push?, as: :resolved_by_push
expose :resolved_by, using: NoteUserEntity
expose :resolved_at
2018-03-27 19:54:05 +05:30
expose :resolve_path, if: -> (d, _) { d.resolvable? } do |discussion|
resolve_project_merge_request_discussion_path(discussion.project, discussion.noteable, discussion.id)
end
2018-05-09 12:01:36 +05:30
expose :resolve_with_issue_path, if: -> (d, _) { d.resolvable? } do |discussion|
2018-03-27 19:54:05 +05:30
new_project_issue_path(discussion.project, merge_request_to_resolve_discussions_of: discussion.noteable.iid, discussion_to_resolve: discussion.id)
end
2019-02-15 15:39:39 +05:30
expose :diff_file, using: DiscussionDiffFileEntity, if: -> (d, _) { d.diff_discussion? }
2018-03-27 19:54:05 +05:30
expose :diff_discussion?, as: :diff_discussion
2018-11-08 19:23:39 +05:30
expose :truncated_diff_lines_path, if: -> (d, _) { !d.expanded? && !render_truncated_diff_lines? } do |discussion|
project_merge_request_discussion_path(discussion.project, discussion.noteable, discussion)
2018-03-27 19:54:05 +05:30
end
2018-11-20 20:47:30 +05:30
expose :truncated_diff_lines, using: DiffLineEntity, if: -> (d, _) { d.diff_discussion? && d.on_text? && (d.expanded? || render_truncated_diff_lines?) }
2018-11-08 19:23:39 +05:30
expose :for_commit?, as: :for_commit
expose :commit_id
2020-04-22 19:07:51 +05:30
expose :confidential?, as: :confidential
2018-11-08 19:23:39 +05:30
private
def render_truncated_diff_lines?
options[:render_truncated_diff_lines]
end
def current_user
request.current_user
end
2020-04-22 19:07:51 +05:30
def display_merge_ref_discussions?(discussion)
return unless discussion.diff_discussion?
return if discussion.legacy_diff_discussion?
2020-10-24 23:57:45 +05:30
Feature.enabled?(:merge_ref_head_comments, discussion.project, default_enabled: true)
2020-04-22 19:07:51 +05:30
end
2018-03-17 18:26:18 +05:30
end