feat(maintenance): add task to copy super admin OTP secrets to Rails 7 encrypted attributes
This commit is contained in:
parent
845a4582d3
commit
1524f5ba16
2 changed files with 51 additions and 0 deletions
|
@ -0,0 +1,26 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Maintenance
|
||||
class CopySuperAdminOtpSecretToRails7EncryptedAttrTask < MaintenanceTasks::Task
|
||||
# Cette tâche finalise la mise à niveau vers devies-two-factor 5
|
||||
# qui utilise les encrypted attributes de Rails 7.
|
||||
# Elle copie les secrets OTP des super admins vers la nouvelle colonne
|
||||
# avant une suppression plus tard des anciennes colonnes.
|
||||
# Plus d'informations : https://github.com/devise-two-factor/devise-two-factor/blob/main/UPGRADING.md
|
||||
# Introduit 2024-08-29, https://github.com/demarches-simplifiees/demarches-simplifiees.fr/pull/10722
|
||||
def collection
|
||||
SuperAdmin.all
|
||||
end
|
||||
|
||||
def process(super_admin)
|
||||
# From https://github.com/devise-two-factor/devise-two-factor/blob/main/UPGRADING.md
|
||||
otp_secret = super_admin.otp_secret # read from otp_secret column, fall back to legacy columns if new column is empty
|
||||
# This is NOOP when otp_secret column has already the same value
|
||||
super_admin.update!(otp_secret: otp_secret)
|
||||
end
|
||||
|
||||
def count
|
||||
SuperAdmin.count
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue