diff --git a/back/app/models/user.rb b/back/app/models/user.rb index 017c874be9d1..f2b1a6a80d75 100644 --- a/back/app/models/user.rb +++ b/back/app/models/user.rb @@ -517,7 +517,7 @@ def reset_confirmation_and_counts end def should_send_confirmation_email? - confirmation_required? && email_confirmation_code_sent_at.nil? + confirmation_required? && email_confirmation_code_sent_at.nil? && (PhoneService.new.encoded_phone_or_email?(email) == :email) end def email_confirmation_code_expiration_at diff --git a/back/app/services/side_fx_user_service.rb b/back/app/services/side_fx_user_service.rb index d13fab9d3ceb..e8c7d91dd953 100644 --- a/back/app/services/side_fx_user_service.rb +++ b/back/app/services/side_fx_user_service.rb @@ -13,7 +13,7 @@ def after_create(user, current_user) LogActivityJob.set(wait: 5.seconds).perform_later(user, 'admin_rights_given', current_user, user.created_at.to_i) end user.create_email_campaigns_unsubscription_token - RequestConfirmationCodeJob.perform_later(user) if user.should_send_confirmation_email? + RequestConfirmationCodeJob.perform_now(user) if user.should_send_confirmation_email? AdditionalSeatsIncrementer.increment_if_necessary(user, current_user) if user.roles_previously_changed? end @@ -29,7 +29,7 @@ def after_update(user, current_user) AdditionalSeatsIncrementer.increment_if_necessary(user, current_user) if user.roles_previously_changed? UpdateMemberCountJob.perform_later - RequestConfirmationCodeJob.perform_later(user) if user.should_send_confirmation_email? + RequestConfirmationCodeJob.perform_now(user) if user.should_send_confirmation_email? end def before_destroy(user, _current_user) diff --git a/back/spec/acceptance/users_spec.rb b/back/spec/acceptance/users_spec.rb index 92fd890d650c..e99495272652 100644 --- a/back/spec/acceptance/users_spec.rb +++ b/back/spec/acceptance/users_spec.rb @@ -156,7 +156,7 @@ context 'when the user_confirmation module is active' do before do - allow(RequestConfirmationCodeJob).to receive(:perform_later) + allow(RequestConfirmationCodeJob).to receive(:perform_now) SettingsService.new.activate_feature! 'user_confirmation' end @@ -170,7 +170,7 @@ assert_status 201 json_response = json_parse(response_body) user = User.order(:created_at).last - expect(RequestConfirmationCodeJob).to have_received(:perform_later).with(user).once + expect(RequestConfirmationCodeJob).to have_received(:perform_now).with(user).once expect(json_response.dig(:data, :attributes, :confirmation_required)).to be true # when no custom fields end end @@ -292,7 +292,7 @@ let(:locale) { 'en' } before do - allow(RequestConfirmationCodeJob).to receive(:perform_later) + allow(RequestConfirmationCodeJob).to receive(:perform_now) SettingsService.new.activate_feature! 'user_confirmation' end @@ -300,7 +300,7 @@ example_request 'User successfully created and requires confirmation' do assert_status 201 user = User.order(:created_at).last - expect(RequestConfirmationCodeJob).to have_received(:perform_later).with(user).once + expect(RequestConfirmationCodeJob).to have_received(:perform_now).with(user).once expect(response_data.dig(:attributes, :confirmation_required)).to be(true) end @@ -319,7 +319,7 @@ do_request assert_status 200 expect(response_data.dig(:attributes, :confirmation_required)).to be(true) - expect(RequestConfirmationCodeJob).to have_received(:perform_later).with(existing_user).once + expect(RequestConfirmationCodeJob).to have_received(:perform_now).with(existing_user).once end context 'when the request tries to pass additional changed attributes', document: false do