fedibird-fe/app/models
ThibG 5524258da9
Fix “Email changed” notification sometimes having wrong e-mail (#13475)
* Fix “Email changed” notification sometimes having wrong e-mail

Fixes #6778

The root of the issue is that `send_devise_notification` was called before
the changes were properly commited to the database, causing the mailer to
pick previous values if running too early.

Devise's documentation provides guidance on how to handle that[1][2], however,
I have found it to not be working, as the following happens, in that order:
- `send_devise_notification` is called for the `email_changed` notification.
  In that case, `changed?` is false and `saved_changes?` is true, so
  if we use the former, we have the same issue.
- the `after_commit` hook is called
- `send_devise_notification` is called for the `confirmation_instructions`
  notification.
  In that case, `changed?` is still false, and `saved_changes?` still true,
  so if we use the latter, that second notification email is simply not
  going to be sent (as we would be queuing the notification *after*
  executing the after_commit hook).

This is because it may be called from either an `after_update` or
`after_commit` hook, the difference not being a call to `save` but the
transaction actually being committed to the database. This may arguably
be a bug in Devise, or Devise's notification.

The proposed workaround is inspired by Devise's documentation but checks
whether a transaction is open to make the call whether to immediately
send the notification or defer it to the `after_commit` hook.

[1]: https://www.rubydoc.info/github/plataformatec/devise/Devise%2FModels%2FAuthenticatable:send_devise_notification
[2]: 406915cb78/lib/devise/models/authenticatable.rb (L133-L194)

* Fix cases when sending notifications without changing the model

* Defer sending if and only if in transaction including current record
2020-04-15 16:13:44 +02:00
..
admin Add ability to filter audit log in admin UI (#13381) 2020-04-03 13:06:34 +02:00
concerns Change local media attachments to perform heavy processing asynchronously (#13210) 2020-03-08 23:56:18 +01:00
form Fix custom emoji category creation silently erroring out on duplicate category (#12647) 2019-12-18 16:56:59 +01:00
web Validate Web::PushSubscription (#11971) 2019-09-27 15:24:13 +02:00
account.rb Add federation support for the "hide network" preference (#11673) 2020-03-09 00:10:29 +01:00
account_alias.rb Fix account aliases page (#13452) 2020-04-13 06:41:43 +02:00
account_conversation.rb Fix crash when conversations have no valid participants (#10078) 2019-02-19 20:00:41 +01:00
account_domain_block.rb Fix crash when saving invalid domain name (#11528) 2019-08-08 23:04:19 +02:00
account_filter.rb Add sorting by username, creation and last activity in moderation view (#13076) 2020-03-08 15:39:13 +01:00
account_identity_proof.rb Fix Keybase verification using wrong domain for remote accounts (#10547) 2019-04-10 20:28:43 +02:00
account_migration.rb Add (back) option to set redirect notice on account without moving followers (#11994) 2019-09-29 05:03:19 +02:00
account_moderation_note.rb Update dependencies for Ruby (2018-04-23) (#7237) 2018-04-23 11:29:17 +02:00
account_pin.rb Add API endpoint to list featured accounts (fixes #8315) (#8317) 2018-08-20 18:46:04 +02:00
account_stat.rb Fix account counters being overwritten by parallel writes (#12045) 2019-10-02 04:59:37 +02:00
account_tag_stat.rb Add profile directory (#9427) 2018-12-06 17:36:11 +01:00
account_warning.rb Add moderation warnings (#9519) 2018-12-22 20:02:09 +01:00
account_warning_preset.rb Add titles to warning presets in admin UI (#13252) 2020-03-12 17:57:59 +01:00
admin.rb Add logging of admin actions (#5757) 2017-11-24 02:05:53 +01:00
announcement.rb Fix PostgreSQL load when linking in announcements (#13250) 2020-04-05 12:51:22 +02:00
announcement_filter.rb Add announcements (#12662) 2020-01-23 22:00:13 +01:00
announcement_mute.rb Add announcements (#12662) 2020-01-23 22:00:13 +01:00
announcement_reaction.rb Add announcements (#12662) 2020-01-23 22:00:13 +01:00
application_record.rb Fix records not being indexed sometimes (#12024) 2019-10-01 01:19:11 +02:00
backup.rb Add announcements (#12662) 2020-01-23 22:00:13 +01:00
block.rb Store URIs of follows, follow requests and blocks for ActivityPub (#7160) 2018-05-04 21:14:34 +02:00
bookmark.rb Add announcements (#12662) 2020-01-23 22:00:13 +01:00
context.rb Refactor JSON templates to be generated with ActiveModelSerializers instead of Rabl (#4090) 2017-07-07 04:02:06 +02:00
conversation.rb Revert "Remove conversation URI (#11423)" (#11424) 2019-07-28 17:47:37 +02:00
conversation_mute.rb Update dependencies for Ruby (2018-04-23) (#7237) 2018-04-23 11:29:17 +02:00
custom_emoji.rb Add announcements (#12662) 2020-01-23 22:00:13 +01:00
custom_emoji_category.rb Add batch actions and categories to admin UI for custom emojis (#11793) 2019-09-09 22:44:17 +02:00
custom_emoji_filter.rb Various fixes and improvements (#12878) 2020-01-20 15:55:03 +01:00
custom_filter.rb Add “account timeline” filter category (#12918) 2020-01-23 21:32:00 +01:00
domain_allow.rb Fix crash when saving invalid domain name (#11528) 2019-08-08 23:04:19 +02:00
domain_block.rb Allow blocking TLDs, and fix TLD blocks not being editable (#12805) 2020-01-08 22:42:05 +01:00
email_domain_block.rb Add option to include resolved DNS records when blacklisting e-mail domains in admin UI (#13254) 2020-03-12 22:35:20 +01:00
export.rb Export and import show_reblogs together with following list (#10495) 2019-04-08 07:28:27 +02:00
favourite.rb Fix records not being indexed sometimes (#12024) 2019-10-01 01:19:11 +02:00
featured_tag.rb Fix featured tags not finding the right tag on save (#11504) 2019-08-07 10:00:58 +02:00
feed.rb Fix non-numbers being passed to Redis and causing an error (#11697) 2019-08-30 02:49:54 +02:00
follow.rb Add specific rate limits for posting and following (#13172) 2020-03-08 15:17:39 +01:00
follow_request.rb Add specific rate limits for posting and following (#13172) 2020-03-08 15:17:39 +01:00
home_feed.rb Fix performance of home feed regeneration (#12084) 2019-10-06 22:11:17 +02:00
identity.rb Change identities id column to a bigint (#9371) 2018-11-27 13:56:25 +01:00
import.rb Add option to overwrite imported data (#9962) 2019-02-03 03:59:51 +01:00
instance.rb Add whitelist mode (#11291) 2019-07-30 11:10:46 +02:00
instance_filter.rb Various fixes and improvements (#12878) 2020-01-20 15:55:03 +01:00
invite.rb Add invite comments (#10465) 2019-08-19 11:40:42 +02:00
invite_filter.rb Various fixes and improvements (#12878) 2020-01-20 15:55:03 +01:00
list.rb Update dependencies for Ruby (2018-04-23) (#7237) 2018-04-23 11:29:17 +02:00
list_account.rb Add abilityto add oneself to lists (#12271) 2019-11-04 13:02:01 +01:00
list_feed.rb Lists (#5703) 2017-11-18 00:16:48 +01:00
marker.rb Add timeline read markers API (#11762) 2019-09-06 13:55:51 +02:00
media_attachment.rb Change tootctl media remove-orphans to work for all classes (#13316) 2020-03-26 01:56:41 +01:00
mention.rb Improve support for aspects/circles (#8950) 2018-10-17 17:13:04 +02:00
mute.rb Update dependencies for Ruby (2018-04-23) (#7237) 2018-04-23 11:29:17 +02:00
notification.rb Add follow_request notification type (#12198) 2019-12-01 17:25:29 +01:00
poll.rb Only normalize local polls (#12515) 2019-12-01 17:24:33 +01:00
poll_vote.rb Add optimistic lock to avoid race conditions when handling votes (#10196) 2019-03-06 19:53:57 +01:00
preview_card.rb Fix preview card image not being re-fetched even if link is re-posted (#11981) 2019-09-28 01:33:16 +02:00
relationship_filter.rb Fix relationships page not showing results in admin UI (#12934) 2020-01-24 00:20:23 +01:00
relay.rb Fix relays UI being available in whitelist/secure mode (#11963) 2019-09-27 02:13:34 +02:00
remote_follow.rb Add account migration UI (#11846) 2019-09-19 20:58:19 +02:00
report.rb Add rate limit for reporting (#13390) 2020-04-05 14:40:08 +02:00
report_filter.rb Various fixes and improvements (#12878) 2020-01-20 15:55:03 +01:00
report_note.rb Fix scope latest of ReportNote (#9630) 2018-12-26 06:38:59 +01:00
scheduled_status.rb Fix deleting a scheduled status immediately deleting media attachments (#9728) 2019-01-06 16:38:40 +01:00
search.rb Refactor JSON templates to be generated with ActiveModelSerializers instead of Rabl (#4090) 2017-07-07 04:02:06 +02:00
session_activation.rb Update dependencies for Ruby (2018-04-23) (#7237) 2018-04-23 11:29:17 +02:00
setting.rb Remove intermediary arrays when creating hash maps from results (#9291) 2018-11-16 15:02:18 +01:00
site_upload.rb Improvements to image upload validation and creation (#10431) 2019-04-01 07:30:46 +02:00
status.rb Fix PostgreSQL load when linking in announcements (#13250) 2020-04-05 12:51:22 +02:00
status_pin.rb Update dependencies for Ruby (2018-04-23) (#7237) 2018-04-23 11:29:17 +02:00
status_stat.rb Reset status cache when status_stat or media_attachment updates (#9119) 2018-10-28 06:42:34 +01:00
tag.rb Fixes featured hashtag setting page erroring out instead of rejecting invalid tags (#12436) 2019-12-17 13:31:56 +01:00
tag_filter.rb Various fixes and improvements (#12878) 2020-01-20 15:55:03 +01:00
tombstone.rb Record deleted(by mod) status to prevent re-appear (#10732) 2019-05-09 22:03:02 +02:00
trending_tags.rb Fix admin setting to auto-approve hashtags not affecting query (#12130) 2019-10-10 02:22:04 +02:00
user.rb Fix “Email changed” notification sometimes having wrong e-mail (#13475) 2020-04-15 16:13:44 +02:00
user_invite_request.rb Add "why do you want to join" field to invite requests (#10524) 2019-04-09 23:06:30 +09:00
web.rb Add extended about page stub 2017-01-13 03:24:41 +01:00