From 6556b26ab0f817300ef50952ec53d073094c5540 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 12 Nov 2024 10:01:30 -0500 Subject: [PATCH] Extract `User::Approval` concern --- app/models/concerns/user/approval.rb | 10 ++++++++++ app/models/user.rb | 11 ----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/models/concerns/user/approval.rb b/app/models/concerns/user/approval.rb index 827159dc0a..28f3c2a825 100644 --- a/app/models/concerns/user/approval.rb +++ b/app/models/concerns/user/approval.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 01ddad4dfa..02b30e4fc5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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