mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 01:56:58 +08:00
FEATURE: Polymorphic bookmarks pt. 1 (CRUD) (#16308)
This commit introduces a new use_polymorphic_bookmarks site setting that is default false and hidden, that will be used to help continuous development of polymorphic bookmarks. This setting **should not** be enabled anywhere in production yet, it is purely for local development. This commit uses the setting to enable create/update/delete actions for polymorphic bookmarks on the server and client side. The bookmark interactions on topics/posts are all usable. Listing, searching, sending bookmark reminders, and other edge cases will be handled in subsequent PRs. Comprehensive UI tests will be added in the final PR -- we already have them for regular bookmarks, so it will just be a matter of changing them to be for polymorphic bookmarks.
This commit is contained in:
@ -4,22 +4,42 @@ class BookmarksController < ApplicationController
|
||||
requires_login
|
||||
|
||||
def create
|
||||
params.require(:post_id)
|
||||
if SiteSetting.use_polymorphic_bookmarks
|
||||
params.require(:bookmarkable_id)
|
||||
params.require(:bookmarkable_type)
|
||||
else
|
||||
params.require(:post_id)
|
||||
end
|
||||
|
||||
RateLimiter.new(
|
||||
current_user, "create_bookmark", SiteSetting.max_bookmarks_per_day, 1.day.to_i
|
||||
).performed!
|
||||
|
||||
bookmark_manager = BookmarkManager.new(current_user)
|
||||
bookmark = bookmark_manager.create(
|
||||
post_id: params[:post_id],
|
||||
|
||||
create_params = {
|
||||
name: params[:name],
|
||||
reminder_at: params[:reminder_at],
|
||||
for_topic: params[:for_topic] == "true",
|
||||
options: {
|
||||
auto_delete_preference: params[:auto_delete_preference] || 0
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if SiteSetting.use_polymorphic_bookmarks
|
||||
bookmark = bookmark_manager.create_for(
|
||||
**create_params.merge(
|
||||
bookmarkable_id: params[:bookmarkable_id],
|
||||
bookmarkable_type: params[:bookmarkable_type]
|
||||
)
|
||||
)
|
||||
else
|
||||
bookmark = bookmark_manager.create(
|
||||
**create_params.merge(
|
||||
post_id: params[:post_id],
|
||||
for_topic: params[:for_topic] == "true",
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
if bookmark_manager.errors.empty?
|
||||
return render json: success_json.merge(id: bookmark.id)
|
||||
@ -30,8 +50,8 @@ class BookmarksController < ApplicationController
|
||||
|
||||
def destroy
|
||||
params.require(:id)
|
||||
result = BookmarkManager.new(current_user).destroy(params[:id])
|
||||
render json: success_json.merge(result)
|
||||
destroyed_bookmark = BookmarkManager.new(current_user).destroy(params[:id])
|
||||
render json: success_json.merge(BookmarkManager.bookmark_metadata(destroyed_bookmark, current_user))
|
||||
end
|
||||
|
||||
def update
|
||||
|
Reference in New Issue
Block a user