Commit 1735ed61 authored by Alexis Reigel's avatar Alexis Reigel

rename cache db column with `_cached` suffix

parent 20575859
...@@ -21,7 +21,7 @@ module EnforcesTwoFactorAuthentication ...@@ -21,7 +21,7 @@ module EnforcesTwoFactorAuthentication
def two_factor_authentication_required? def two_factor_authentication_required?
current_application_settings.require_two_factor_authentication? || current_application_settings.require_two_factor_authentication? ||
current_user.try(:require_two_factor_authentication?) current_user.try(:require_two_factor_authentication_from_group?)
end end
def two_factor_authentication_reason(global: -> {}, group: -> {}) def two_factor_authentication_reason(global: -> {}, group: -> {})
...@@ -37,7 +37,7 @@ module EnforcesTwoFactorAuthentication ...@@ -37,7 +37,7 @@ module EnforcesTwoFactorAuthentication
def two_factor_grace_period def two_factor_grace_period
periods = [current_application_settings.two_factor_grace_period] periods = [current_application_settings.two_factor_grace_period]
periods << current_user.two_factor_grace_period if current_user.try(:require_two_factor_authentication?) periods << current_user.two_factor_grace_period if current_user.try(:require_two_factor_authentication_from_group?)
periods.min periods.min
end end
......
...@@ -974,7 +974,7 @@ class User < ActiveRecord::Base ...@@ -974,7 +974,7 @@ class User < ActiveRecord::Base
def update_two_factor_requirement def update_two_factor_requirement
periods = expanded_groups_requiring_two_factor_authentication.pluck(:two_factor_grace_period) periods = expanded_groups_requiring_two_factor_authentication.pluck(:two_factor_grace_period)
self.require_two_factor_authentication = periods.any? self.require_two_factor_authentication_from_group = periods.any?
self.two_factor_grace_period = periods.min || User.column_defaults['two_factor_grace_period'] self.two_factor_grace_period = periods.min || User.column_defaults['two_factor_grace_period']
save save
......
...@@ -6,12 +6,12 @@ class AddTwoFactorColumnsToUsers < ActiveRecord::Migration ...@@ -6,12 +6,12 @@ class AddTwoFactorColumnsToUsers < ActiveRecord::Migration
disable_ddl_transaction! disable_ddl_transaction!
def up def up
add_column_with_default(:users, :require_two_factor_authentication, :boolean, default: false) add_column_with_default(:users, :require_two_factor_authentication_from_group, :boolean, default: false)
add_column_with_default(:users, :two_factor_grace_period, :integer, default: 48) add_column_with_default(:users, :two_factor_grace_period, :integer, default: 48)
end end
def down def down
remove_column(:users, :require_two_factor_authentication) remove_column(:users, :require_two_factor_authentication_from_group)
remove_column(:users, :two_factor_grace_period) remove_column(:users, :two_factor_grace_period)
end end
end end
...@@ -1249,7 +1249,7 @@ ActiveRecord::Schema.define(version: 20170402231018) do ...@@ -1249,7 +1249,7 @@ ActiveRecord::Schema.define(version: 20170402231018) do
t.boolean "authorized_projects_populated" t.boolean "authorized_projects_populated"
t.boolean "ghost" t.boolean "ghost"
t.boolean "notified_of_own_activity" t.boolean "notified_of_own_activity"
t.boolean "require_two_factor_authentication", default: false, null: false t.boolean "require_two_factor_authentication_from_group", default: false, null: false
t.integer "two_factor_grace_period", default: 48, null: false t.integer "two_factor_grace_period", default: 48, null: false
end end
......
...@@ -183,7 +183,7 @@ describe ApplicationController do ...@@ -183,7 +183,7 @@ describe ApplicationController do
end end
it 'returns true if a 2FA requirement is set on the user' do it 'returns true if a 2FA requirement is set on the user' do
user.require_two_factor_authentication = true user.require_two_factor_authentication_from_group = true
allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
expect(subject).to be_truthy expect(subject).to be_truthy
...@@ -201,7 +201,7 @@ describe ApplicationController do ...@@ -201,7 +201,7 @@ describe ApplicationController do
end end
context 'with a 2FA requirement set on the user' do context 'with a 2FA requirement set on the user' do
let(:user) { create :user, require_two_factor_authentication: true, two_factor_grace_period: 23 } let(:user) { create :user, require_two_factor_authentication_from_group: true, two_factor_grace_period: 23 }
it 'returns the user grace period if lower than the application grace period' do it 'returns the user grace period if lower than the application grace period' do
stub_application_setting two_factor_grace_period: 24 stub_application_setting two_factor_grace_period: 24
......
...@@ -1548,7 +1548,7 @@ describe User, models: true do ...@@ -1548,7 +1548,7 @@ describe User, models: true do
end end
it 'requires 2FA' do it 'requires 2FA' do
expect(user.require_two_factor_authentication).to be true expect(user.require_two_factor_authentication_from_group).to be true
end end
it 'uses the shortest grace period' do it 'uses the shortest grace period' do
...@@ -1567,7 +1567,7 @@ describe User, models: true do ...@@ -1567,7 +1567,7 @@ describe User, models: true do
end end
it 'requires 2FA' do it 'requires 2FA' do
expect(user.require_two_factor_authentication).to be true expect(user.require_two_factor_authentication_from_group).to be true
end end
end end
...@@ -1582,7 +1582,7 @@ describe User, models: true do ...@@ -1582,7 +1582,7 @@ describe User, models: true do
end end
it 'requires 2FA' do it 'requires 2FA' do
expect(user.require_two_factor_authentication).to be true expect(user.require_two_factor_authentication_from_group).to be true
end end
end end
...@@ -1596,7 +1596,7 @@ describe User, models: true do ...@@ -1596,7 +1596,7 @@ describe User, models: true do
end end
it 'does not require 2FA' do it 'does not require 2FA' do
expect(user.require_two_factor_authentication).to be false expect(user.require_two_factor_authentication_from_group).to be false
end end
it 'falls back to the default grace period' do it 'falls back to the default grace period' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment