From 5ea8d7690380555426de98d904c9c145e7a296f0 Mon Sep 17 00:00:00 2001 From: kikito Date: Wed, 13 Jan 2016 11:32:29 +0100 Subject: [PATCH] Rename find_for_oauth param and refactor user expression --- app/models/user.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 6906f21c3..8a227b82c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -52,17 +52,14 @@ class User < ActiveRecord::Base before_validation :clean_document_number - def self.find_for_oauth(auth, signed_in_resource = nil) - # Get the identity and user if they exist - identity = Identity.find_for_oauth(auth) + def self.find_for_oauth(auth, current_user) identity = Identity.first_or_create_from_oauth(auth) - # If a signed_in_resource is provided it always overrides the existing user + # If a current is provided it always overrides the existing user # to prevent the identity being locked with accidentally created accounts. # Note that this may leave zombie accounts (with no associated identity) which # can be cleaned up at a later date. - user = signed_in_resource ? signed_in_resource : identity.user - user ||= first_or_create_for_oauth(auth) + user = current_user || identity.user || first_or_create_for_oauth(auth) identity.update(user: user) user