From d1e50f2ef6724f8e1d782817dd94e4f1c03f5820 Mon Sep 17 00:00:00 2001 From: farhatahmad <35435341+farhatahmad@users.noreply.github.com> Date: Tue, 23 Jul 2019 11:02:25 -0400 Subject: [PATCH] GRN2-213: Cleaned up omniauth user create (#682) * Fixed omniauth user create * Added readonly exception --- app/models/user.rb | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index f7af9a35..a3428a7c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -55,14 +55,31 @@ class User < ApplicationRecord def from_omniauth(auth) # Provider is the customer name if in loadbalanced config mode provider = auth['provider'] == "bn_launcher" ? auth['info']['customer'] : auth['provider'] - find_or_initialize_by(social_uid: auth['uid'], provider: provider).tap do |u| - u.name = auth_name(auth) unless u.name - u.username = auth_username(auth) unless u.username - u.email = auth_email(auth) - u.image = auth_image(auth) - u.email_verified = true - u.save! + u = find_by(social_uid: auth['uid'], provider: provider) + + if ENV["MAINTENANCE_MODE"] == "readonly" + raise ActiveRecord::ReadOnlyRecord if u.nil? + + return u end + + return User.create( + name: auth_name(auth), + username: auth_username(auth), + email: auth_email(auth), + social_uid: auth['uid'], + provider: provider, + image: auth_image(auth), + email_verified: true + ) if u.nil? + + u.name = auth_name(auth) unless u.name + u.username = auth_username(auth) unless u.username + u.email = auth_email(auth) + u.image = auth_image(auth) + u.email_verified = true + u.save! + u end private