Class: User

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

Direct Known Subclasses

IAMUser, OpenidUser

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



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

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

#account_idObject



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

def 
  @account_id ||= &.id
end

#account_uuidObject



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

def 
  @account_uuid ||= &.uuid
end

#active_mhv_idsObject



193
194
195
# File 'app/models/user.rb', line 193

def active_mhv_ids
  mpi_profile&.active_mhv_ids
end

#addressObject



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_emailsObject



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_dateObject

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_mpiObject



213
214
215
# File 'app/models/user.rb', line 213

def birth_date_mpi
  mpi_profile&.birth_date
end

#can_access_id_card?Boolean

Returns:

  • (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 # Default to false for any veteran_status error
  false
end

#can_access_user_profile?Boolean

Returns:

  • (Boolean)


316
317
318
# File 'app/models/user.rb', line 316

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

#can_access_vet360?Boolean

Returns:

  • (Boolean)


414
415
416
417
418
# File 'app/models/user.rb', line 414

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

#common_nameObject



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

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

#credential_lockObject



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

#deceased_dateObject



209
210
211
# File 'app/models/user.rb', line 209

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

#destroyObject

destroy both UserIdentity and self



353
354
355
356
# File 'app/models/user.rb', line 353

def destroy
  identity&.destroy
  super
end

#edipiObject



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

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

#edipi_mpiObject



217
218
219
# File 'app/models/user.rb', line 217

def edipi_mpi
  mpi_profile&.edipi
end

#first_nameObject



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

def first_name
  identity.first_name.presence || first_name_mpi
end

#first_name_mpiObject



221
222
223
# File 'app/models/user.rb', line 221

def first_name_mpi
  given_names&.first
end

#flipper_idObject



434
435
436
# File 'app/models/user.rb', line 434

def flipper_id
  email&.downcase || 
end

#full_name_normalizedObject



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

#genderObject



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

def gender
  identity.gender.presence || gender_mpi
end

#gender_mpiObject



229
230
231
# File 'app/models/user.rb', line 229

def gender_mpi
  mpi_profile&.gender
end

#given_namesObject



233
234
235
# File 'app/models/user.rb', line 233

def given_names
  mpi_profile&.given_names
end

#home_phoneObject



237
238
239
# File 'app/models/user.rb', line 237

def home_phone
  mpi_profile&.home_phone
end

#icnObject



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

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

#identityObject



386
387
388
# File 'app/models/user.rb', line 386

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

#in_progress_formsObject



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

def in_progress_forms
  InProgressForm.for_user(self)
end

#inherited_proof_verifiedObject



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

def inherited_proof_verified
  @inherited_proof_verified ||= InheritedProofVerifiedUserAccount.where(user_account_id: ).present?
end

#invalidate_mpi_cacheObject

Other MPI



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_nameObject



157
158
159
# File 'app/models/user.rb', line 157

def last_name
  identity.last_name.presence || last_name_mpi
end

#last_name_mpiObject



241
242
243
# File 'app/models/user.rb', line 241

def last_name_mpi
  mpi_profile&.family_name
end

#loaObject



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

def loa
  identity&.loa || {}
end

#mhv_account_stateObject



245
246
247
248
249
250
251
# File 'app/models/user.rb', line 245

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



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

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

#mhv_correlation_idObject



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

def mhv_correlation_id
  identity.mhv_correlation_id || mpi_mhv_correlation_id
end

#mhv_idsObject



253
254
255
# File 'app/models/user.rb', line 253

def mhv_ids
  mpi_profile&.mhv_ids
end

#middle_nameObject



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

def middle_name
  identity.middle_name.presence || middle_name_mpi
end

#middle_name_mpiObject



225
226
227
# File 'app/models/user.rb', line 225

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

#military_informationObject



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

def military_information
  @military_information ||= if Flipper.enabled?(:military_information_vaprofile)
                              FormProfile.new(form_id: nil, user: self).initialize_military_information
                            else
                              EMISRedis::MilitaryInformation.for_user(self)
                            end
end

#mpi_gcidsObject



285
286
287
# File 'app/models/user.rb', line 285

def mpi_gcids
  mpi_profile&.full_mvi_ids || []
end

#mpi_profile?Boolean

Returns:

  • (Boolean)


273
274
275
# File 'app/models/user.rb', line 273

def mpi_profile?
  mpi_profile != nil
end

#needs_accepted_terms_of_useObject



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 = &.needs_accepted_terms_of_use?
end

#normalized_suffixObject



257
258
259
# File 'app/models/user.rb', line 257

def normalized_suffix
  mpi_profile&.normalized_suffix
end

#pciu_alternate_phoneObject



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

def pciu_alternate_phone
  pciu&.get_alternate_phone&.to_s
end

#pciu_emailObject



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

def pciu_email
  pciu&.get_email_address&.email
end

#pciu_primary_phoneObject



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

def pciu_primary_phone
  pciu&.get_primary_phone&.to_s
end

#postal_codeObject



261
262
263
# File 'app/models/user.rb', line 261

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

#power_of_attorneyObject



430
431
432
# File 'app/models/user.rb', line 430

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

#recacheObject

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

#relationshipsObject



438
439
440
# File 'app/models/user.rb', line 438

def relationships
  @relationships ||= get_relationships_array
end

#sec_idObject



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

Returns:

  • (Boolean)


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

MPI setter methods



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

#ssnObject



165
166
167
# File 'app/models/user.rb', line 165

def ssn
  identity&.ssn || ssn_mpi
end

#ssn_mismatch?Boolean

Returns:

  • (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_mpiObject



265
266
267
# File 'app/models/user.rb', line 265

def ssn_mpi
  mpi_profile&.ssn
end

#ssn_normalizedObject



169
170
171
# File 'app/models/user.rb', line 169

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

#suffixObject



269
270
271
# File 'app/models/user.rb', line 269

def suffix
  mpi_profile&.suffix
end

#user_accountObject



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

def 
  @user_account ||= user_verification&.
end

#user_account_uuidObject



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

def 
  @user_account_uuid ||= &.id
end

#user_verificationObject



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

def user_verification
  @user_verification ||= get_user_verification
end

#user_verification_idObject



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

Returns:

  • (Boolean)


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

def va_patient?
  va_treatment_facility_ids.length.positive?
end

#va_profile_emailObject



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

def va_profile_email
  vet360_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



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

#vet360_contact_infoObject



390
391
392
393
394
# File 'app/models/user.rb', line 390

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



366
367
368
369
370
371
372
# File 'app/models/user.rb', line 366

def veteran_status
  @veteran_status ||= if Flipper.enabled?(:veteran_status_updated)
                        VAProfileRedis::VeteranStatus.for_user(self)
                      else
                        EMISRedis::VeteranStatus.for_user(self)
                      end
end

#vha_facility_hashObject



281
282
283
# File 'app/models/user.rb', line 281

def vha_facility_hash
  mpi_profile&.vha_facility_hash || {}
end

#vha_facility_idsObject



277
278
279
# File 'app/models/user.rb', line 277

def vha_facility_ids
  mpi_profile&.vha_facility_ids || []
end