FIX: Bookmark reminder was clearing incorrectly (#28506)

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.
This commit is contained in:
Martin Brennan
2024-08-26 09:17:39 +10:00
committed by GitHub
parent 274e18622e
commit e58e7a49f5
5 changed files with 47 additions and 33 deletions

View File

@@ -11,7 +11,7 @@ class BookmarkReminderNotificationHandler
return if bookmark.blank?
Bookmark.transaction do
if !bookmark.registered_bookmarkable.can_send_reminder?(bookmark)
clear_reminder
bookmark.clear_reminder!
else
bookmark.registered_bookmarkable.send_reminder_notification(bookmark)
@@ -19,18 +19,8 @@ class BookmarkReminderNotificationHandler
BookmarkManager.new(bookmark.user).destroy(bookmark.id)
end
clear_reminder
bookmark.clear_reminder!
end
end
end
def clear_reminder
Rails.logger.debug(
"Clearing bookmark reminder for bookmark_id #{bookmark.id}. reminder at: #{bookmark.reminder_at}",
)
bookmark.reminder_at = nil if bookmark.auto_clear_reminder_when_reminder_sent?
bookmark.clear_reminder!
end
end

View File

@@ -17,27 +17,33 @@ class BookmarksBulkAction
if BookmarksBulkAction.operations.exclude?(@operation[:type])
raise Discourse::InvalidParameters.new(:operation)
end
# careful these are private methods, we need send
send(@operation[:type])
case @operation[:type]
when "clear_reminder"
clear_reminder
when "delete"
delete
end
@changed_ids.sort
end
private
def delete
@bookmark_ids.each do |b_id|
if guardian.can_delete?(b_id)
BookmarkManager.new(@user).destroy(b_id)
@changed_ids << b_id
@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 |b|
if guardian.can_edit?(b)
BookmarkReminderNotificationHandler.new(b).clear_reminder
@changed_ids << b.id
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