Class: TermsOfUse::SignUpServiceUpdaterJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/sidekiq/terms_of_use/sign_up_service_updater_job.rb

Constant Summary collapse

LOG_TITLE =
'[TermsOfUse][SignUpServiceUpdaterJob]'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#user_account_uuidObject (readonly)

Returns the value of attribute user_account_uuid.



30
31
32
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 30

def 
  @user_account_uuid
end

#versionObject (readonly)

Returns the value of attribute version.



30
31
32
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 30

def version
  @version
end

Instance Method Details

#acceptObject (private)



70
71
72
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 70

def accept
  map_client.agreements_accept(icn: mpi_profile.icn, signature_name:, version:)
end

#agreement_unchanged?Boolean (private)

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 59

def agreement_unchanged?
  if terms_of_use_agreement.declined? != map_status[:opt_out] ||
     terms_of_use_agreement.accepted? != map_status[:agreement_signed]
    return false
  end

  Rails.logger.info("#{LOG_TITLE} Not updating Sign Up Service due to unchanged agreement",
                    { icn: .icn })
  true
end

#declineObject (private)



74
75
76
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 74

def decline
  map_client.agreements_decline(icn: mpi_profile.icn)
end

#log_updated_icnObject (private)



44
45
46
47
48
49
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 44

def log_updated_icn
  if .icn != mpi_profile.icn
    Rails.logger.info("#{LOG_TITLE} Detected changed ICN for user",
                      { icn: .icn, mpi_icn: mpi_profile.icn })
  end
end

#map_clientObject (private)



51
52
53
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 51

def map_client
  @map_client ||= MAP::SignUp::Service.new
end

#map_statusObject (private)



55
56
57
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 55

def map_status
  @map_status ||= map_client.status(icn: mpi_profile.icn)
end

#missing_sec_id?Boolean (private)

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
86
87
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 78

def missing_sec_id?
  if mpi_profile.sec_id.present?
    validate_multiple_sec_ids
    return false
  end

  Rails.logger.info("#{LOG_TITLE} Sign Up Service not updated due to user missing sec_id",
                    { icn: .icn })
  true
end

#mpi_profileObject (private)



107
108
109
110
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 107

def mpi_profile
  @mpi_profile ||= MPI::Service.new.find_profile_by_identifier(identifier: .icn,
                                                               identifier_type: MPI::Constants::ICN)&.profile
end

#perform(user_account_uuid, version) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 32

def perform(, version)
  @user_account_uuid = 
  @version = version

  return if missing_sec_id? || agreement_unchanged?

  log_updated_icn
  terms_of_use_agreement.accepted? ? accept : decline
end

#signature_nameObject (private)



103
104
105
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 103

def signature_name
  "#{mpi_profile.given_names.first} #{mpi_profile.family_name}"
end

#terms_of_use_agreementObject (private)



99
100
101
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 99

def terms_of_use_agreement
  .terms_of_use_agreements.where(agreement_version: version).last
end

#user_accountObject (private)



95
96
97
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 95

def 
  @user_account ||= UserAccount.find()
end

#validate_multiple_sec_idsObject (private)



89
90
91
92
93
# File 'app/sidekiq/terms_of_use/sign_up_service_updater_job.rb', line 89

def validate_multiple_sec_ids
  if mpi_profile.sec_ids.many?
    Rails.logger.info("#{LOG_TITLE} Multiple sec_id values detected", { icn: .icn })
  end
end