FIX: Allow users to add emails which were deleted before

This commit is contained in:
Dan Ungureanu
2020-06-11 14:53:41 +03:00
parent dd85d44dda
commit b7e70850e4
3 changed files with 22 additions and 1 deletions

View File

@@ -6,8 +6,10 @@ class EmailLog < ActiveRecord::Base
admin_login admin_login
confirm_new_email confirm_new_email
confirm_old_email confirm_old_email
confirm_old_email_add
forgot_password forgot_password
notify_old_email notify_old_email
notify_old_email_add
signup signup
signup_after_approval signup_after_approval
} }

View File

@@ -54,7 +54,7 @@ class EmailUpdater
change_req.new_email = email change_req.new_email = email
end end
if change_req.change_state.blank? if change_req.change_state.blank? || change_req.change_state == EmailChangeRequest.states[:complete]
change_req.change_state = if @user.staff? change_req.change_state = if @user.staff?
# Staff users must confirm their old email address first. # Staff users must confirm their old email address first.
EmailChangeRequest.states[:authorizing_old] EmailChangeRequest.states[:authorizing_old]

View File

@@ -168,6 +168,25 @@ describe EmailUpdater do
expect(@change_req.change_state).to eq(EmailChangeRequest.states[:complete]) expect(@change_req.change_state).to eq(EmailChangeRequest.states[:complete])
end end
end end
context 'that was deleted before' do
it 'works' do
Jobs.expects(:enqueue).once.with(:critical_user_email, has_entries(type: :notify_old_email_add, to_address: old_email))
updater.confirm(@change_req.new_email_token.token)
expect(user.reload.user_emails.pluck(:email)).to contain_exactly(old_email, new_email)
user.user_emails.where(email: new_email).delete_all
expect(user.reload.user_emails.pluck(:email)).to contain_exactly(old_email)
Jobs.expects(:enqueue).once.with(:critical_user_email, has_entries(type: :confirm_new_email, to_address: new_email))
updater.change_to(new_email, add: true)
@change_req = user.email_change_requests.first
Jobs.expects(:enqueue).once.with(:critical_user_email, has_entries(type: :notify_old_email_add, to_address: old_email))
updater.confirm(@change_req.new_email_token.token)
expect(user.reload.user_emails.pluck(:email)).to contain_exactly(old_email, new_email)
end
end
end end
end end