diff options
author | Claire <claire.github-309c@sitedethib.com> | 2023-01-24 20:32:31 +0100 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2023-01-24 20:32:31 +0100 |
commit | 3074338d79e5e9eb056d810c234e57f14c04c5f9 (patch) | |
tree | 3cda43f51dbf40ed742beeac0090b3be08e47c90 /app/models | |
parent | 368d6fe54f94ad2ecd2a1c1e7e5a2359dc37ad30 (diff) | |
parent | a5a00d7f7adff5e0afbd23ac1e1b16120137509a (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/user.rb | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 2e3c067ec..a813ac83c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -195,10 +195,16 @@ class User < ApplicationRecord super - if new_user && approved? - prepare_new_user! - elsif new_user - notify_staff_about_pending_account! + if new_user + # Avoid extremely unlikely race condition when approving and confirming + # the user at the same time + reload unless approved? + + if approved? + prepare_new_user! + else + notify_staff_about_pending_account! + end end end @@ -209,7 +215,13 @@ class User < ApplicationRecord skip_confirmation! save! - prepare_new_user! if new_user && approved? + if new_user + # Avoid extremely unlikely race condition when approving and confirming + # the user at the same time + reload unless approved? + + prepare_new_user! if approved? + end end def update_sign_in!(new_sign_in: false) @@ -261,7 +273,11 @@ class User < ApplicationRecord return if approved? update!(approved: true) - prepare_new_user! + + # Avoid extremely unlikely race condition when approving and confirming + # the user at the same time + reload unless confirmed? + prepare_new_user! if confirmed? end def otp_enabled? |