BigW Consortium Gitlab

note_entity.rb 1.72 KB
Newer Older
1 2 3 4 5
class NoteEntity < API::Entities::Note
  include RequestAwareEntity

  expose :type

Douwe Maan committed
6
  expose :author, using: NoteUserEntity
7 8 9 10 11 12 13 14 15 16

  expose :human_access do |note|
    note.project.team.human_max_access(note.author_id)
  end

  unexpose :note, as: :body
  expose :note

  expose :redacted_note_html, as: :note_html

Douwe Maan committed
17 18
  expose :last_edited_at, if: -> (note, _) { note.edited? }
  expose :last_edited_by, using: NoteUserEntity, if: -> (note, _) { note.edited? }
19

20 21 22 23
  expose :current_user do
    expose :can_edit do |note|
      Ability.can_edit_note?(request.current_user, note)
    end
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  end

  expose :system_note_icon_name, if: -> (note, _) { note.system? } do |note|
    SystemNoteHelper.system_note_icon_name(note)
  end

  expose :discussion_id do |note|
    note.discussion_id(request.noteable)
  end

  expose :emoji_awardable?, as: :emoji_awardable
  expose :award_emoji, if: -> (note, _) { note.emoji_awardable? }, using: AwardEmojiEntity
  expose :toggle_award_path, if: -> (note, _) { note.emoji_awardable? } do |note|
    if note.for_personal_snippet?
      toggle_award_emoji_snippet_note_path(note.noteable, note)
    else
40
      toggle_award_emoji_project_note_path(note.project, note.id)
41 42 43 44 45 46 47 48 49 50 51
    end
  end

  expose :report_abuse_path do |note|
    new_abuse_report_path(user_id: note.author.id, ref_url: Gitlab::UrlBuilder.build(note))
  end

  expose :path do |note|
    if note.for_personal_snippet?
      snippet_note_path(note.noteable, note)
    else
52
      project_note_path(note.project, note)
53 54 55
    end
  end

56
  expose :attachment, using: NoteAttachmentEntity, if: -> (note, _) { note.attachment? }
57
  expose :delete_attachment_path, if: -> (note, _) { note.attachment? } do |note|
58
    delete_attachment_project_note_path(note.project, note)
59 60
  end
end