diff --git a/app/models/profile.rb b/app/models/profile.rb index be986e03cf4..2052eb33eaf 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true class Profile < ApplicationRecord + # IDV levels equivalent to facial match FACIAL_MATCH_IDV_LEVELS = %w[unsupervised_with_selfie in_person].to_set.freeze + # Facial match through IAL2 opt-in flow + FACIAL_MATCH_OPT_IN = %w[unsupervised_with_selfie].to_set.freeze belongs_to :user # rubocop:disable Rails/InverseOf @@ -52,6 +55,14 @@ def self.verified where.not(verified_at: nil) end + def self.facial_match + where(idv_level: FACIAL_MATCH_IDV_LEVELS) + end + + def self.facial_match_opt_in + where(idv_level: FACIAL_MATCH_OPT_IN) + end + def self.fraud_rejection where.not(fraud_rejection_at: nil) end diff --git a/app/services/reporting/agency_and_sp_report.rb b/app/services/reporting/agency_and_sp_report.rb index 2ab63c8320d..d58744e3a31 100644 --- a/app/services/reporting/agency_and_sp_report.rb +++ b/app/services/reporting/agency_and_sp_report.rb @@ -48,12 +48,12 @@ def agency_and_sp_emailable_report end def active_agencies - @active_agencies ||= Agreements::PartnerAccountStatus.find_by(name: 'active'). - partner_accounts. - includes(:agency). - where('became_partner <= ?', report_date). - map(&:agency). - uniq + @active_agencies ||= Agency.joins(:partner_accounts). + where(partner_accounts: { + partner_account_status: Agreements::PartnerAccountStatus.find_by(name: 'active'), + became_partner: ..report_date, + }). + distinct end def service_providers @@ -67,11 +67,12 @@ def service_providers end def facial_match_issuers - @facial_match_issuers ||= Profile.where(active: true).where( - 'verified_at <= ?', - report_date.end_of_day, - ).where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS). - pluck(:initiating_service_provider_issuer).uniq + @facial_match_issuers ||= Reports::BaseReport.transaction_with_timeout do + Profile.active.facial_match_opt_in. + where('verified_at <= ?', report_date.end_of_day). + distinct. + pluck(:initiating_service_provider_issuer) + end end end end diff --git a/app/services/reporting/total_user_count_report.rb b/app/services/reporting/total_user_count_report.rb index 62ac028906d..b521f7a8f97 100644 --- a/app/services/reporting/total_user_count_report.rb +++ b/app/services/reporting/total_user_count_report.rb @@ -83,33 +83,30 @@ def total_user_count def verified_legacy_idv_user_count Reports::BaseReport.transaction_with_timeout do - Profile.where(active: true).where( - 'verified_at <= ?', - end_date, + Profile.active.where( + 'verified_at <= ?', end_date ).count - verified_facial_match_user_count end end def verified_facial_match_user_count @verified_facial_match_user_count ||= Reports::BaseReport.transaction_with_timeout do - Profile.where(active: true).where( - 'verified_at <= ?', - end_date, - ).where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS).count + Profile.active.facial_match_opt_in.where( + 'verified_at <= ?', end_date + ).count end end def new_verified_legacy_idv_user_count Reports::BaseReport.transaction_with_timeout do - Profile.where(active: true).where(verified_at: current_month).count - + Profile.active.where(verified_at: current_month).count - new_verified_facial_match_user_count end end def new_verified_facial_match_user_count @new_verified_facial_match_user_count ||= Reports::BaseReport.transaction_with_timeout do - Profile.where(active: true).where(verified_at: current_month). - where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS).count + Profile.active.facial_match_opt_in.where(verified_at: current_month).count end end @@ -121,15 +118,16 @@ def annual_total_user_count def annual_verified_legacy_idv_user_count Reports::BaseReport.transaction_with_timeout do - Profile.where(active: true).where(verified_at: annual_start_date..annual_end_date).count - + Profile.active.where(verified_at: annual_start_date..annual_end_date).count - annual_verified_facial_match_user_count end end def annual_verified_facial_match_user_count @annual_verified_facial_match_user_count ||= Reports::BaseReport.transaction_with_timeout do - Profile.where(active: true).where(verified_at: annual_start_date..annual_end_date). - where(idv_level: Profile::FACIAL_MATCH_IDV_LEVELS).count + Profile.active.facial_match_opt_in.where( + verified_at: annual_start_date..annual_end_date, + ).count end end diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 00000000000..cb53ebe5f00 --- /dev/null +++ b/bin/rspec @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") diff --git a/spec/factories/profiles.rb b/spec/factories/profiles.rb index 66eead40d4c..c1483a146d4 100644 --- a/spec/factories/profiles.rb +++ b/spec/factories/profiles.rb @@ -80,7 +80,7 @@ end trait :facial_match_proof do - idv_level { :in_person } + idv_level { :unsupervised_with_selfie } initiating_service_provider_issuer { 'urn:gov:gsa:openidconnect:inactive:sp:test' } end