From 9dcca39b5e76e4b3a79667fa7c24130ca5c566ae Mon Sep 17 00:00:00 2001 From: Vishal Jadhav Date: Tue, 27 Feb 2018 11:02:50 -0500 Subject: [PATCH 1/6] fix unit tests --- app/controllers/signup_controller.rb | 13 ++++++++++--- lib/carto/http_header_authentication.rb | 4 ++-- lib/user_account_creator.rb | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/controllers/signup_controller.rb b/app/controllers/signup_controller.rb index 51d9c42bf442..b815493ccfac 100644 --- a/app/controllers/signup_controller.rb +++ b/app/controllers/signup_controller.rb @@ -21,7 +21,7 @@ class SignupController < ApplicationController before_filter :initialize_google_plus_config, :initialize_github_config - def signup + def signup email = params[:email].present? ? params[:email] : nil @user = ::User.new(email: email) end @@ -54,7 +54,7 @@ def create account_creator.with_password(params[:user][:password]) if params[:user][:password].present? end - if account_creator.valid? + if account_creator.valid? trigger_account_creation(account_creator) render 'shared/signup_confirmation' else @@ -168,7 +168,14 @@ def load_organization #subdomain = CartoDB.subdomainless_urls? ? request.host.to_s.gsub(".#{CartoDB.session_domain}", '') : CartoDB.subdomain_from_request(request) #@organization = ::Organization.where(name: subdomain).first if subdomain # You need to have this organization created up-front - @organization = ::Organization.where(name: 'blp-global').first + blp_org = ::Organization.where(name: 'blp-global').first + if (blp_org) + @organization = blp_org + else + subdomain = CartoDB.subdomainless_urls? ? request.host.to_s.gsub(".#{CartoDB.session_domain}", '') : CartoDB.subdomain_from_request(request) + @organization = ::Organization.where(name: subdomain).first if subdomain + end + end def check_organization_quotas diff --git a/lib/carto/http_header_authentication.rb b/lib/carto/http_header_authentication.rb index 5cc10bc4bb85..08dfb5f7797b 100644 --- a/lib/carto/http_header_authentication.rb +++ b/lib/carto/http_header_authentication.rb @@ -32,8 +32,8 @@ def autocreation_enabled? def autocreation_valid?(request) puts "user-auto-creation : autocreation_valid" - autocreation_enabled? && field(request) == 'username' - #autocreation_enabled? && field(request) == 'email' + #autocreation_enabled? && field(request) == 'username' + autocreation_enabled? && field(request) == 'email' end def identity(request) diff --git a/lib/user_account_creator.rb b/lib/user_account_creator.rb index df3250bea69f..e68fe1d0e443 100644 --- a/lib/user_account_creator.rb +++ b/lib/user_account_creator.rb @@ -197,7 +197,7 @@ def enqueue_creation(current_controller) puts "user-auto-creation : save the user_creation info" blp_user_info = build_blp_user_info - blp_user_info.save + blp_user_info.save if blp_user_info.uuid puts "user-auto-creation : saved the blp_user_info" From efab2c53dcc30ff404c222c84f51b1f6334e46be Mon Sep 17 00:00:00 2001 From: Vishal Jadhav Date: Tue, 27 Feb 2018 14:12:06 -0800 Subject: [PATCH 2/6] fix the unit test flow, persitent-id is used for Bloomberg flow --- app/controllers/signup_controller.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/signup_controller.rb b/app/controllers/signup_controller.rb index b815493ccfac..21a826fe7f35 100644 --- a/app/controllers/signup_controller.rb +++ b/app/controllers/signup_controller.rb @@ -98,9 +98,12 @@ def create_http_authentication logger.info "user-auto-creation : checking with_http_headers" account_creator = CartoDB::UserAccountCreator. - new(Carto::UserCreation::CREATED_VIA_HTTP_AUTENTICATION). -# with_email_only(authenticator.email(request)) - with_http_headers(request.headers) + new(Carto::UserCreation::CREATED_VIA_HTTP_AUTENTICATION) + if (request.headers['persistent-id']) + account_creator.with_http_headers(request.headers) + else + account_creator.with_email_only(authenticator.email(request)) + end account_creator = account_creator.with_organization(@organization) if @organization From 95f4df04c7912a85a2235d45580f80cc93a27987 Mon Sep 17 00:00:00 2001 From: Vishal Jadhav Date: Wed, 28 Feb 2018 05:52:41 -0800 Subject: [PATCH 3/6] fix whitespaces --- app/controllers/signup_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/signup_controller.rb b/app/controllers/signup_controller.rb index 21a826fe7f35..e2f9cc27ebb7 100644 --- a/app/controllers/signup_controller.rb +++ b/app/controllers/signup_controller.rb @@ -21,7 +21,7 @@ class SignupController < ApplicationController before_filter :initialize_google_plus_config, :initialize_github_config - def signup + def signup email = params[:email].present? ? params[:email] : nil @user = ::User.new(email: email) end @@ -54,7 +54,7 @@ def create account_creator.with_password(params[:user][:password]) if params[:user][:password].present? end - if account_creator.valid? + if account_creator.valid? trigger_account_creation(account_creator) render 'shared/signup_confirmation' else From 2d95a4a3414d8e2e9fa32b2a1ad74072e1b2ac9b Mon Sep 17 00:00:00 2001 From: Vishal Jadhav Date: Wed, 28 Feb 2018 06:59:33 -0800 Subject: [PATCH 4/6] username is a valid filed for Bloomberg --- lib/carto/http_header_authentication.rb | 3 +-- spec/requests/signup_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/carto/http_header_authentication.rb b/lib/carto/http_header_authentication.rb index 08dfb5f7797b..d3e5769b3ab4 100644 --- a/lib/carto/http_header_authentication.rb +++ b/lib/carto/http_header_authentication.rb @@ -32,8 +32,7 @@ def autocreation_enabled? def autocreation_valid?(request) puts "user-auto-creation : autocreation_valid" - #autocreation_enabled? && field(request) == 'username' - autocreation_enabled? && field(request) == 'email' + autocreation_enabled? && (field(request) == 'username' || field(request) == 'email') end def identity(request) diff --git a/spec/requests/signup_controller_spec.rb b/spec/requests/signup_controller_spec.rb index bc582d1d6756..76964a2cad7a 100644 --- a/spec/requests/signup_controller_spec.rb +++ b/spec/requests/signup_controller_spec.rb @@ -287,7 +287,7 @@ end it 'returns 500 if http authentication is not set to email' do - ['auto', 'id', 'username'].each do |field| + ['auto', 'id'].each do |field| stub_http_header_authentication_configuration(autocreation: true, field: field) get signup_http_authentication_url response.status.should == 500 From e11b47c45dc8f6b2ed261d37bbe8abdbf486c828 Mon Sep 17 00:00:00 2001 From: Vishal Jadhav Date: Wed, 28 Feb 2018 07:45:51 -0800 Subject: [PATCH 5/6] fix the test for non-org memeber, change the search test as per the UI --- spec/requests/sessions_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/sessions_controller_spec.rb b/spec/requests/sessions_controller_spec.rb index 3ba2bc4db3ec..e71330b0e6af 100644 --- a/spec/requests/sessions_controller_spec.rb +++ b/spec/requests/sessions_controller_spec.rb @@ -509,7 +509,7 @@ def create_admin_user(organization) Carto::Organization.any_instance.stubs(:auth_enabled?).returns(true) post create_session_url(user_domain: @organization.name, email: @user.username, password: @user.password) response.status.should == 200 - response.body.should include 'Not a member' + response.body.should include 'The user is not part of the organization' end end From c7767e1c5c0f10e28bb05c2f225da9b1ce70ebd6 Mon Sep 17 00:00:00 2001 From: Vishal Jadhav Date: Fri, 16 Mar 2018 13:28:23 -0400 Subject: [PATCH 6/6] remove comments --- app/controllers/signup_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/signup_controller.rb b/app/controllers/signup_controller.rb index e2f9cc27ebb7..423596478c26 100644 --- a/app/controllers/signup_controller.rb +++ b/app/controllers/signup_controller.rb @@ -168,8 +168,6 @@ def initialize_github_config end def load_organization - #subdomain = CartoDB.subdomainless_urls? ? request.host.to_s.gsub(".#{CartoDB.session_domain}", '') : CartoDB.subdomain_from_request(request) - #@organization = ::Organization.where(name: subdomain).first if subdomain # You need to have this organization created up-front blp_org = ::Organization.where(name: 'blp-global').first if (blp_org)