Class: User
Overview
Table name: users
id :bigint not null, primary key
first_name :string(255) default(""), not null
last_name :string(255) default(""), not null
phone_number :string(255)
last_mfa_login :datetime
email_validated :boolean default(FALSE)
mfa_enabled :boolean default(FALSE), not null
active :boolean default(TRUE), not null
admin :string(255)
last_known_timezone :string(255)
last_known_timezone_update :datetime
email :string(255) default(""), not null
encrypted_password :string(255) default(""), not null
reset_password_token :string(255)
reset_password_sent_at :datetime
remember_created_at :datetime
sign_in_count :integer default(0), not null
current_sign_in_at :datetime
last_sign_in_at :datetime
current_sign_in_ip :string(255)
last_sign_in_ip :string(255)
created_at :datetime not null
updated_at :datetime not null
Constant Summary
RailsBase::UserConstants::ADMIN_ENUMS, RailsBase::UserConstants::SAFE_AUTOMAGIC_UPGRADE_COLS, RailsBase::UserConstants::SOFT_DESTROY_PARAMS
Class Method Summary
collapse
Instance Method Summary
collapse
_magically_defined_time_objects
Class Method Details
._def_admin_convenience_method!(admin_method:) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/models/user.rb', line 40
def self._def_admin_convenience_method!(admin_method:)
types = RailsBase.config.admin.admin_types
define_method("at_least_#{admin_method}?") do
i = types.find_index(admin.to_sym)
i >= types.find_index(admin_method.to_sym)
end
define_method("admin_#{admin_method}?") do
admin.to_sym == admin_method
end
define_method("admin_#{admin_method}!") do
update!(admin: admin_method)
end
define_singleton_method("admin_#{admin_method}s") do
where(admin: admin_method)
end
define_singleton_method("admin_#{admin_method}") do
arr = [admin_method]
arr = [admin_method, '', nil] if ADMIN_ROLE_NONE == admin_method
where(admin: arr)
end
end
|
.time_bound ⇒ Object
68
69
70
|
# File 'app/models/user.rb', line 68
def self.time_bound
Time.zone.now - RailsBase.config.auth.mfa_time_duration
end
|
Instance Method Details
#admin ⇒ Object
72
73
74
|
# File 'app/models/user.rb', line 72
def admin
(self[:admin].presence || ADMIN_ROLE_NONE).to_sym
end
|
#convert_time(time:) ⇒ Object
119
120
121
|
# File 'app/models/user.rb', line 119
def convert_time(time:)
time.in_time_zone(timezone)
end
|
#destroy_user! ⇒ Object
100
101
102
|
# File 'app/models/user.rb', line 100
def destroy_user!
self.delete
end
|
#full_name ⇒ Object
76
77
78
|
# File 'app/models/user.rb', line 76
def full_name
"#{first_name} #{last_name}"
end
|
#inspect_name ⇒ Object
104
105
106
|
# File 'app/models/user.rb', line 104
def inspect_name
"[#{id}]: #{full_name}"
end
|
#masked_phone ⇒ Object
90
91
92
93
94
|
# File 'app/models/user.rb', line 90
def masked_phone
return nil unless phone_number
"(#{phone_number[0]}**) ****-**#{phone_number[-2..-1]}"
end
|
#past_mfa_time_duration? ⇒ Boolean
80
81
82
83
84
|
# File 'app/models/user.rb', line 80
def past_mfa_time_duration?
return true if last_mfa_login.nil?
last_mfa_login < self.class.time_bound
end
|
#set_last_mfa_login!(time: Time.zone.now) ⇒ Object
86
87
88
|
# File 'app/models/user.rb', line 86
def set_last_mfa_login!(time: Time.zone.now)
update(last_mfa_login: time)
end
|
#soft_destroy_user! ⇒ Object
96
97
98
|
# File 'app/models/user.rb', line 96
def soft_destroy_user!
update(SOFT_DESTROY_PARAMS)
end
|
#timezone ⇒ Object
115
116
117
|
# File 'app/models/user.rb', line 115
def timezone
RailsBase.config.user.user_timezone(self)
end
|
#update_tz(tz_name:) ⇒ Object
108
109
110
111
112
113
|
# File 'app/models/user.rb', line 108
def update_tz(tz_name:)
return if last_known_timezone == tz_name
Rails.logger.info { "#{id}: Setting tz_name: #{tz_name}" }
update(last_known_timezone: tz_name, last_known_timezone_update: Time.now )
end
|