Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 39 additions & 25 deletions app/jobs/reports/irs_verification_report.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

require 'csv'
require 'reporting/irs_verification_report'
require 'reporting/sp_verification_report'

module Reports
class IrsVerificationReport < BaseReport
REPORT_NAME = 'irs-verification-report'
class SpVerificationReport < BaseReport
# REPORT_NAME = 'sp-verification-report'

attr_reader :report_date, :report_receiver
attr_reader :report_date, :report_receiver, :report_name, :report_title

def initialize(init_date = nil, init_receiver = :internal, *args, **rest)
@report_date = init_date
Expand All @@ -19,24 +19,40 @@ def perform(perform_date = Time.zone.yesterday.end_of_day, perform_receiver = :i
@report_date = perform_date
@report_receiver = perform_receiver.to_sym

email_addresses = emails
IdentityConfig.store.sp_verification_report_configs.each do |report_config|
send_report(report_config)
end
end

def send_report(report_config)
issuers = report_config['issuers']
agency_abbreviation = report_config['agency_abbreviation']
partner_emails = report_config['partner_emails']
internal_emails = report_config['internal_emails']

@report_name = "#{agency_abbreviation.downcase}_verification_report"
@report_title = "#{agency_abbreviation} Verification Report"

email_addresses = emails(internal_emails, partner_emails)
to_emails = email_addresses[:to].select(&:present?)
bcc_emails = email_addresses[:bcc].select(&:present?)

if to_emails.empty? && bcc_emails.empty?
Rails.logger.warn 'No email addresses received - IRS Verification Report NOT SENT'
Rails.logger.warn "No email addresses received - #{@report_title} NOT SENT"
return false
end

reports.each do |report|
emailable_reports = reports(issuers, agency_abbreviation)

emailable_reports.each do |report|
upload_to_s3(report.table, report_name: report.filename)
end

ReportMailer.tables_report(
email: to_emails,
bcc: bcc_emails,
subject: "IRS Verification Report - #{report_date.to_date}",
reports: reports,
subject: "#{@report_title} - #{report_date.to_date}",
reports: emailable_reports,
message: preamble,
attachment_format: :csv,
).deliver_now
Expand All @@ -61,41 +77,39 @@ def preamble(env: Identity::Hostdata.env || 'local')
ERB
end

def reports
@reports ||= irs_verification_report.as_emailable_reports
def reports(issuers, agency_abbreviation)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we getting rid of memoization here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was causing an issue. When I was testing it for multiple configs, it was using first created one for the second config as well, and becasue of that both reports were showing the same issuers in the report

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense, there might be a smarter way to do it without completely getting rid of the memoization. Although I wonder if the performance savings is worth it

sp_verification_report(issuers, agency_abbreviation).as_emailable_reports
end

def previous_week_range
@report_date.beginning_of_week(:sunday).prev_occurring(:sunday).all_week(:sunday)
end

def irs_verification_report
@irs_verification_report ||= Reporting::IrsVerificationReport.new(
def sp_verification_report(issuers, agency_abbreviation)
Reporting::SpVerificationReport.new(
time_range: previous_week_range,
issuers: IdentityConfig.store.irs_verification_report_issuers || [],
issuers: issuers || [],
agency_abbreviation: agency_abbreviation,
)
end

def emails
internal_emails = [*IdentityConfig.store.team_daily_reports_emails].select(&:present?)
irs_emails = [*IdentityConfig.store.irs_verification_report_config].select(&:present?)

if report_receiver == :both && irs_emails.empty?
def emails(internal_emails, partner_emails)
if report_receiver == :both && partner_emails.empty?
Rails.logger.warn(
'IRS Verification Report: recipient is :both ' \
'but no external email specified',
"#{@report_title}: recipient is :both " \
"but no external email specified",
)
end

if report_receiver == :both && irs_emails.present?
{ to: irs_emails, bcc: internal_emails }
if report_receiver == :both && partner_emails.present?
{ to: partner_emails, bcc: internal_emails }
else
{ to: internal_emails, bcc: [] }
end
end

def upload_to_s3(report_body, report_name: nil)
_latest, path = generate_s3_paths(REPORT_NAME, 'csv', subname: report_name, now: report_date)
_latest, path = generate_s3_paths(@report_name, 'csv', subname: report_name, now: report_date)

if bucket_name.present?
upload_file_to_s3_bucket(
Expand All @@ -115,4 +129,4 @@ def csv_file(report_array)
end
end
end
end
end
1 change: 1 addition & 0 deletions config/application.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ sp_handoff_bounce_max_seconds: 2
sp_idv_weekly_dropoff_report_configs: '[]'
sp_issuer_user_counts_report_configs: '[]'
sp_proofing_events_by_uuid_report_configs: '[]'
sp_verification_report_configs: '[]'
state_tracking_enabled: true
team_ada_email: ''
team_all_login_emails: '[]'
Expand Down
9 changes: 9 additions & 0 deletions config/initializers/job_configurations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@
cron: cron_every_monday_5am,
args: -> { [Time.zone.yesterday.end_of_day, :both] },
},

# Send previous week's verification reports to partners
# (Note: This is currently only for testing)
sp_weekly_verification_report: {
class: 'Reports::SpVerificationReport',
cron: cron_every_monday_5am,
args: -> { [Time.zone.yesterday.end_of_day, :internal] },
},

# Send Identity Verification report to S3
identity_verification_report: {
class: 'Reports::IdentityVerificationReport',
Expand Down
1 change: 1 addition & 0 deletions lib/identity_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ def self.store
config.add(:sp_idv_weekly_dropoff_report_configs, type: :json)
config.add(:sp_issuer_user_counts_report_configs, type: :json)
config.add(:sp_proofing_events_by_uuid_report_configs, type: :json)
config.add(:sp_verification_report_configs, type: :json)
config.add(:state_tracking_enabled, type: :boolean)
config.add(:team_ada_email, type: :string)
config.add(:team_all_login_emails, type: :json)
Expand Down
13 changes: 7 additions & 6 deletions lib/reporting/irs_verification_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
end

module Reporting
class IrsVerificationReport
class SpVerificationReport
include Reporting::CloudwatchQueryQuoting

attr_reader :issuers, :time_range
attr_reader :issuers, :time_range, :agency_abbreviation

module Events
VERIFICATION_DEMAND = 'IdV: doc auth welcome submitted'
Expand All @@ -29,14 +29,15 @@ def self.all_events
end
end

def initialize(time_range:, issuers:, verbose: false, progress: false, slice: 6.hours,
threads: 1)
def initialize(time_range:, issuers:, agency_abbreviation:, verbose: false, progress: false,
slice: 1.day, threads: 5)
@issuers = issuers
@time_range = time_range || previous_week_range
@verbose = verbose
@progress = progress
@slice = slice
@threads = threads
@agency_abbreviation = agency_abbreviation
end

def verbose?
Expand Down Expand Up @@ -221,7 +222,7 @@ def to_percent(numerator, denominator)

if __FILE__ == $PROGRAM_NAME
options = Reporting::CommandLineOptions.new.parse!(ARGV)
Reporting::IrsVerificationReport.new(**options).to_csvs.each do |csv|
Reporting::SPVerificationReport.new(**options).to_csvs.each do |csv|
puts csv
end
end
end
Loading