mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 05:34:55 +08:00
Rename column
This commit is contained in:
parent
88f54b16d7
commit
de8aca9dbd
4 changed files with 8 additions and 8 deletions
|
@ -286,8 +286,8 @@ class User < ApplicationRecord
|
|||
foreign_key: :resource_owner_id,
|
||||
dependent: :delete_all
|
||||
|
||||
before_save :ensure_2fa_token, if: ->(user) { user.changed.include?('twofa_enabled') }
|
||||
before_create :generate_2fa_token
|
||||
before_save :ensure_2fa_token, if: ->(user) { user.changed.include?('two_factor_auth_enabled') }
|
||||
before_create :assign_2fa_token
|
||||
before_destroy :destroy_notifications
|
||||
|
||||
def name
|
||||
|
@ -661,11 +661,11 @@ class User < ApplicationRecord
|
|||
Rails.cache.delete_matched(%r{^views\/users\/#{id}-})
|
||||
end
|
||||
|
||||
def generate_2fa_token
|
||||
def assign_2fa_token
|
||||
self.otp_secret = ROTP::Base32.random
|
||||
end
|
||||
|
||||
def ensure_2fa_token
|
||||
generate_2fa_token unless otp_secret
|
||||
assign_2fa_token unless otp_secret
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class Add2faToUsers < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
change_table :users, bulk: true do |t|
|
||||
t.boolean :twofa_enabled, default: false, null: false
|
||||
t.boolean :two_factor_auth_enabled, default: false, null: false
|
||||
t.string :otp_secret
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2648,7 +2648,7 @@ CREATE TABLE public.users (
|
|||
authentication_token character varying(30),
|
||||
settings jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
variables jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
twofa_enabled boolean DEFAULT false NOT NULL,
|
||||
two_factor_auth_enabled boolean DEFAULT false NOT NULL,
|
||||
otp_secret character varying
|
||||
);
|
||||
|
||||
|
|
|
@ -349,13 +349,13 @@ describe User, type: :model do
|
|||
it 'sets token before save' do
|
||||
user.update_column(:otp_secret, nil)
|
||||
|
||||
expect { user.update(twofa_enabled: true) }.to(change { user.otp_secret })
|
||||
expect { user.update(two_factor_auth_enabled: true) }.to(change { user.otp_secret })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user does have otp_secret' do
|
||||
it 'does not set new token before save' do
|
||||
expect { user.update(twofa_enabled: true) }.not_to(change { user.otp_secret })
|
||||
expect { user.update(two_factor_auth_enabled: true) }.not_to(change { user.otp_secret })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue