diff options
Diffstat (limited to 'app/serializers/note_entity.rb')
-rw-r--r-- | app/serializers/note_entity.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/serializers/note_entity.rb b/app/serializers/note_entity.rb index ef305195e22..9a96778786b 100644 --- a/app/serializers/note_entity.rb +++ b/app/serializers/note_entity.rb @@ -34,6 +34,10 @@ class NoteEntity < API::Entities::Note expose :can_resolve do |note| note.resolvable? && can?(current_user, :resolve_note, note) end + + expose :can_resolve_discussion do |note| + note.discussion.resolvable? && note.discussion.can_resolve?(current_user) + end end expose :suggestions, using: SuggestionEntity @@ -77,11 +81,25 @@ class NoteEntity < API::Entities::Note expose :cached_markdown_version + # Correctly rendering a note requires some background information about any + # discussion it is part of. This is essential for the notes endpoint, but + # optional for the discussions endpoint, which will include the discussion + # along with the note + expose :discussion, as: :base_discussion, using: BaseDiscussionEntity, if: -> (_, _) { with_base_discussion? } + private + def discussion + @discussion ||= object.to_discussion(request.noteable) + end + def current_user request.current_user end + + def with_base_discussion? + options.fetch(:with_base_discussion, true) + end end NoteEntity.prepend_if_ee('EE::NoteEntity') |