Class: User

Inherits:
Common::RedisStore show all
Extended by:
Gem::Deprecate
Includes:
Authorization
Defined in:
app/models/user.rb

Direct Known Subclasses

IAMUser

Constant Summary collapse

ID_CARD_ALLOWED_STATUSES =

Defined per issue #6042

%w[V1 V3 V6].freeze

Constants inherited from Common::RedisStore

Common::RedisStore::REQ_CLASS_INSTANCE_VARS

Instance Method Summary collapse

Methods included from Authorization

#authorize

Methods inherited from Common::RedisStore

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!

Constructor Details

This class inherits a constructor from Common::RedisStore

Instance Method Details

#accountObject



39
40
41
# File 'app/models/user.rb', line 39

def 
  @account ||= Identity::AccountCreator.new(self).call
end

#account_idObject



47
48
49
# File 'app/models/user.rb', line 47

def 
  @account_id ||= &.id
end

#account_uuidObject



43
44
45
# File 'app/models/user.rb', line 43

def 
  @account_uuid ||= &.uuid
end

#active_mhv_idsObject



211
212
213
# File 'app/models/user.rb', line 211

def active_mhv_ids
  mpi_profile&.active_mhv_ids
end

#addressObject



215
216
217
218
219
220
221
222
223
224
225
# File 'app/models/user.rb', line 215

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_emailsObject



425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'app/models/user.rb', line 425

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

#bgs_relationshipsObject (private)



520
521
522
523
524
525
# File 'app/models/user.rb', line 520

def bgs_relationships
  bgs_dependents = BGS::DependentService.new(self).get_dependents
  return unless bgs_dependents.presence && bgs_dependents[:persons]

  bgs_dependents[:persons].map { |dependent| UserRelationship.from_bgs_dependent(dependent) }
end

#birth_dateObject

Returns a Date string in iso8601 format, eg. ‘year-month-day’



107
108
109
110
111
# File 'app/models/user.rb', line 107

def birth_date
  birth_date = identity.birth_date || birth_date_mpi

  Formatters::DateFormatter.format_date(birth_date)
end

#birth_date_mpiObject



231
232
233
# File 'app/models/user.rb', line 231

def birth_date_mpi
  mpi_profile&.birth_date
end

#can_access_id_card?Boolean

Returns:

  • (Boolean)


357
358
359
360
361
362
# File 'app/models/user.rb', line 357

def can_access_id_card?
  loa3? && edipi.present? &&
    ID_CARD_ALLOWED_STATUSES.include?(veteran_status.title38_status)
rescue # Default to false for any veteran_status error
  false
end

#can_access_user_profile?Boolean

Returns:

  • (Boolean)


338
339
340
# File 'app/models/user.rb', line 338

def can_access_user_profile?
  loa[:current].present?
end

#can_access_vet360?Boolean

Returns:

  • (Boolean)


439
440
441
442
443
# File 'app/models/user.rb', line 439

def can_access_vet360?
  loa3? && icn.present? && vet360_id.present?
rescue # Default to false for any error
  false
end

#can_create_mhv_account?Boolean

Returns:

  • (Boolean)


473
474
475
476
477
# File 'app/models/user.rb', line 473

def can_create_mhv_account?
  return false unless Flipper.enabled?(:mhv_account_creation_after_login, )

  loa3? && va_patient? && !needs_accepted_terms_of_use
end

#common_nameObject



117
118
119
# File 'app/models/user.rb', line 117

def common_name
  [first_name, middle_name, last_name, suffix].compact.join(' ')
end

#create_mhv_account_asyncObject



467
468
469
470
471
# File 'app/models/user.rb', line 467

def 
  return unless can_create_mhv_account?

  MHV::AccountCreatorJob.perform_async(user_verification_id)
end

#credential_lockObject



55
56
57
58
59
# File 'app/models/user.rb', line 55

def credential_lock
  return @credential_lock unless @credential_lock.nil?

  @credential_lock = user_verification&.locked
end

#deceased_dateObject



227
228
229
# File 'app/models/user.rb', line 227

def deceased_date
  Formatters::DateFormatter.format_date(mpi_profile&.deceased_date)
end

#destroyObject

destroy both UserIdentity and self



