summaryrefslogtreecommitdiff
path: root/app/serializers
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-06-09 16:24:54 -0500
committerFatih Acet <acetfatih@gmail.com>2017-07-21 22:35:24 +0300
commit76c3d2d434d3c550c3de912abc0a5b1dc1455368 (patch)
treecaf45606608993ccd660c8cab45ef387fbf9756e /app/serializers
parentcb2287df0ad9396d1f075bde1c4f6de481d908e6 (diff)
downloadgitlab-ce-76c3d2d434d3c550c3de912abc0a5b1dc1455368.tar.gz
Add full JSON endpoints for issue notes and discussions
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/award_emoji_entity.rb4
-rw-r--r--app/serializers/discussion_entity.rb20
-rw-r--r--app/serializers/discussion_serializer.rb3
-rw-r--r--app/serializers/note_attachment_entity.rb5
-rw-r--r--app/serializers/note_entity.rb58
-rw-r--r--app/serializers/note_serializer.rb3
-rw-r--r--app/serializers/user_entity.rb2
7 files changed, 95 insertions, 0 deletions
diff --git a/app/serializers/award_emoji_entity.rb b/app/serializers/award_emoji_entity.rb
new file mode 100644
index 00000000000..6e03cd02392
--- /dev/null
+++ b/app/serializers/award_emoji_entity.rb
@@ -0,0 +1,4 @@
+class AwardEmojiEntity < Grape::Entity
+ expose :name
+ expose :user, using: API::Entities::UserSafe
+end
diff --git a/app/serializers/discussion_entity.rb b/app/serializers/discussion_entity.rb
new file mode 100644
index 00000000000..cb6c3c23807
--- /dev/null
+++ b/app/serializers/discussion_entity.rb
@@ -0,0 +1,20 @@
+class DiscussionEntity < Grape::Entity
+ include RequestAwareEntity
+
+ expose :id, :reply_id
+ expose :expanded?, as: :expanded
+ expose :author, using: UserEntity
+
+ expose :created_at
+
+ expose :last_updated_at, if: -> (discussion, _) { discussion.updated? }
+ expose :last_updated_by, if: -> (discussion, _) { discussion.updated? }, using: UserEntity
+
+ expose :notes, using: NoteEntity
+
+ expose :individual_note?, as: :individual_note
+
+ expose :can_reply do |discussion|
+ can?(request.current_user, :create_note, discussion.project)
+ end
+end
diff --git a/app/serializers/discussion_serializer.rb b/app/serializers/discussion_serializer.rb
new file mode 100644
index 00000000000..ed5e1224bb2
--- /dev/null
+++ b/app/serializers/discussion_serializer.rb
@@ -0,0 +1,3 @@
+class DiscussionSerializer < BaseSerializer
+ entity DiscussionEntity
+end
diff --git a/app/serializers/note_attachment_entity.rb b/app/serializers/note_attachment_entity.rb
new file mode 100644
index 00000000000..1ad50568ab9
--- /dev/null
+++ b/app/serializers/note_attachment_entity.rb
@@ -0,0 +1,5 @@
+class NoteAttachmentEntity < Grape::Entity
+ expose :url
+ expose :filename
+ expose :image?, as: :image
+end
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
diff --git a/app/serializers/note_serializer.rb b/app/serializers/note_serializer.rb
new file mode 100644
index 00000000000..2afe40d7a34
--- /dev/null
+++ b/app/serializers/note_serializer.rb
@@ -0,0 +1,3 @@
+class NoteSerializer < BaseSerializer
+ entity NoteEntity
+end
diff --git a/app/serializers/user_entity.rb b/app/serializers/user_entity.rb
index 876512b12dc..3bb340065c4 100644
--- a/app/serializers/user_entity.rb
+++ b/app/serializers/user_entity.rb
@@ -1,6 +1,8 @@
class UserEntity < API::Entities::UserBasic
include RequestAwareEntity
+ unexpose :web_url
+
expose :path do |user|
user_path(user)
end