Class: User
Constant Summary
collapse
- ID_CARD_ALLOWED_STATUSES =
%w[V1 V3 V6].freeze
Common::RedisStore::REQ_CLASS_INSTANCE_VARS
Instance Method Summary
collapse
#authorize
create, delete, #destroyed?, exists?, #expire, find, find_or_build, #initialize, #initialize_dup, keys, #persisted?, pop, redis_key, redis_store, redis_ttl, #save, #save!, #ttl, #update, #update!
Instance Method Details
#account_id ⇒ Object
46
47
48
|
# File 'app/models/user.rb', line 46
def account_id
@account_id ||= account&.id
end
|
#account_uuid ⇒ Object
42
43
44
|
# File 'app/models/user.rb', line 42
def account_uuid
@account_uuid ||= account&.uuid
end
|
#active_mhv_ids ⇒ Object
193
194
195
|
# File 'app/models/user.rb', line 193
def active_mhv_ids
mpi_profile&.active_mhv_ids
end
|
#address ⇒ Object
197
198
199
200
201
202
203
204
205
206
207
|
# File 'app/models/user.rb', line 197
def address
address = mpi_profile&.address || {}
{
street: address[:street],
street2: address[:street2],
city: address[:city],
state: address[:state],
country: address[:country],
postal_code: address[:postal_code]
}
end
|
#all_emails ⇒ Object
400
401
402
403
404
405
406
407
408
409
410
411
412
|
# File 'app/models/user.rb', line 400
def all_emails
the_va_profile_email =
begin
va_profile_email
rescue
nil
end
[the_va_profile_email, email]
.reject(&:blank?)
.map(&:downcase)
.uniq
end
|
#birth_date ⇒ Object
Returns a Date string in iso8601 format, eg. ‘year-month-day’
106
107
108
109
110
|
# File 'app/models/user.rb', line 106
def birth_date
birth_date = identity.birth_date || birth_date_mpi
Formatters::DateFormatter.format_date(birth_date)
end
|
#birth_date_mpi ⇒ Object
213
214
215
|
# File 'app/models/user.rb', line 213
def birth_date_mpi
mpi_profile&.birth_date
end
|
#can_access_id_card? ⇒ Boolean
335
336
337
338
339
340
|
# File 'app/models/user.rb', line 335
def can_access_id_card?
loa3? && edipi.present? &&
ID_CARD_ALLOWED_STATUSES.include?(veteran_status.title38_status)
rescue false
end
|
#can_access_user_profile? ⇒ Boolean
316
317
318
|
# File 'app/models/user.rb', line 316
def can_access_user_profile?
loa[:current].present?
end
|
#can_access_vet360? ⇒ Boolean
414
415
416
417
418
|
# File 'app/models/user.rb', line 414
def can_access_vet360?
loa3? && icn.present? && vet360_id.present?
rescue false
end
|
#common_name ⇒ Object
116
117
118
|
# File 'app/models/user.rb', line 116
def common_name
[first_name, middle_name, last_name, suffix].compact.join(' ')
end
|
#credential_lock ⇒ Object
50
51
52
53
54
|
# File 'app/models/user.rb', line 50
def credential_lock
return @credential_lock unless @credential_lock.nil?
@credential_lock = user_verification&.locked
end
|
#destroy ⇒ Object
destroy both UserIdentity and self
353
354
355
356
|
# File 'app/models/user.rb', line 353
def destroy
identity&.destroy
super
end
|
#edipi ⇒ Object
120
121
122
|
# File 'app/models/user.rb', line 120
def edipi
loa3? && identity.edipi.present? ? identity.edipi : edipi_mpi
end
|
#edipi_mpi ⇒ Object
217
218
219
|
# File 'app/models/user.rb', line 217
def edipi_mpi
mpi_profile&.edipi
end
|
#first_name ⇒ Object
112
113
114
|
# File 'app/models/user.rb', line 112
def first_name
identity.first_name.presence || first_name_mpi
end
|
#first_name_mpi ⇒ Object
221
222
223
|
# File 'app/models/user.rb', line 221
def first_name_mpi
given_names&.first
end
|
#flipper_id ⇒ Object
434
435
436
|
# File 'app/models/user.rb', line 434
def flipper_id
email&.downcase || account_uuid
end
|
#full_name_normalized ⇒ Object
124
125
126
127
128
129
130
131
|
# File 'app/models/user.rb', line 124
def full_name_normalized
{
first: first_name&.capitalize,
middle: middle_name&.capitalize,
last: last_name&.capitalize,
suffix: normalized_suffix
}
end
|
#gender ⇒ Object
133
134
135
|
# File 'app/models/user.rb', line 133
def gender
identity.gender.presence || gender_mpi
end
|
#gender_mpi ⇒ Object
229
230
231
|
# File 'app/models/user.rb', line 229
def gender_mpi
mpi_profile&.gender
end
|
#given_names ⇒ Object
233
234
235
|
# File 'app/models/user.rb', line 233
def given_names
mpi_profile&.given_names
end
|
#home_phone ⇒ Object
237
238
239
|
# File 'app/models/user.rb', line 237
def home_phone
mpi_profile&.home_phone
end
|
#icn ⇒ Object
137
138
139
|
# File 'app/models/user.rb', line 137
def icn
identity&.icn || mpi&.icn
end
|
#identity ⇒ Object
386
387
388
|
# File 'app/models/user.rb', line 386
def identity
@identity ||= UserIdentity.find(uuid)
end
|
#inherited_proof_verified ⇒ Object
78
79
80
|
# File 'app/models/user.rb', line 78
def inherited_proof_verified
@inherited_proof_verified ||= InheritedProofVerifiedUserAccount.where(user_account_id: user_account_uuid).present?
end
|
#invalidate_mpi_cache ⇒ Object
299
300
301
302
303
304
|
# File 'app/models/user.rb', line 299
def invalidate_mpi_cache
return unless mpi.mpi_response_is_cached?
mpi.destroy
@mpi = nil
end
|
#last_name ⇒ Object
157
158
159
|
# File 'app/models/user.rb', line 157
def last_name
identity.last_name.presence || last_name_mpi
end
|
#last_name_mpi ⇒ Object
241
242
243
|
# File 'app/models/user.rb', line 241
def last_name_mpi
mpi_profile&.family_name
end
|
#loa ⇒ Object
141
142
143
|
# File 'app/models/user.rb', line 141
def loa
identity&.loa || {}
end
|
#mhv_account_state ⇒ Object
245
246
247
248
249
250
251
|
# File 'app/models/user.rb', line 245
def mhv_account_state
return 'DEACTIVATED' if (mhv_ids.to_a - active_mhv_ids.to_a).any?
return 'MULTIPLE' if active_mhv_ids.to_a.size > 1
return 'NONE' if mhv_correlation_id.blank?
'OK'
end
|
#mhv_account_type ⇒ Object
#mhv_correlation_id ⇒ Object
149
150
151
|
# File 'app/models/user.rb', line 149
def mhv_correlation_id
identity.mhv_correlation_id || mpi_mhv_correlation_id
end
|
#mhv_ids ⇒ Object
253
254
255
|
# File 'app/models/user.rb', line 253
def mhv_ids
mpi_profile&.mhv_ids
end
|
#middle_name ⇒ Object
153
154
155
|
# File 'app/models/user.rb', line 153
def middle_name
identity.middle_name.presence || middle_name_mpi
end
|
#middle_name_mpi ⇒ Object
225
226
227
|
# File 'app/models/user.rb', line 225
def middle_name_mpi
mpi&.profile&.given_names.to_a[1..]&.join(' ').presence
end
|
#mpi_gcids ⇒ Object
285
286
287
|
# File 'app/models/user.rb', line 285
def mpi_gcids
mpi_profile&.full_mvi_ids || []
end
|
#mpi_profile? ⇒ Boolean
273
274
275
|
# File 'app/models/user.rb', line 273
def mpi_profile?
mpi_profile != nil
end
|
#needs_accepted_terms_of_use ⇒ Object
56
57
58
59
60
|
# File 'app/models/user.rb', line 56
def needs_accepted_terms_of_use
return @needs_accepted_terms_of_use unless @needs_accepted_terms_of_use.nil?
@needs_accepted_terms_of_use = user_account&.needs_accepted_terms_of_use?
end
|
#normalized_suffix ⇒ Object
257
258
259
|
# File 'app/models/user.rb', line 257
def normalized_suffix
mpi_profile&.normalized_suffix
end
|
#pciu_alternate_phone ⇒ Object
90
91
92
|
# File 'app/models/user.rb', line 90
def pciu_alternate_phone
pciu&.get_alternate_phone&.to_s
end
|
#pciu_email ⇒ Object
82
83
84
|
# File 'app/models/user.rb', line 82
def pciu_email
pciu&.get_email_address&.email
end
|
#pciu_primary_phone ⇒ Object
86
87
88
|
# File 'app/models/user.rb', line 86
def pciu_primary_phone
pciu&.get_primary_phone&.to_s
end
|
#postal_code ⇒ Object
261
262
263
|
# File 'app/models/user.rb', line 261
def postal_code
mpi&.profile&.address&.postal_code
end
|
#power_of_attorney ⇒ Object
#recache ⇒ Object
Re-caches the MPI response. Use in response to any local changes that have been made.
348
349
350
|
# File 'app/models/user.rb', line 348
def recache
mpi.cache(uuid, mpi.mvi_response)
end
|
#relationships ⇒ Object
438
439
440
|
# File 'app/models/user.rb', line 438
def relationships
@relationships ||= get_relationships_array
end
|
#sec_id ⇒ Object
161
162
163
|
# File 'app/models/user.rb', line 161
def sec_id
identity&.sec_id || mpi_profile&.sec_id
end
|
#served_in_military? ⇒ Boolean
A user can have served in the military without being a veteran. For example, someone can be ex-military by having a discharge status higher than ‘Other Than Honorable’.
426
427
428
|
# File 'app/models/user.rb', line 426
def served_in_military?
edipi.present? && veteran? || military_person?
end
|
#set_mhv_ids(mhv_id) ⇒ Object
291
292
293
294
295
|
# File 'app/models/user.rb', line 291
def set_mhv_ids(mhv_id)
mpi_profile.mhv_ids = [mhv_id] + mhv_ids
mpi_profile.active_mhv_ids = [mhv_id] + active_mhv_ids
recache
end
|
#ssn ⇒ Object
165
166
167
|
# File 'app/models/user.rb', line 165
def ssn
identity&.ssn || ssn_mpi
end
|
#ssn_mismatch? ⇒ Boolean
310
311
312
313
314
|
# File 'app/models/user.rb', line 310
def ssn_mismatch?
return false unless loa3? && identity&.ssn && ssn_mpi
identity.ssn != ssn_mpi
end
|
#ssn_mpi ⇒ Object
265
266
267
|
# File 'app/models/user.rb', line 265
def ssn_mpi
mpi_profile&.ssn
end
|
#ssn_normalized ⇒ Object
169
170
171
|
# File 'app/models/user.rb', line 169
def ssn_normalized
ssn&.gsub(/[^\d]/, '')
end
|
#suffix ⇒ Object
269
270
271
|
# File 'app/models/user.rb', line 269
def suffix
mpi_profile&.suffix
end
|
#user_account ⇒ Object
66
67
68
|
# File 'app/models/user.rb', line 66
def user_account
@user_account ||= user_verification&.user_account
end
|
#user_account_uuid ⇒ Object
74
75
76
|
# File 'app/models/user.rb', line 74
def user_account_uuid
@user_account_uuid ||= user_account&.id
end
|
#user_verification ⇒ Object
62
63
64
|
# File 'app/models/user.rb', line 62
def user_verification
@user_verification ||= get_user_verification
end
|
#user_verification_id ⇒ Object
70
71
72
|
# File 'app/models/user.rb', line 70
def user_verification_id
@user_verification_id ||= user_verification&.id
end
|
#va_patient? ⇒ Boolean
True if the user has 1 or more treatment facilities, false otherwise
321
322
323
|
# File 'app/models/user.rb', line 321
def va_patient?
va_treatment_facility_ids.length.positive?
end
|
#va_profile_email ⇒ Object
396
397
398
|
# File 'app/models/user.rb', line 396
def va_profile_email
vet360_contact_info&.email&.email_address
end
|
#va_treatment_facility_ids ⇒ Object
User’s profile contains a list of VHA facility-specific identifiers. Facilities in the defined range are treating facilities
327
328
329
330
331
332
333
|
# File 'app/models/user.rb', line 327
def va_treatment_facility_ids
facilities = vha_facility_ids
facilities.select do |f|
Settings.mhv.facility_range.any? { |range| f.to_i.between?(*range) } ||
Settings.mhv.facility_specific.include?(f)
end
end
|
#vha_facility_hash ⇒ Object
281
282
283
|
# File 'app/models/user.rb', line 281
def vha_facility_hash
mpi_profile&.vha_facility_hash || {}
end
|
#vha_facility_ids ⇒ Object
277
278
279
|
# File 'app/models/user.rb', line 277
def vha_facility_ids
mpi_profile&.vha_facility_ids || []
end
|