375
376
377
378
# File 'app/models/user.rb', line 375

def destroy
  identity&.destroy
  super
end

#edipiObject



121
122
123
# File 'app/models/user.rb', line 121

def edipi
  loa3? && identity.edipi.present? ? identity.edipi : edipi_mpi
end

#edipi_mpiObject



235
236
237
# File 'app/models/user.rb', line 235

def edipi_mpi
  mpi_profile&.edipi
end

#first_nameObject



113
114
115
# File 'app/models/user.rb', line 113

def first_name
  identity.first_name.presence || first_name_mpi
end

#first_name_mpiObject



239
240
241
# File 'app/models/user.rb', line 239

def first_name_mpi
  given_names&.first
end

#flipper_idObject



459
460
461
# File 'app/models/user.rb', line 459

def flipper_id
  email&.downcase || 
end

#full_name_normalizedObject



125
126
127
128
129
130
131
132
# File 'app/models/user.rb', line 125

def full_name_normalized
  {
    first: first_name&.capitalize,
    middle: middle_name&.capitalize,
    last: last_name&.capitalize,
    suffix: normalized_suffix
  }
end

#genderObject



138
139
140
# File 'app/models/user.rb', line 138

def gender
  identity.gender.presence || gender_mpi
end

#gender_mpiObject



251
252
253
# File 'app/models/user.rb', line 251

def gender_mpi
  mpi_profile&.gender
end

#get_relationships_arrayObject (private)



508
509
510
511
512
# File 'app/models/user.rb', line 508

def get_relationships_array
  return unless loa3?

  mpi_profile_relationships || bgs_relationships
end

#get_user_verificationObject (private)

Get user_verification based on login method Default is idme, if login method and login uuid are not available, fall back to idme



494
495
496
497
498
499
500
501
502
503
504
505
506
# File 'app/models/user.rb', line 494

def get_user_verification
  case &.dig(:service_name)
  when SAML::User::MHV_ORIGINAL_CSID
    return UserVerification.find_by(mhv_uuid: mhv_correlation_id) if mhv_correlation_id
  when SAML::User::DSLOGON_CSID
    return UserVerification.find_by(dslogon_uuid: identity.edipi) if identity.edipi
  when SAML::User::LOGINGOV_CSID
    return UserVerification.find_by(logingov_uuid:) if logingov_uuid
  end
  return nil unless idme_uuid

  UserVerification.find_by(idme_uuid:) || UserVerification.find_by(backing_idme_uuid: idme_uuid)
end

#given_namesObject



255
256
257
# File 'app/models/user.rb', line 255

def given_names
  mpi_profile&.given_names
end

#home_phoneObject



259
260
261
# File 'app/models/user.rb', line 259

def home_phone
  mpi_profile&.home_phone
end

#icnObject



142
143
144
# File 'app/models/user.rb', line 142

def icn
  identity&.icn || mpi&.icn
end

#identityObject



396
397
398
# File 'app/models/user.rb', line 396

def identity
  @identity ||= UserIdentity.find(uuid)
end

#in_progress_formsObject



364
365
366
# File 'app/models/user.rb', line 364

def in_progress_forms
  InProgressForm.for_user(self)
end

#initial_sign_inObject



51
52
53
# File 'app/models/user.rb', line 51

def 
  .created_at
end

#invalidate_mpi_cacheObject

Other MPI



321
322
323
324
325
326
# File 'app/models/user.rb', line 321

def invalidate_mpi_cache
  return unless loa3? && mpi.mpi_response_is_cached? && mpi.mvi_response

  mpi.destroy
  @mpi = nil
end

#last_nameObject



175
176
177
# File 'app/models/user.rb', line 175

def last_name
  identity.last_name.presence || last_name_mpi
end

#last_name_mpiObject



263
264
265
# File 'app/models/user.rb', line 263

def last_name_mpi
  mpi_profile&.family_name
end

#loaObject



146
147
148
# File 'app/models/user.rb', line 146

def loa
  identity&.loa || {}
end

#log_mhv_user_account_error(error_message) ⇒ Object (private)



531
532
533
# File 'app/models/user.rb', line 531

def (error_message)
  Rails.logger.info('[User] mhv_user_account error', error_message:, icn:)
end

