feat(maintenance): add task to copy super admin OTP secrets to Rails 7 encrypted attributes

This commit is contained in:
Colin Darie 2024-08-29 13:11:36 +02:00
parent 845a4582d3
commit 1524f5ba16
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 51 additions and 0 deletions

View file

@ -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