2018-07-19 14:43:13 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-09 17:24:54 -04:00
|
|
|
class DiscussionEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
2018-06-21 08:22:40 -04:00
|
|
|
include NotesHelper
|
2017-06-09 17:24:54 -04:00
|
|
|
|
|
|
|
expose :id, :reply_id
|
2018-06-28 09:36:26 -04:00
|
|
|
expose :position, if: -> (d, _) { d.diff_discussion? && !d.legacy_diff_discussion? }
|
2018-09-08 02:37:41 -04:00
|
|
|
expose :original_position, if: -> (d, _) { d.diff_discussion? && !d.legacy_diff_discussion? }
|
2018-06-21 08:22:40 -04:00
|
|
|
expose :line_code, if: -> (d, _) { d.diff_discussion? }
|
2017-06-09 17:24:54 -04:00
|
|
|
expose :expanded?, as: :expanded
|
2018-06-21 08:22:40 -04:00
|
|
|
expose :active?, as: :active, if: -> (d, _) { d.diff_discussion? }
|
|
|
|
expose :project_id
|
2017-06-09 17:24:54 -04:00
|
|
|
|
2018-04-03 12:03:00 -04:00
|
|
|
expose :notes do |discussion, opts|
|
|
|
|
request.note_entity.represent(discussion.notes, opts)
|
|
|
|
end
|
2017-06-09 17:24:54 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expose :discussion_path do |discussion|
|
|
|
|
discussion_path(discussion)
|
|
|
|
end
|
|
|
|
|
2017-06-09 17:24:54 -04:00
|
|
|
expose :individual_note?, as: :individual_note
|
2018-06-21 08:22:40 -04:00
|
|
|
expose :resolvable do |discussion|
|
|
|
|
discussion.resolvable?
|
|
|
|
end
|
|
|
|
|
2018-02-27 19:10:43 -05:00
|
|
|
expose :resolved?, as: :resolved
|
2018-06-21 08:22:40 -04:00
|
|
|
expose :resolved_by_push?, as: :resolved_by_push
|
2018-10-01 09:53:08 -04:00
|
|
|
expose :resolved_by, using: NoteUserEntity
|
2018-06-21 08:22:40 -04:00
|
|
|
expose :resolved_at
|
2018-02-27 19:10:43 -05:00
|
|
|
expose :resolve_path, if: -> (d, _) { d.resolvable? } do |discussion|
|
|
|
|
resolve_project_merge_request_discussion_path(discussion.project, discussion.noteable, discussion.id)
|
|
|
|
end
|
2018-04-03 12:03:00 -04:00
|
|
|
expose :resolve_with_issue_path, if: -> (d, _) { d.resolvable? } do |discussion|
|
2018-02-27 19:10:43 -05:00
|
|
|
new_project_issue_path(discussion.project, merge_request_to_resolve_discussions_of: discussion.noteable.iid, discussion_to_resolve: discussion.id)
|
|
|
|
end
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expose :diff_file, using: DiffFileEntity, if: -> (d, _) { d.diff_discussion? }
|
2018-02-27 19:10:43 -05:00
|
|
|
|
|
|
|
expose :diff_discussion?, as: :diff_discussion
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
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-02-27 19:10:43 -05:00
|
|
|
end
|
|
|
|
|
2018-08-16 14:53:33 -04:00
|
|
|
expose :truncated_diff_lines, using: DiffLineEntity, if: -> (d, _) { d.diff_discussion? && d.on_text? && (d.expanded? || render_truncated_diff_lines?) }
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
expose :image_diff_html, if: -> (d, _) { d.diff_discussion? && d.on_image? } do |discussion|
|
2018-02-27 19:10:43 -05:00
|
|
|
diff_file = discussion.diff_file
|
|
|
|
partial = diff_file.new_file? || diff_file.deleted_file? ? 'single_image_diff' : 'replaced_image_diff'
|
|
|
|
options[:context].render_to_string(
|
|
|
|
partial: "projects/diffs/#{partial}",
|
|
|
|
locals: { diff_file: diff_file,
|
|
|
|
position: discussion.position.to_json,
|
|
|
|
click_to_comment: false },
|
|
|
|
layout: false,
|
|
|
|
formats: [:html]
|
|
|
|
)
|
|
|
|
end
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
expose :for_commit?, as: :for_commit
|
|
|
|
expose :commit_id
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def render_truncated_diff_lines?
|
|
|
|
options[:render_truncated_diff_lines]
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_user
|
|
|
|
request.current_user
|
|
|
|
end
|
2017-06-09 17:24:54 -04:00
|
|
|
end
|