#mhv_account_stateObject



267
268
269
270
271
272
273
# File 'app/models/user.rb', line 267

def 
  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_typeObject



150
151
152
# File 'app/models/user.rb', line 150

def 
  identity. || MHVAccountTypeService.new(self).
end

#mhv_correlation_idObject



154
155
156
# File 'app/models/user.rb', line 154

def mhv_correlation_id
  identity.mhv_correlation_id || mpi_mhv_correlation_id
end

#mhv_idsObject



275
276
277
# File 'app/models/user.rb', line 275

def mhv_ids
  mpi_profile&.mhv_ids
end

#mhv_user_accountObject



158
159
160
161
162
163
164
165
166
167
168
169
# File 'app/models/user.rb', line 158

def 
  @mhv_user_account ||= if va_patient?
                          MHV::UserAccount::Creator.new(user_verification:).perform
                        else
                          ('User has no va_treatment_facility_ids')

                          nil
                        end
rescue MHV::UserAccount::Errors::UserAccountError => e
  (e.message)
  raise
end

#middle_nameObject



171
172
173
# File 'app/models/user.rb', line 171

def middle_name
  identity.middle_name.presence || middle_name_mpi
end

#middle_name_mpiObject



247
248
249
# File 'app/models/user.rb', line 247

def middle_name_mpi
  mpi&.profile&.given_names.to_a[1..]&.join(' ').presence
end

#mpiObject (private)



487
488
489
# File 'app/models/user.rb', line 487

def mpi
  @mpi ||= MPIData.for_user(identity)
end

#mpi_gcidsObject



307
308
309
# File 'app/models/user.rb', line 307

def mpi_gcids
  mpi_profile&.full_mvi_ids || []
end

#mpi_profileObject (private)



481
482
483
484
485
# File 'app/models/user.rb', line 481

def mpi_profile
  return nil unless identity && mpi

  mpi.profile
end

#mpi_profile?Boolean

Returns:

  • (Boolean)


295
296
297
# File 'app/models/user.rb', line 295

def mpi_profile?
  mpi_profile != nil
end

#mpi_profile_relationshipsObject (private)



514
515
516
517
518
# File 'app/models/user.rb', line 514

def mpi_profile_relationships
  return unless mpi_profile && mpi_profile.relationships.presence

  mpi_profile.relationships.map { |relationship| UserRelationship.from_mpi_relationship(relationship) }
end

#needs_accepted_terms_of_useObject



61
62
63
64
65
# File 'app/models/user.rb', line 61

def needs_accepted_terms_of_use
  return @needs_accepted_terms_of_use unless @needs_accepted_terms_of_use.nil?

  @needs_accepted_terms_of_use = &.needs_accepted_terms_of_use?
end

#normalized_suffixObject



279
280
281
# File 'app/models/user.rb', line 279

def normalized_suffix
  mpi_profile&.normalized_suffix
end

#onboardingObject



400
401
402
# File 'app/models/user.rb', line 400

def onboarding
  @onboarding ||= VeteranOnboarding.for_user(self)
end

#pciuObject (private)



527
528
529
# File 'app/models/user.rb', line 527

def pciu
  @pciu ||= EVSS::PCIU::Service.new self if loa3? && edipi.present?
end

#pciu_alternate_phoneObject



91
92
93
# File 'app/models/user.rb', line 91

def pciu_alternate_phone
  pciu&.get_alternate_phone&.to_s
end

#pciu_emailObject



83
84
85
# File 'app/models/user.rb', line 83

def pciu_email
  pciu&.get_email_address&.email
end

#pciu_primary_phoneObject



87
88
89
# File 'app/models/user.rb', line 87

def pciu_primary_phone
  pciu&.get_primary_phone&.to_s
end

#postal_codeObject



283
284
285
# File 'app/models/user.rb', line 283

def postal_code
  mpi&.profile&.address&.postal_code
end

#power_of_attorneyObject



455
456
457
# File 'app/models/user.rb', line 455

def power_of_attorney
  EVSS::CommonService.get_current_info[:poa]
end

#preferred_nameObject



134
135
136
# File 'app/models/user.rb', line 134

def preferred_name
  preferred_name_mpi
end

#preferred_name_mpiObject



