discourse/app/serializers/user_bookmark_base_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

69 lines
1.3 KiB
Ruby

# frozen_string_literal: true
class UserBookmarkBaseSerializer < ApplicationSerializer
attributes :id,
:created_at,
:updated_at,
:name,
:reminder_at,
:reminder_at_ics_start,
:reminder_at_ics_end,
:pinned,
:title,
:fancy_title,
:excerpt,
:bookmarkable_id,
:bookmarkable_type,
:bookmarkable_url
def title
raise NotImplementedError
end
def fancy_title
raise NotImplementedError
end
def cooked
raise NotImplementedError
end
def bookmarkable_url
raise NotImplementedError
end
def excerpt
raise NotImplementedError
end
def include_reminder_at_ics_start?
reminder_at.present?
end
def include_reminder_at_ics_end?
reminder_at.present?
end
def reminder_at_ics_start
object.reminder_at_ics
end
def reminder_at_ics_end
object.reminder_at_ics(offset: 1.hour)
end
# Note: This assumes that the bookmarkable has a user attached to it,
# we may need to revisit this assumption at some point.
has_one :user, serializer: BasicUserSerializer, embed: :objects
def user
bookmarkable_user
end
private
def bookmarkable
object.bookmarkable
end
end