Class: Login::UserAcceptableVerifiedCredentialUpdaterLogger

Inherits:
Object
  • Object
show all
Defined in:
app/services/login/user_acceptable_verified_credential_updater_logger.rb

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.user_avc_updater'
LOG_MESSAGE =
'[UserAcceptableVerifiedCredentialUpdater] - User AVC Updated'
FROM_TYPES =
[MHV_TYPE = 'mhv', DSLOGON_TYPE = 'dslogon', IDME_TYPE = 'idme', LOGINGOV_TYPE = 'logingov'].freeze
ADDED_TYPES =
[AVC_TYPE = 'avc', IVC_TYPE = 'ivc'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_acceptable_verified_credential:) ⇒ UserAcceptableVerifiedCredentialUpdaterLogger

Returns a new instance of UserAcceptableVerifiedCredentialUpdaterLogger.



10
11
12
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 10

def initialize(user_acceptable_verified_credential:)
  @user_avc = user_acceptable_verified_credential
end

Instance Attribute Details

#user_avcObject (readonly, private)

Returns the value of attribute user_avc.



23
24
25
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 23

def user_avc
  @user_avc
end

Instance Method Details

#added_avc_only?Boolean (private)

Checks if the newly added avc is the only verified_credential_at that exists.

Returns:

  • (Boolean)


171
172
173
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 171

def added_avc_only?
  avc_added? && user_avc.idme_verified_credential_at.nil?
end

#added_from_typeObject (private)



51
52
53
54
55
56
57
58
59
60
61
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 51

def added_from_type
  @added_from_type ||= if from_mhv?
                         MHV_TYPE
                       elsif from_dslogon?
                         DSLOGON_TYPE
                       elsif from_logingov?
                         LOGINGOV_TYPE
                       elsif from_idme?
                         IDME_TYPE
                       end
end

#added_ivc_only?Boolean (private)

Checks if the newly added ivc is the only verified_credential_at that exists.

Returns:

  • (Boolean)


165
166
167
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 165

def added_ivc_only?
  ivc_added? && user_avc.acceptable_verified_credential_at.nil?
end

#added_typeObject (private)



43
44
45
46
47
48
49
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 43

def added_type
  @added_type ||= if avc_added?
                    AVC_TYPE
                  elsif ivc_added?
                    IVC_TYPE
                  end
end

#avc_added?Boolean (private)

Returns:

  • (Boolean)


123
124
125
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 123

def avc_added?
  user_avc.saved_change_to_acceptable_verified_credential_at?
end

#backing_idme_uuidObject (private)



111
112
113
114
115
116
117
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 111

def backing_idme_uuid
  @backing_idme_uuid ||= if from_mhv?
                           mhv_credential.backing_idme_uuid
                         elsif from_dslogon?
                           dslogon_credential.backing_idme_uuid
                         end
end

#build_log_payloadObject (private)



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 76

def build_log_payload
  payload = {}

  payload[:added_type] = added_type
  payload[:added_from] = added_from_type if added_from_type.present?
  payload[:user_account_id] = .id
  payload[:mhv_uuid] = mhv_credential.mhv_uuid if added_from_type == MHV_TYPE
  payload[:dslogon_uuid] = dslogon_credential.dslogon_uuid if added_from_type == DSLOGON_TYPE
  payload[:backing_idme_uuid] = backing_idme_uuid if backing_idme_uuid.present?
  payload[:idme_uuid] = idme_credential&.idme_uuid
  payload[:logingov_uuid] = logingov_credential&.logingov_uuid

  payload
end

#build_statsd_keysObject (private)



63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 63

def build_statsd_keys
  keys = []
  return keys unless added_type.present? && added_from_type.present?

  keys << "#{STATSD_KEY_PREFIX}.#{added_from_type}.#{added_type}.added"

  if added_from_type == MHV_TYPE || added_from_type == DSLOGON_TYPE
    keys << "#{STATSD_KEY_PREFIX}.#{MHV_TYPE}_#{DSLOGON_TYPE}.#{added_type}.added"
  end

  keys
end

#dslogon_credentialObject (private)



107
108
109
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 107

def dslogon_credential
  @dslogon_credential ||= user_verifications.dslogon.first
end

#from_dslogon?Boolean (private)

When the newly added verified_credential_at is the only one that exists and the user has a dslogon credential it is from dslogon e.g. user_avc_updater.dslogon.#added_type.added

Returns:

  • (Boolean)


139
140
141
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 139

def from_dslogon?
  dslogon_credential.present? && (added_ivc_only? || added_avc_only?)
end

#from_idme?Boolean (private)

Returns:

  • (Boolean)


143
144
145
146
147
148
149
150
151
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 143

def from_idme?
  # When an avc is added on a uavc already having an ivc it is from idme.
  # e.g. user_avc_updater.idme.avc.added
  return user_avc.idme_verified_credential_at.present? if avc_added?

  # When ivc is the only verified_credential_at that exists and it's not from mhv or dslogon,
  # it's from idme e.g. user_avc_updater.idme.ivc.added
  added_ivc_only? && !from_mhv? && !from_dslogon?
end

#from_logingov?Boolean (private)

Returns:

  • (Boolean)


153
154
155
156
157
158
159
160
161
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 153

def from_logingov?
  # When an ivc is added on a uavc already having an avc it is from logingov.
  # e.g. user_avc_updater.logingov.ivc.added
  return user_avc.acceptable_verified_credential_at.present? if ivc_added?

  # When avc is the only verified_credential_at that exists and it's not from mhv or dslogon,
  # it's from logingov e.g. user_avc_updater.logingov.avc.added
  added_avc_only? && !from_mhv? && !from_dslogon?
end

#from_mhv?Boolean (private)

When the newly added verified_credential_at is the only one that exists and the user has a mhv credential it is from mhv e.g. user_avc_updater.mhv.#added_type.added

Returns:

  • (Boolean)


133
134
135
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 133

def from_mhv?
  mhv_credential.present? && (added_ivc_only? || added_avc_only?)
end

#idme_credentialObject (private)



95
96
97
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 95

def idme_credential
  @idme_credential ||= user_verifications.idme.first
end

#increment_statsdObject (private)



25
26
27
28
29
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 25

def increment_statsd
  statsd_keys.each do |key|
    StatsD.increment(key, 1)
  end
end

#ivc_added?Boolean (private)

Returns:

  • (Boolean)


127
128
129
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 127

def ivc_added?
  user_avc.saved_change_to_idme_verified_credential_at?
end

#log_infoObject (private)



31
32
33
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 31

def log_info
  Rails.logger.info(LOG_MESSAGE, log_payload)
end

#log_payloadObject (private)



39
40
41
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 39

def log_payload
  @log_payload ||= build_log_payload
end

#logingov_credentialObject (private)



99
100
101
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 99

def logingov_credential
  @logingov_credential ||= user_verifications.logingov.first
end

#mhv_credentialObject (private)



103
104
105
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 103

def mhv_credential
  @mhv_credential ||= user_verifications.mhv.first
end

#performObject



14
15
16
17
18
19
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 14

def perform
  return if user_avc.nil?

  increment_statsd
  log_info
end

#statsd_keysObject (private)



35
36
37
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 35

def statsd_keys
  @statsd_keys ||= build_statsd_keys
end

#user_accountObject (private)



91
92
93
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 91

def 
  @user_account ||= user_avc.
end

#user_verificationsObject (private)



119
120
121
# File 'app/services/login/user_acceptable_verified_credential_updater_logger.rb', line 119

def user_verifications
  @user_verifications ||= .user_verifications
end