Class: InProgressForm

Inherits:
ApplicationRecord show all
Defined in:
app/models/in_progress_form.rb

Defined Under Namespace

Classes: CleanUUID

Constant Summary collapse

RETURN_URL_SQL =
"CAST(metadata -> 'returnUrl' AS text)"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Instance Attribute Details

#real_user_uuidObject

Returns the value of attribute real_user_uuid.



16
17
18
# File 'app/models/in_progress_form.rb', line 16

def real_user_uuid
  @real_user_uuid
end

#skip_exipry_updateObject

Returns the value of attribute skip_exipry_update.



16
17
18
# File 'app/models/in_progress_form.rb', line 16

def skip_exipry_update
  @skip_exipry_update
end

Class Method Details

.for_user(user) ⇒ Object



67
68
69
70
71
72
73
74
# File 'app/models/in_progress_form.rb', line 67

def self.for_user(user)
  user_uuid_forms = InProgressForm.where(user_uuid: user.uuid)
  if user.
    user_uuid_forms.or(InProgressForm.where(user_account: user.))
  else
    user_uuid_forms
  end
end

.form_for_user(form_id, user) ⇒ Object



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

def self.form_for_user(form_id, user)
  user_uuid_form = InProgressForm.find_by(form_id:, user_uuid: user.uuid)
   = InProgressForm.find_by(form_id:, user_account: user.) if user.
  user_uuid_form || 
end

Instance Method Details

#custom_expires_afterObject (private)



152
153
154
155
156
# File 'app/models/in_progress_form.rb', line 152

def custom_expires_after
  options = { form_id:, days_till_expires: }

  FormDurations::Worker.build(options).get_duration
end

#data_and_metadataObject



76
77
78
79
80
81
# File 'app/models/in_progress_form.rb', line 76

def 
  {
    formData: JSON.parse(form_data),
    metadata:
  }
end

#days_till_expiresObject (private)



139
140
141
# File 'app/models/in_progress_form.rb', line 139

def days_till_expires
  @days_till_expires ||= JSON.parse(form_data)['days_till_expires']
end

#default_expires_afterObject (private)



143
144
145
146
147
148
149
150
# File 'app/models/in_progress_form.rb', line 143

def default_expires_after
  case form_id
  when '21-526EZ', '21P-527EZ', '21P-530V2'
    1.year
  else
    60.days
  end
end

#expires_afterActiveSupport::Duration

Determines an expiration duration based on the UI form_id. If the in_progress_form_custom_expiration feature is enabled, the method can additionally return custom expiration durations whose values are passed in as Strings from the UI.

Returns:

  • (ActiveSupport::Duration)

    an instance of ActiveSupport::Duration



102
103
104
105
106
107
108
109
# File 'app/models/in_progress_form.rb', line 102

def expires_after
  @expires_after ||=
    if Flipper.enabled?(:in_progress_form_custom_expiration)
      custom_expires_after
    else
      default_expires_after
    end
end

#id_me_user_uuidObject (private)

Some IDs we get from ID.me are 20, 21, 22 or 23 char hex strings > we started off with just 22 random hex chars (from openssl random bytes) years > ago, and switched to UUID v4 (minus dashes) later on dsva.slack.com/archives/C1A7KLZ9B/p1501856503336861



121
122
123
124
125
# File 'app/models/in_progress_form.rb', line 121

def id_me_user_uuid
  if user_uuid && !user_uuid.length.in?([20, 21, 22, 23, 32])
    errors.add(:user_uuid, "(#{user_uuid}) is not a proper length")
  end
end

#log_hca_email_diffObject (private)



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

def log_hca_email_diff
  HCA::LogEmailDiffJob.perform_async(id, real_user_uuid) if form_id == '1010ez'
end

#metadataObject



83
84
85
86
87
88
89
90
91
92
# File 'app/models/in_progress_form.rb', line 83

def 
  data = super || {}
  last_accessed = updated_at || Time.current
  data.merge(
    'createdAt' => created_at&.to_time.to_i,
    'expiresAt' => expires_at.to_i || (last_accessed + expires_after).to_i,
    'lastUpdated' => updated_at.to_i,
    'inProgressFormId' => id
  )
end

#serialize_form_dataObject (private)



127
128
129
# File 'app/models/in_progress_form.rb', line 127

def serialize_form_data
  self.form_data = form_data.to_json unless form_data.is_a?(String)
end

#set_expires_atObject (private)



131
132
133
# File 'app/models/in_progress_form.rb', line 131

def set_expires_at
  self.expires_at = Time.current + expires_after
end

#skip_exipry_update_checkObject (private)



135
136
137
# File 'app/models/in_progress_form.rb', line 135

def skip_exipry_update_check
  self.skip_exipry_update = expires_at.present?
end