Skip to content

Commit

Permalink
Merge pull request demarches-simplifiees#9887 from mfo/US/fix-fci-mis…
Browse files Browse the repository at this point in the history
…sing-device-callback

Correctif: ETQ usager invité, lorsque je crée mon compte via FC, je ne retrouve pas mes invitations
  • Loading branch information
mfo authored Jan 4, 2024
2 parents e076de2 + a63bd95 commit 9df978f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/france_connect_information.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def associate_user!(email)
password: Devise.friendly_token[0, 20],
confirmed_at: Time.zone.now
)
user.after_confirmation
rescue ActiveRecord::RecordNotUnique
# ignore this exception because we check before is user is nil.
# exception can be raised in race conditions, when FranceConnect calls callback 2 times.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@
expect(controller.current_user).to eq(user)
expect(response).to redirect_to(root_path)
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

context 'and an user with the same email exists' do
Expand Down

0 comments on commit 9df978f

Please sign in to comment.