mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 07:43:43 +08:00
3e4621c2cb
This pull request follows on from https://github.com/discourse/discourse/pull/16308. This one does the following:
* Changes `BookmarkQuery` to allow for querying more than just Post and Topic bookmarkables
* Introduces a `Bookmark.register_bookmarkable` method which requires a model, serializer, fields and preload includes for searching. These registered `Bookmarkable` types are then used when validating new bookmarks, and also when determining which serializer to use for the bookmark list. The `Post` and `Topic` bookmarkables are registered by default.
* Adds new specific types for Post and Topic bookmark serializers along with preloading of associations in `UserBookmarkList`
* Changes to the user bookmark list template to allow for more generic bookmarkable types alongside the Post and Topic ones which need to display in a particular way
All of these changes are gated behind the `use_polymorphic_bookmarks` site setting, apart from the .hbs changes where I have updated the original `UserBookmarkSerializer` with some stub methods.
Following this PR will be several plugin PRs (for assign, chat, encrypt) that will register their own bookmarkable types or otherwise alter the bookmark serializers in their own way, also gated behind `use_polymorphic_bookmarks`.
This commit also removes `BookmarkQuery.preloaded_custom_fields` and the functionality surrounding it. It was added in 0cd502a558
but only used by one plugin (discourse-assign) where it has since been removed, and is now used by no plugins. We don't need it anymore.
42 lines
981 B
Ruby
42 lines
981 B
Ruby
# frozen_string_literal: true
|
|
|
|
Fabricator(:bookmark) do
|
|
user
|
|
post {
|
|
if !SiteSetting.use_polymorphic_bookmarks
|
|
Fabricate(:post)
|
|
end
|
|
}
|
|
name "This looked interesting"
|
|
reminder_at { 1.day.from_now.iso8601 }
|
|
reminder_set_at { Time.zone.now }
|
|
bookmarkable {
|
|
if SiteSetting.use_polymorphic_bookmarks
|
|
Fabricate(:post)
|
|
end
|
|
}
|
|
|
|
# TODO (martin) [POLYBOOK] Not relevant once polymorphic bookmarks are implemented.
|
|
before_create do |bookmark|
|
|
if bookmark.bookmarkable_id.present? || bookmark.bookmarkable.present?
|
|
bookmark.post = nil
|
|
bookmark.post_id = nil
|
|
bookmark.for_topic = false
|
|
end
|
|
end
|
|
end
|
|
|
|
Fabricator(:bookmark_next_business_day_reminder, from: :bookmark) do
|
|
reminder_at do
|
|
date = if Time.zone.now.friday?
|
|
Time.zone.now + 3.days
|
|
elsif Time.zone.now.saturday?
|
|
Time.zone.now + 2.days
|
|
else
|
|
Time.zone.now + 1.day
|
|
end
|
|
date.iso8601
|
|
end
|
|
reminder_set_at { Time.zone.now }
|
|
end
|