mirror of
https://github.com/discourse/discourse.git
synced 2024-11-21 16:38:15 -06:00
e58e7a49f5
Followup 76c56c8284
The change introduced above made it so the expired
bookmark reminders were cleared when using the bulk
action menu for bookmarks. However this also affected
clearing reminders for bookmarks when sending notifications.
When clearing bookmark reminders after sending notifications,
we take into account the auto delete preference:
* never - The bookmark `reminder_at` date should not be cleared,
and the bookmark is kept.
* clear_reminder - The bookmark `reminder_at` date is cleared and
the bookmark is kept
The `never` option made it so "expired" bookmark reminder show
on the user's bookmark list.
This commit fixes the change from the other commit and only
forces clearing of `reminder_at` if using the bookmark bulk
action service.
61 lines
1.2 KiB
Ruby
61 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class BookmarksBulkAction
|
|
def initialize(user, bookmark_ids, operation, options = {})
|
|
@user = user
|
|
@bookmark_ids = bookmark_ids
|
|
@operation = operation
|
|
@changed_ids = []
|
|
@options = options
|
|
end
|
|
|
|
def self.operations
|
|
@operations ||= %w[clear_reminder delete]
|
|
end
|
|
|
|
def perform!
|
|
if BookmarksBulkAction.operations.exclude?(@operation[:type])
|
|
raise Discourse::InvalidParameters.new(:operation)
|
|
end
|
|
|
|
case @operation[:type]
|
|
when "clear_reminder"
|
|
clear_reminder
|
|
when "delete"
|
|
delete
|
|
end
|
|
|
|
@changed_ids.sort
|
|
end
|
|
|
|
private
|
|
|
|
def delete
|
|
@bookmark_ids.each do |bookmark_id|
|
|
if guardian.can_delete?(bookmark_id)
|
|
BookmarkManager.new(@user).destroy(bookmark_id)
|
|
@changed_ids << bookmark_id
|
|
end
|
|
end
|
|
end
|
|
|
|
def clear_reminder
|
|
bookmarks.each do |bookmark|
|
|
if guardian.can_edit?(bookmark)
|
|
bookmark.clear_reminder!(force_clear_reminder_at: true)
|
|
@changed_ids << bookmark.id
|
|
else
|
|
raise Discourse::InvalidAccess.new
|
|
end
|
|
end
|
|
end
|
|
|
|
def guardian
|
|
@guardian ||= Guardian.new(@user)
|
|
end
|
|
|
|
def bookmarks
|
|
@bookmarks ||= Bookmark.where(id: @bookmark_ids)
|
|
end
|
|
end
|