Skip to content
Merged
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
42 changes: 35 additions & 7 deletions app/jobs/reports/sp_issuer_user_counts_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class SpIssuerUserCountsReport < BaseReport

def perform(_date)
configs = IdentityConfig.store.sp_issuer_user_counts_report_configs
message = "Report: #{REPORT_NAME}"
subject = 'Service provider user count report'

configs.each do |report_hash|
emails = report_hash['emails']
Expand All @@ -13,17 +15,43 @@ def perform(_date)
Db::Identity::SpUserCounts.with_issuer(issuer)
end

reports = [
Reporting::EmailableReport.new(
title: 'Overview',
table: overview_table(issuer),
),
Reporting::EmailableReport.new(
title: 'User counts',
table: user_table(user_counts),
),
]

emails.each do |email|
ReportMailer.sp_issuer_user_counts_report(
name: REPORT_NAME,
email: email,
issuer: issuer,
total: user_counts['total'],
ial1_total: user_counts['ial1_total'],
ial2_total: user_counts['ial2_total'],
ReportMailer.tables_report(
email:,
subject:,
message:,
reports:,
attachment_format: :csv,
).deliver_now
end
end
end

def overview_table(issuer)
[
['Report Generated', Time.zone.today.to_s],
['Issuer', issuer],
]
end

def user_table(user_counts)
[
['Metric', 'Number of users'],
['Total Users', user_counts['total']],
['IAL1 Users', user_counts['ial1_total']],
['Identity Verified Users', user_counts['ial2_total']],
]
end
end
end
9 changes: 0 additions & 9 deletions app/mailers/report_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ def deleted_user_accounts_report(email:, name:, issuers:, data:)
mail(to: email, subject: t('report_mailer.deleted_accounts_report.subject'))
end

def sp_issuer_user_counts_report(email:, issuer:, total:, ial1_total:, ial2_total:, name:)
@name = name
@issuer = issuer
@total = total
@ial1_total = ial1_total
@ial2_total = ial2_total
mail(to: email, subject: t('report_mailer.sp_issuer_user_counts_report.subject'))
end

def system_demand_report(email:, data:, name:)
@name = name
attachments['system_demand.csv'] = data
Expand Down
5 changes: 0 additions & 5 deletions app/views/report_mailer/sp_issuer_user_counts_report.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions config/locales/report_mailer/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ en:
issuers: Issuers
name: Name
subject: Deleted accounts report
sp_issuer_user_counts_report:
ial1_total: IAL1 users
ial2_total: IAL2 users
issuer: Issuer
name: Name
subject: Service provider user count report
total: Total users
system_demand_report:
name: Name
subject: System demand report
7 changes: 0 additions & 7 deletions config/locales/report_mailer/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ es:
issuers: Emisores
name: Nombre
subject: Informe de cuentas eliminadas
sp_issuer_user_counts_report:
ial1_total: IAL1 usuarias
ial2_total: IAL2 usuarias
issuer: Identificación del emisor
name: Nombre
subject: Informe de recuento de usuarios del proveedor de servicios
total: Total de usuarias
system_demand_report:
name: Nombre
subject: Informe de demanda del sistema
7 changes: 0 additions & 7 deletions config/locales/report_mailer/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ fr:
issuers: Émetteurs
name: Nom
subject: Rapport sur les comptes supprimés
sp_issuer_user_counts_report:
ial1_total: IAL1 utilisatrices
ial2_total: IAL2 utilisatrices
issuer: Identifiant de l’émetteur
name: Nom
subject: Rapport sur le nombre d’utilisateurs
total: Nombre total d’utilisateurs
system_demand_report:
name: Nom
subject: Rapport de demande du système
2 changes: 1 addition & 1 deletion lib/reporting/authentication_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def cloudwatch_client
def overview_table
[
['Report Timeframe', "#{time_range.begin} to #{time_range.end}"],
['Report Generated', Date.today.to_s], # rubocop:disable Rails/Date
['Report Generated', Time.zone.today.to_s],
['Issuer', issuers.join(', ')],
['Total # of IAL1 Users', sp_redirect_initiated_all],
]
Expand Down
2 changes: 1 addition & 1 deletion lib/reporting/identity_verification_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def progress?
def to_csv
CSV.generate do |csv|
csv << ['Report Timeframe', "#{time_range.begin} to #{time_range.end}"]
csv << ['Report Generated', Date.today.to_s] # rubocop:disable Rails/Date
csv << ['Report Generated', Time.zone.today.to_s]
csv << ['Issuer', issuers.join(', ')] if issuers.present?
csv << []
csv << ['Metric', '# of Users']
Expand Down
62 changes: 45 additions & 17 deletions spec/jobs/reports/sp_issuer_user_counts_report_spec.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,58 @@
require 'rails_helper'

RSpec.describe Reports::SpIssuerUserCountsReport do
let(:name) { 'sp-issuer-user-counts-report' }
let(:issuer) { 'urn:gov:gsa:openidconnect:sp:sinatra' }
let(:email) { 'foo@bar.com' }
let(:user) { create(:user) }
let(:uuid) { 'foo' }
let(:last_authenticated_at) { '2020-01-02 12:03:04 UTC' }
let(:date) { Time.zone.today.to_s }
let(:user_counts) do
{
'total' => 56,
'ial1_total' => 40,
'ial2_total' => 16,
}
end

subject { described_class.new }

it 'sends out a report to the email listed with one total user' do
create(
:service_provider_identity,
service_provider: issuer,
user: user,
uuid: uuid,
last_authenticated_at: last_authenticated_at,
)
let(:reports) do
[
Reporting::EmailableReport.new(
title: 'Overview',
table: [
['Report Generated', date],
['Issuer', issuer],
],
),
Reporting::EmailableReport.new(
title: 'User counts',
table: [
['Metric', 'Number of users'],
['Total Users', 56],
['IAL1 Users', 40],
['Identity Verified Users', 16],
],
),
]
end

before do
expect(Db::Identity::SpUserCounts).to receive(:with_issuer).with(issuer).
and_return(user_counts)

allow(IdentityConfig.store).to receive(:sp_issuer_user_counts_report_configs).
and_return([{ 'issuer' => issuer, 'emails' => [email] }])

allow(ReportMailer).to receive(:tables_report).and_call_original
end

allow(IdentityConfig.store).to receive(:sp_issuer_user_counts_report_configs).and_return(
[{ 'issuer' => issuer, 'emails' => [email] }],
it 'emails the csv' do
expect(ReportMailer).to receive(:tables_report).with(
email:,
subject: 'Service provider user count report',
message: "Report: #{Reports::SpIssuerUserCountsReport::REPORT_NAME}",
reports:,
attachment_format: :csv,
)
expect(ReportMailer).to receive(:sp_issuer_user_counts_report).with(
name: name, email: email, ial1_total: 1, ial2_total: 0, issuer: issuer, total: 1,
).and_call_original

subject.perform(Time.zone.today)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/reporting/authentication_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def expected_tables(strings: false)
[
[
['Report Timeframe', "#{time_range.begin} to #{time_range.end}"],
['Report Generated', Date.today.to_s], # rubocop:disable Rails/Date
['Report Generated', Time.zone.today.to_s],
['Issuer', issuer],
['Total # of IAL1 Users', strings ? '2' : 2],
],
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/reporting/identity_verification_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

expected_csv = [
['Report Timeframe', "#{time_range.begin} to #{time_range.end}"],
['Report Generated', Date.today.to_s], # rubocop:disable Rails/Date
['Report Generated', Time.zone.today.to_s],
['Issuer', issuer],
[],
['Metric', '# of Users'],
Expand Down