Skip to content

Commit

Permalink
[issue-4351] move UserInfoChangedMailer call outside super to prevent…
Browse files Browse the repository at this point in the history
… race condition
  • Loading branch information
Tooyosi committed Aug 16, 2024
1 parent 883d2e5 commit aae5b02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ def me

def update
prev_email = user.email
email_changed = false
super do |user|
if user.email_changed?
user.update(valid_email: true)
UserInfoChangedMailerWorker.perform_async(user.id, 'email', prev_email)
end
email_changed = user.email_changed?
end

if email_changed
user.update(valid_email: true)
UserInfoChangedMailerWorker.perform_async(user.id, 'email', prev_email)
end

end

def destroy
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/user_info_changed_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ class UserInfoChangedMailer < ApplicationMailer
def user_info_changed(user, info, previous_email=nil)
@user = user
@recipient_emails = [user.email]
@recipient_emails << previous_email if previous_email.present? && info == 'email'

case info
when "email"
subject = "Your Zooniverse email address has been changed"
template = "email_changed"
@recipient_emails << previous_email if previous_email
when "password"
subject = "Your Zooniverse password has been changed"
template = "password_changed"
Expand Down

0 comments on commit aae5b02

Please sign in to comment.