243
244
245
# File 'app/models/user.rb', line 243

def preferred_name_mpi
  mpi_profile&.preferred_names&.first
end

#recacheObject

Re-caches the MPI response. Use in response to any local changes that have been made.



370
371
372
# File 'app/models/user.rb', line 370

def recache
  mpi.cache(uuid, mpi.mvi_response)
end

#relationshipsObject



463
464
465
# File 'app/models/user.rb', line 463

def relationships
  @relationships ||= get_relationships_array
end

#sec_idObject



179
180
181
# File 'app/models/user.rb', line 179

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’.

Returns:

  • (Boolean)


451
452
453
# File 'app/models/user.rb', line 451

def served_in_military?
  edipi.present? && veteran? || military_person?
end

#set_mhv_ids(mhv_id) ⇒ Object

MPI setter methods



313
314
315
316
317
# File 'app/models/user.rb', line 313

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

#ssnObject



183
184
185
# File 'app/models/user.rb', line 183

def ssn
  identity&.ssn || ssn_mpi
end

#ssn_mismatch?Boolean

Returns:

  • (Boolean)


332
333
334
335
336
# File 'app/models/user.rb', line 332

def ssn_mismatch?
  return false unless loa3? && identity&.ssn && ssn_mpi

  identity.ssn != ssn_mpi
end

#ssn_mpiObject



287
288
289
# File 'app/models/user.rb', line 287

def ssn_mpi
  mpi_profile&.ssn
end

#ssn_normalizedObject



187
188
189
# File 'app/models/user.rb', line 187

def ssn_normalized
  ssn&.gsub(/[^\d]/, '')
end

#suffixObject



291
292
293
# File 'app/models/user.rb', line 291

def suffix
  mpi_profile&.suffix
end

#user_accountObject



71
72
73
# File 'app/models/user.rb', line 71

def 
  @user_account ||= user_verification&.
end

#user_account_uuidObject



79
80
81
# File 'app/models/user.rb', line 79

def 
  @user_account_uuid ||= &.id
end

#user_verificationObject



67
68
69
# File 'app/models/user.rb', line 67

def user_verification
  @user_verification ||= UserVerification.find_by(id: user_verification_id)
end

#user_verification_idObject



75
76
77
# File 'app/models/user.rb', line 75

def user_verification_id
  @user_verification_id ||= get_user_verification&.id
end

#va_patient?Boolean

True if the user has 1 or more treatment facilities, false otherwise

Returns:

  • (Boolean)


343
344
345
# File 'app/models/user.rb', line 343

def va_patient?
  va_treatment_facility_ids.any?
end

#va_profile_emailObject



413
414
415
# File 'app/models/user.rb', line 413

def va_profile_email
  vet360_contact_info&.email&.email_address
end

#va_profile_v2_emailObject



421
422
423
# File 'app/models/user.rb', line 421

def va_profile_v2_email
  vaprofile_contact_info&.email&.email_address
end

#va_treatment_facility_idsObject

User’s profile contains a list of VHA facility-specific identifiers. Facilities in the defined range are treating facilities



349
350
351
352
353
354
355
# File 'app/models/user.rb', line 349

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

#vaprofile_contact_infoObject



417
418
419
# File 'app/models/user.rb', line 417

def vaprofile_contact_info
  @vaprofile_contact_info ||= VAProfileRedis::V2::ContactInformation.for_user(self)
end

#vet360_contact_infoObject



407
408
409
410
411
# File 'app/models/user.rb', line 407

def vet360_contact_info
  return nil unless VAProfile::Configuration::SETTINGS.contact_information.enabled && vet360_id.present?

  @vet360_contact_info ||= VAProfileRedis::ContactInformation.for_user(self)
end

#veteran_statusObject



380
381
382
# File 'app/models/user.rb', line 380

def veteran_status
  @veteran_status ||= VAProfileRedis::VeteranStatus.for_user(self)
end

#vha_facility_hashObject



303
304
305
# File 'app/models/user.rb', line 303

def vha_facility_hash
  mpi_profile&.vha_facility_hash || {}
end

#vha_facility_idsObject



299
300
301
# File 'app/models/user.rb', line 299

def vha_facility_ids
  mpi_profile&.vha_facility_ids || []
end