Merge pull request #9887 from mfo/US/fix-fci-missing-device-callback

Correctif: ETQ usager invité, lorsque je crée mon compte via FC, je ne retrouve pas mes invitations
This commit is contained in:
mfo 2024-01-04 06:15:14 +00:00 committed by GitHub
commit 9df978f6fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View file

@ -12,6 +12,7 @@ class FranceConnectInformation < ApplicationRecord
password: Devise.friendly_token[0, 20], password: Devise.friendly_token[0, 20],
confirmed_at: Time.zone.now confirmed_at: Time.zone.now
) )
user.after_confirmation
rescue ActiveRecord::RecordNotUnique rescue ActiveRecord::RecordNotUnique
# ignore this exception because we check before is user is nil. # ignore this exception because we check before is user is nil.
# exception can be raised in race conditions, when FranceConnect calls callback 2 times. # exception can be raised in race conditions, when FranceConnect calls callback 2 times.

View file

@ -0,0 +1,22 @@
namespace :after_party do
desc 'Deployment task: backfill_invites_missing_existing_user'
task backfill_invites_missing_existing_user: :environment do
puts "Running deploy task 'backfill_invites_missing_existing_user'"
# Put your task implementation HERE.
Invite.where.missing(:user).in_batches do |invites_with_missing_user|
linkable_users_and_invite = User.where(email: invites_with_missing_user.pluck(:email))
linkable_users_and_invite.each do |linkable_user_and_invite|
begin
linkable_user_and_invite.after_confirmation # calls link_invites!
rescue err
Sentry.capture_exception(err)
end
end
end
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -96,6 +96,15 @@ describe FranceConnect::ParticulierController, type: :controller do
expect(controller.current_user).to eq(user) expect(controller.current_user).to eq(user)
expect(response).to redirect_to(root_path) expect(response).to redirect_to(root_path)
end end
context 'when invites are pending' do
let!(:invite) { create(:invite, email: email, user: nil) }
it 'links pending invites' do
expect(invite.reload.user).to eq(nil)
subject
expect(invite.reload.user).to eq(User.last)
end
end
end end
context 'and an user with the same email exists' do context 'and an user with the same email exists' do