Class: VeteranOnboarding
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- VeteranOnboarding
- Defined in:
- app/models/veteran_onboarding.rb
Overview
The VeteranOnboarding model represents the onboarding status of a veteran. Each instance corresponds to a veteran who is in the process of onboarding.
Schema Information
Table name: veteran_onboardings
id :bigint not null, primary key
user_account_uuid :string not null, unique
display_onboarding_flow :boolean default(TRUE)
created_at :datetime not null
updated_at :datetime not null
Instance Attribute Summary collapse
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#show_onboarding_flow_on_login ⇒ Object
Determines whether the onboarding flow should be displayed for a veteran.
Methods inherited from ApplicationRecord
descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?
Instance Attribute Details
#user ⇒ Object
Returns the value of attribute user.
20 21 22 |
# File 'app/models/veteran_onboarding.rb', line 20 def user @user end |
Class Method Details
.for_user(user) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/veteran_onboarding.rb', line 46 def self.for_user(user) if user.user_account&.verified? && ( Flipper.enabled?(:veteran_onboarding_beta_flow, user) || Flipper.enabled?(:veteran_onboarding_show_to_newly_onboarded, user) ) veteran_onboarding = find_or_create_by(user_account: user.user_account) veteran_onboarding.user = user veteran_onboarding end end |
Instance Method Details
#show_onboarding_flow_on_login ⇒ Object
Determines whether the onboarding flow should be displayed for a veteran. Currently, we have two feature toggle checks:
-
veteran_onboarding_show_to_newly_onboarded examines settings for veteran_onboarding.onboarding_threshold_days, (default 180 days) and examines the user_verification.verified_at attribute
-
veteran_onboarding_beta_flow just checks if the feature toggle is enabled for the user
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/veteran_onboarding.rb', line 27 def show_onboarding_flow_on_login if @user.user_account&.verified? if Flipper.enabled?(:veteran_onboarding_show_to_newly_onboarded, @user) days_since_verification = UserVerification.where(user_account_id: @user.user_account_uuid).map do |uv| (Time.zone.today - uv.verified_at.to_date).to_i end.max threshold_days = Settings.veteran_onboarding&.onboarding_threshold_days || 180 if days_since_verification <= threshold_days display_onboarding_flow else update!(display_onboarding_flow: false) false end elsif Flipper.enabled?(:veteran_onboarding_beta_flow, @user) display_onboarding_flow end end end |