diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-06-10 00:24:54 +0300 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2017-07-21 22:35:24 +0300 |
commit | 76c3d2d434d3c550c3de912abc0a5b1dc1455368 (patch) | |
tree | caf45606608993ccd660c8cab45ef387fbf9756e /app/serializers/note_entity.rb | |
parent | cb2287df0ad9396d1f075bde1c4f6de481d908e6 (diff) |
Add full JSON endpoints for issue notes and discussions
Diffstat (limited to 'app/serializers/note_entity.rb')
-rw-r--r-- | app/serializers/note_entity.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/app/serializers/note_entity.rb b/app/serializers/note_entity.rb new file mode 100644 index 00000000000..7a49ec4ef55 --- /dev/null +++ b/app/serializers/note_entity.rb @@ -0,0 +1,58 @@ +class NoteEntity < API::Entities::Note + include RequestAwareEntity + + expose :type + + expose :author, using: UserEntity + + 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 + + expose :last_edited_at, if: -> (note, _) { note.is_edited? } + expose :last_edited_by, using: UserEntity, if: -> (note, _) { note.is_edited? } + + expose :can_edit do |note| + Ability.can_edit_note?(request.current_user, note) + 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 + toggle_award_emoji_namespace_project_note_path(note.project.namespace, note.project, note.id) + 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 + namespace_project_note_path(note.project.namespace, note.project, note) + end + end + + expose :attachment, using: NoteAttachmentEntity + expose :delete_attachment_path, if: -> (note, _) { note.attachment? } do |note| + delete_attachment_namespace_project_note_path(note.project.namespace, note.project, note) + end +end |