Fix broadcast message dismissal cookie not restoring upon login
What does this MR do and why?
We introduced a feature to restore broadcast message dismissals cookies from database records upon login in !151056 (merged).
However, it has a bug: it can't get all the valid dismissals because we are getting current active broadcast message ids with System::BroadcastMessage.current
, which won't be able to get any broadcast messages that have a target_path requirement upon login, and passing those ids to finder to retrieve dismissal db records. More details here: #472290 (comment 2017725757)
This MR propose a fix that instead of using current broadcast message ids to find dismissals, we just get all the dismissals from a user that are not expired.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
Reproduce Bug
- Checkout master
- Create a dismissible broadcast message (URL
/admin/broadcast_messages
) with Target Path requirement:*/issues/*
- Go to any issue, dismiss the broadcast message
- Logout and back in again
- Go to any issue, and see the broadcast message again because the cookie is not restored.
Verify Fix
- Checkout this branch
- Enable feature flag:
echo "Feature.enable :new_broadcast_message_dismissal" | gdk rails c
- Repeat the steps above to create and dismiss a broadcast message
- Logout and back in to verify that the dismissal cookie is restored, and the broadcast message is not present.
SQL
SELECT
"user_broadcast_message_dismissals".*
FROM
"user_broadcast_message_dismissals"
WHERE (expires_at > '2024-08-02 15:22:35.657320')
AND "user_broadcast_message_dismissals"."user_id" = 102
Query Plan
https://console.postgres.ai/shared/f33aedff-7a25-4f60-b5ba-a0914aa22af6
Related to #472290 (closed)