mirror of https://github.com/mastodon/mastodon
Fix OTP secret post-deployment migration
This commit is contained in:
parent
b89418f9a3
commit
e758e9a49c
|
@ -3,7 +3,18 @@
|
|||
class MigrateDeviseTwoFactorSecrets < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
class MigrationUser < ApplicationRecord
|
||||
self.table_name = :users
|
||||
|
||||
devise :two_factor_authenticatable,
|
||||
otp_secret_encryption_key: Rails.configuration.x.otp_secret
|
||||
|
||||
include LegacyOtpSecret # Must be after the above `devise` line in order to override the legacy method
|
||||
end
|
||||
|
||||
def up
|
||||
MigrationUser.reset_column_information
|
||||
|
||||
users_with_otp_enabled.find_each do |user|
|
||||
# Gets the new value on already-updated users
|
||||
# Falls back to legacy value on not-yet-migrated users
|
||||
|
@ -23,6 +34,6 @@ class MigrateDeviseTwoFactorSecrets < ActiveRecord::Migration[7.1]
|
|||
private
|
||||
|
||||
def users_with_otp_enabled
|
||||
User.where(otp_required_for_login: true)
|
||||
MigrationUser.where(otp_required_for_login: true, otp_secret: nil)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue