Extract `User::Approval` concern

pull/32855/head
Matt Jankowski 2024-11-12 10:01:30 -05:00
parent 7e9e390447
commit 6556b26ab0
2 changed files with 10 additions and 11 deletions

View File

@ -11,4 +11,14 @@ module User::Approval
def pending?
!approved?
end
def approve!
return if approved?
update!(approved: true)
# Handle scenario when approving and confirming a user at the same time
reload unless confirmed?
prepare_new_user! if confirmed?
end
end

View File

@ -242,17 +242,6 @@ class User < ApplicationRecord
unconfirmed? || pending?
end
def approve!
return if approved?
update!(approved: true)
# 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?
otp_required_for_login
end