File tree 2 files changed +26
-2
lines changed 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -29,8 +29,11 @@ def connect_provider
29
29
30
30
# Check if credential is already in use
31
31
existing_credential_holder = User . find_by_credential type : provider , id : auth_hash . uid
32
- if existing_credential_holder && existing_credential_holder != current_user
33
- if existing_credential_holder . has_activity?
32
+ if existing_credential_holder
33
+ if existing_credential_holder == current_user
34
+ flash . notice = I18n . t ( 'auth.already_linked' , provider : I18n . t ( "auth.#{ provider } " ) )
35
+ return redirect_to edit_user_registration_path
36
+ elsif existing_credential_holder . has_activity?
34
37
# Linking is not possible and takeover is not possible
35
38
# Display a custom error message explaining the credential is already
36
39
# tied to an account, and what we can do about it.
Original file line number Diff line number Diff line change @@ -901,6 +901,27 @@ class OmniauthCallbacksControllerTest < ActionController::TestCase
901
901
assert_equal expected_error , flash . alert
902
902
end
903
903
904
+ test "connect_provider: Presents no-op message if the provided credentials are already linked to user's account" do
905
+ # Given the current user already has credential X
906
+ user = create :user , :multi_auth_migrated
907
+ credential = create :google_authentication_option , user : user
908
+ assert_equal 1 , user . authentication_options . count
909
+
910
+ # When I attempt to add credential X
911
+ link_credential user ,
912
+ type : credential . credential_type ,
913
+ id : credential . authentication_id
914
+
915
+ # Then I should have the same authentication options
916
+ user . reload
917
+ assert_equal 1 , user . authentication_options . count
918
+
919
+ # And receive a friendly notice about already having the credential
920
+ assert_redirected_to 'http://test.host/users/edit'
921
+ expected_notice = I18n . t ( 'auth.already_linked' , provider : I18n . t ( "auth.google_oauth2" ) )
922
+ assert_equal expected_notice , flash . notice
923
+ end
924
+
904
925
private
905
926
906
927
def set_oauth_takeover_session_variables ( provider , user )
You can’t perform that action at this time.
0 commit comments