Class: Users::Profile
- Inherits:
-
Object
- Object
- Users::Profile
- Includes:
- Common::Client::Concerns::ServiceStatus
- Defined in:
- app/services/users/profile.rb
Constant Summary collapse
- HTTP_OK =
200
- HTTP_SOME_ERRORS =
296
Constants included from Common::Client::Concerns::ServiceStatus
Common::Client::Concerns::ServiceStatus::RESPONSE_STATUS
Instance Attribute Summary collapse
-
#scaffold ⇒ Object
readonly
Returns the value of attribute scaffold.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #account ⇒ Object private
-
#claims ⇒ Object
private
rubocop:enable Metrics/MethodLength.
- #facility(facility_id) ⇒ Object private
- #fetch_and_serialize_profile ⇒ Object private
- #form_526_required_identifiers ⇒ Object private
- #in_progress_forms ⇒ Object private
-
#initialize(user, session = nil) ⇒ Profile
constructor
A new instance of Profile.
- #mpi_profile ⇒ Object private
- #onboarding ⇒ Object private
-
#pre_serialize ⇒ Struct
Fetches and serializes all of the initialized user’s profile data that is returned in the ‘/v0/user’ endpoint.
- #prefills_available ⇒ Object private
-
#profile ⇒ Object
private
rubocop:disable Metrics/MethodLength.
- #services ⇒ Object private
- #session_data ⇒ Object private
- #update_status_and_errors ⇒ Object private
- #validate!(user) ⇒ Object private
- #vet360_contact_information ⇒ Object private
- #veteran_status ⇒ Object private
Constructor Details
Instance Attribute Details
#scaffold ⇒ Object (readonly)
Returns the value of attribute scaffold.
13 14 15 |
# File 'app/services/users/profile.rb', line 13 def scaffold @scaffold end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
13 14 15 |
# File 'app/services/users/profile.rb', line 13 def user @user end |
Instance Method Details
#account ⇒ Object (private)
60 61 62 63 64 65 |
# File 'app/services/users/profile.rb', line 60 def account { account_uuid: user.account_uuid } rescue => e scaffold.errors << Users::ExceptionHandler.new(e, 'Account').serialize_error nil end |
#claims ⇒ Object (private)
rubocop:enable Metrics/MethodLength
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/services/users/profile.rb', line 97 def claims if Flipper.enabled?(:profile_user_claims, user) { appeals: AppealsPolicy.new(user).access?, coe: CoePolicy.new(user).access?, communication_preferences: Vet360Policy.new(user).access? && CommunicationPreferencesPolicy.new(user).access?, connected_apps: true, medical_copays: MedicalCopaysPolicy.new(user).access?, military_history: Vet360Policy.new(user).military_access?, payment_history: BGSPolicy.new(user).access?(log_stats: false), personal_information: MPIPolicy.new(user).queryable?, rating_info: LighthousePolicy.new(user)., **form_526_required_identifiers } end end |
#facility(facility_id) ⇒ Object (private)
205 206 207 208 209 210 211 |
# File 'app/services/users/profile.rb', line 205 def facility(facility_id) cerner_facility_ids = user.cerner_facility_ids || [] { facility_id:, is_cerner: cerner_facility_ids.include?(facility_id) } end |
#fetch_and_serialize_profile ⇒ Object (private)
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/users/profile.rb', line 47 def fetch_and_serialize_profile scaffold.account = account scaffold.profile = profile scaffold.vet360_contact_information = vet360_contact_information scaffold.va_profile = mpi_profile scaffold.veteran_status = veteran_status scaffold.in_progress_forms = in_progress_forms scaffold.prefills_available = prefills_available scaffold.services = services scaffold.session = session_data scaffold.onboarding = onboarding end |
#form_526_required_identifiers ⇒ Object (private)
115 116 117 118 119 |
# File 'app/services/users/profile.rb', line 115 def form_526_required_identifiers return {} unless Flipper.enabled?(:form_526_required_identifiers_in_user_object, user) { form526_required_identifier_presence: Users::Form526UserIdentifiersStatusService.call(user) } end |
#in_progress_forms ⇒ Object (private)
177 178 179 180 181 182 183 184 185 |
# File 'app/services/users/profile.rb', line 177 def in_progress_forms InProgressForm.submission_pending.for_user(user).map do |form| { form: form.form_id, metadata: form., lastUpdated: form.updated_at.to_i } end end |
#mpi_profile ⇒ Object (private)
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'app/services/users/profile.rb', line 143 def mpi_profile status = user.mpi_status if status == :ok { status: RESPONSE_STATUS[:ok], birth_date: user.birth_date_mpi, family_name: user.last_name_mpi, gender: user.gender_mpi, given_names: user.given_names, is_cerner_patient: !user.cerner_id.nil?, cerner_id: user.cerner_id, cerner_facility_ids: user.cerner_facility_ids, facilities: user.va_treatment_facility_ids.map { |id| facility(id) }, va_patient: user.va_patient?, mhv_account_state: user.mhv_account_state, active_mhv_ids: user.active_mhv_ids } else scaffold.errors << Users::ExceptionHandler.new(user.mpi_error, 'MVI').serialize_error nil end end |
#onboarding ⇒ Object (private)
221 222 223 224 225 |
# File 'app/services/users/profile.rb', line 221 def onboarding { show: user.show_onboarding_flow_on_login } end |
#pre_serialize ⇒ Struct
Fetches and serializes all of the initialized user’s profile data that is returned in the ‘/v0/user’ endpoint.
If there are no external service errors, the status property is set to 200, and the ‘errors` property is set to nil.
If there are errors from any associated external services, the status property is set to 296, and serialized versions of the errors are added to the ‘errors` array.
33 34 35 36 37 |
# File 'app/services/users/profile.rb', line 33 def pre_serialize fetch_and_serialize_profile update_status_and_errors scaffold end |
#prefills_available ⇒ Object (private)
187 188 189 190 191 |
# File 'app/services/users/profile.rb', line 187 def prefills_available return [] if user.identity.blank? FormProfile.prefill_enabled_forms end |
#profile ⇒ Object (private)
rubocop:disable Metrics/MethodLength
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/services/users/profile.rb', line 68 def profile { email: user.email, first_name: user.first_name, middle_name: user.middle_name, last_name: user.last_name, preferred_name: user.preferred_name, birth_date: user.birth_date, gender: user.gender, zip: user.postal_code, last_signed_in: user.last_signed_in, loa: user.loa, multifactor: user.multifactor, verified: user.loa3?, sign_in: user.identity.sign_in, authn_context: user.authn_context, claims:, icn: user.icn, birls_id: user.birls_id, edipi: user.edipi, sec_id: user.sec_id, logingov_uuid: user.logingov_uuid, idme_uuid: user.idme_uuid, id_theft_flag: user.id_theft_flag, initial_sign_in: user.initial_sign_in } end |
#services ⇒ Object (private)
193 194 195 |
# File 'app/services/users/profile.rb', line 193 def services Users::Services.new(user). end |
#session_data ⇒ Object (private)
213 214 215 216 217 218 219 |
# File 'app/services/users/profile.rb', line 213 def session_data { auth_broker: @user.identity.sign_in[:auth_broker], ssoe: @session[:ssoe_transactionid] ? true : false, transactionid: @session[:ssoe_transactionid] } end |
#update_status_and_errors ⇒ Object (private)
197 198 199 200 201 202 203 |
# File 'app/services/users/profile.rb', line 197 def update_status_and_errors if scaffold.errors.present? scaffold.status = HTTP_SOME_ERRORS else scaffold.errors = nil end end |
#validate!(user) ⇒ Object (private)
41 42 43 44 45 |
# File 'app/services/users/profile.rb', line 41 def validate!(user) raise Common::Exceptions::ParameterMissing.new('user'), 'user' unless user&.class == User user end |
#vet360_contact_information ⇒ Object (private)
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/services/users/profile.rb', line 121 def vet360_contact_information contact_info_v2_enabled = Flipper.enabled?(:va_v3_contact_information_service, user) person = contact_info_v2_enabled ? user.vaprofile_contact_info : user.vet360_contact_info return {} if person.blank? { vet360_id: user.vet360_id, va_profile_id: user.vet360_id, email: person.email, residential_address: person.residential_address, mailing_address: person.mailing_address, mobile_phone: person.mobile_phone, home_phone: person.home_phone, work_phone: person.work_phone, temporary_phone: person.temporary_phone, fax_number: person.fax_number } rescue => e scaffold.errors << Users::ExceptionHandler.new(e, 'VAProfile').serialize_error nil end |
#veteran_status ⇒ Object (private)
166 167 168 169 170 171 172 173 174 175 |
# File 'app/services/users/profile.rb', line 166 def veteran_status { status: RESPONSE_STATUS[:ok], is_veteran: user.veteran?, served_in_military: user.served_in_military? } rescue => e scaffold.errors << Users::ExceptionHandler.new(e, 'VAProfile').serialize_error nil end |