discourse/app/serializers/user_bookmark_list_serializer.rb
Martin Brennan 4037cdb6db
FIX: Allow .ics for polymorphic bookmarks (#16694)
We have a .ics endpoint for user bookmarks, this
commit makes it so polymorphic bookmarks work on
that endpoint, using the serializer associated with
the RegisteredBookmarkable.
2022-05-11 09:29:24 +10:00

20 lines
560 B
Ruby

# frozen_string_literal: true
class UserBookmarkListSerializer < ApplicationSerializer
attributes :more_bookmarks_url, :bookmarks
def bookmarks
if SiteSetting.use_polymorphic_bookmarks
object.bookmarks.map do |bm|
bm.registered_bookmarkable.serializer.new(bm, scope: scope, root: false)
end
else
object.bookmarks.map { |bm| UserBookmarkSerializer.new(bm, scope: scope, root: false) }
end
end
def include_more_bookmarks_url?
@include_more_bookmarks_url ||= object.bookmarks.size == object.per_page
end
end