Skip to content

Commit f88546d

Browse files
committed
Special error if credentials are in use by account with progress
1 parent 95caca6 commit f88546d

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

dashboard/app/controllers/omniauth_callbacks_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def connect_provider
3434
# Linking is not possible and takeover is not possible
3535
# Display a custom error message explaining the credential is already
3636
# tied to an account, and what we can do about it.
37+
flash.alert = I18n.t('auth.already_in_use', provider: I18n.t("auth.#{provider}"))
38+
return redirect_to edit_user_registration_path
3739
else
3840
# The credential is tied to an unused account.
3941
# Destroy the unused account and proceed to link this one.

dashboard/test/controllers/omniauth_callbacks_controller_test.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,15 +872,33 @@ class OmniauthCallbacksControllerTest < ActionController::TestCase
872872
end
873873

874874
test "connect_provider: Refuses to link credential if there is an account with matching credential that has activity" do
875+
user = create :user, :multi_auth_migrated
876+
875877
# Given there exists another user
876878
# having credential X
877879
# and having activity
880+
other_user = create :user, :multi_auth_migrated
881+
credential = create :google_authentication_option, user: other_user
882+
create :user_level, user: other_user, best_result: ActivityConstants::MINIMUM_PASS_RESULT
883+
assert other_user.has_activity?
878884

879885
# When I attempt to add credential X
886+
link_credential user,
887+
type: credential.credential_type,
888+
id: credential.authentication_id
889+
890+
# Then the other user should not be destroyed
891+
other_user.reload
892+
refute other_user.deleted?
880893

881-
# Then I should fail to add credential X
882-
# And the other user should not be destroyed
883-
# And I should receive a helpful error message about the credential already being in use.
894+
# And I should fail to add credential X
895+
user.reload
896+
assert_empty user.authentication_options
897+
898+
# And receive a helpful error message about the credential already being in use.
899+
assert_redirected_to 'http://test.host/users/edit'
900+
expected_error = I18n.t('auth.already_in_use', provider: I18n.t("auth.google_oauth2"))
901+
assert_equal expected_error, flash.alert
884902
end
885903

886904
private

0 commit comments

Comments
 (0)