From 3cd12bd6eade68d67687f654bb61683c75e8a45c Mon Sep 17 00:00:00 2001 From: kikito Date: Fri, 15 Apr 2016 16:29:57 +0200 Subject: [PATCH] Simplifies use of registering_with_oauth in User Now we just ignore all validations when saving a user for oauth --- app/models/user.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index f7980c796..113781ef1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -182,11 +182,11 @@ class User < ActiveRecord::Base end def username_required? - !organization? && !erased? && !registering_with_oauth + !organization? && !erased? end def email_required? - !erased? && !registering_with_oauth + !erased? end def has_official_email? @@ -215,11 +215,15 @@ class User < ActiveRecord::Base end def save_requiring_finish_signup - self.update(registering_with_oauth: true) - end - - def save_requiring_finish_signup_without_email - self.update(registering_with_oauth: true, email: nil) + begin + self.registering_with_oauth= true + self.save(validate: false) + # Devise puts unique constraints for the email the db, so we must detect & handle that + rescue ActiveRecord::RecordNotUnique + self.email = nil + self.save(validate: false) + end + true end def ability