fix: don't set preferred domain on signup/signin unless feature is enabled

This commit is contained in:
Colin Darie 2024-04-08 21:45:04 +02:00
parent 37ae3142ff
commit 3c7018fd31
5 changed files with 20 additions and 12 deletions

View file

@ -40,7 +40,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
end end
super do super do
resource.update_preferred_domain(Current.host) if resource.valid? resource.update_preferred_domain(Current.host) if resource.valid? && helpers.switch_domain_enabled?(request)
end end
end end

View file

@ -13,7 +13,7 @@ class Users::SessionsController < Devise::SessionsController
if user&.valid_password?(params[:user][:password]) if user&.valid_password?(params[:user][:password])
user.update(loged_in_with_france_connect: nil) user.update(loged_in_with_france_connect: nil)
user.update_preferred_domain(Current.host) user.update_preferred_domain(Current.host) if helpers.switch_domain_enabled?(request)
end end
super super

View file

@ -7,14 +7,12 @@ module DomainMigratableConcern
validates :preferred_domain, inclusion: { in: User.preferred_domains.keys, allow_nil: true } validates :preferred_domain, inclusion: { in: User.preferred_domains.keys, allow_nil: true }
def update_preferred_domain(host) def update_preferred_domain(host)
# DIRTY FIX case host
# when ApplicationHelper::APP_HOST
# case host preferred_domain_demarches_gouv_fr!
# when ApplicationHelper::APP_HOST when ApplicationHelper::APP_HOST_LEGACY
# preferred_domain_demarches_gouv_fr! preferred_domain_demarches_simplifiees_fr!
# when ApplicationHelper::APP_HOST_LEGACY end
# preferred_domain_demarches_simplifiees_fr!
# end
end end
end end
end end

View file

@ -44,6 +44,11 @@ describe Users::RegistrationsController, type: :controller do
before do before do
allow(Current).to receive(:host).and_return(ENV.fetch("APP_HOST")) allow(Current).to receive(:host).and_return(ENV.fetch("APP_HOST"))
Flipper.enable(:switch_domain)
end
after do
Flipper.disable(:switch_domain)
end end
context 'when user is correct' do context 'when user is correct' do
@ -54,7 +59,7 @@ describe Users::RegistrationsController, type: :controller do
subject subject
# expect(User.last.preferred_domain_demarches_gouv_fr?).to be_truthy expect(User.last.preferred_domain_demarches_gouv_fr?).to be_truthy
end end
end end

View file

@ -69,12 +69,17 @@ describe Users::SessionsController, type: :controller do
context 'when user has not yet a preferred domain' do context 'when user has not yet a preferred domain' do
before do before do
allow(Current).to receive(:host).and_return(ENV.fetch("APP_HOST")) allow(Current).to receive(:host).and_return(ENV.fetch("APP_HOST"))
Flipper.enable(:switch_domain)
end
after do
Flipper.disable(:switch_domain)
end end
it 'update preferred domain' do it 'update preferred domain' do
subject subject
# expect(user.reload.preferred_domain_demarches_gouv_fr?).to be_truthy expect(user.reload.preferred_domain_demarches_gouv_fr?).to be_truthy
end end
end end
end end