From a41c7b79b4e0b50e0c0916542aa3dcc7fdd42dc3 Mon Sep 17 00:00:00 2001 From: Vijay Oommen Date: Thu, 13 Nov 2025 13:33:56 -0600 Subject: [PATCH] [PM-20132] Total Member Count (#17330) * PM-20132 total member count * Apply suggestions from code review Co-authored-by: Leslie Tilton <23057410+Banrion@users.noreply.github.com> * PM-20132 updated PR comments * PM-20132 update as per PR comments * PM-20132 removed unwanted code * PM-20132 fixed PR comment from Claude * PM-20132 reduced ambiguity in code * PM-20132 removed unwanted observables * PM-20132 removed default value as it is not needed anymore * PM-20132 fixed failed test --------- Co-authored-by: Leslie Tilton <23057410+Banrion@users.noreply.github.com> --- .../risk-insights-orchestrator.service.ts | 25 ++++++++++++++++--- .../domain/risk-insights-report.service.ts | 4 +-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/domain/risk-insights-orchestrator.service.ts b/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/domain/risk-insights-orchestrator.service.ts index 59affad10d..38e1237318 100644 --- a/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/domain/risk-insights-orchestrator.service.ts +++ b/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/domain/risk-insights-orchestrator.service.ts @@ -42,6 +42,7 @@ import { createNewSummaryData, flattenMemberDetails, getTrimmedCipherUris, + getUniqueMembers, } from "../../helpers"; import { ApplicationHealthReportDetailEnriched, @@ -234,6 +235,7 @@ export class RiskInsightsOrchestratorService { const updatedSummaryData = this.reportService.getApplicationsSummary( report!.reportData, updatedApplicationData, + report!.summaryData.totalMemberCount, ); // Used for creating metrics with updated application data @@ -366,6 +368,7 @@ export class RiskInsightsOrchestratorService { const updatedSummaryData = this.reportService.getApplicationsSummary( report!.reportData, updatedApplicationData, + report!.summaryData.totalMemberCount, ); // Used for creating metrics with updated application data @@ -502,6 +505,7 @@ export class RiskInsightsOrchestratorService { const updatedSummaryData = this.reportService.getApplicationsSummary( report!.reportData, updatedApplicationData, + report!.summaryData.totalMemberCount, ); // Used for creating metrics with updated application data const manualEnrichedApplications = report!.reportData.map( @@ -656,19 +660,30 @@ export class RiskInsightsOrchestratorService { switchMap(([ciphers, memberCiphers]) => { this.logService.debug("[RiskInsightsOrchestratorService] Analyzing password health"); this._reportProgressSubject.next(ReportProgress.AnalyzingPasswords); - return this._getCipherHealth(ciphers ?? [], memberCiphers); + return forkJoin({ + memberDetails: of(memberCiphers), + cipherHealthReports: this._getCipherHealth(ciphers ?? [], memberCiphers), + }).pipe( + map(({ memberDetails, cipherHealthReports }) => { + const uniqueMembers = getUniqueMembers(memberDetails); + const totalMemberCount = uniqueMembers.length; + + return { cipherHealthReports, totalMemberCount }; + }), + ); }), - map((cipherHealthReports) => { + map(({ cipherHealthReports, totalMemberCount }) => { this.logService.debug("[RiskInsightsOrchestratorService] Calculating risk scores"); this._reportProgressSubject.next(ReportProgress.CalculatingRisks); - return this.reportService.generateApplicationsReport(cipherHealthReports); + const report = this.reportService.generateApplicationsReport(cipherHealthReports); + return { report, totalMemberCount }; }), tap(() => { this.logService.debug("[RiskInsightsOrchestratorService] Generating report data"); this._reportProgressSubject.next(ReportProgress.GeneratingReport); }), withLatestFrom(this.rawReportData$), - map(([report, previousReport]) => { + map(([{ report, totalMemberCount }, previousReport]) => { // Update the application data const updatedApplicationData = this.reportService.getOrganizationApplications( report, @@ -688,6 +703,7 @@ export class RiskInsightsOrchestratorService { const updatedSummary = this.reportService.getApplicationsSummary( report, updatedApplicationData, + totalMemberCount, ); // For now, merge the report with the critical marking flag to make the enriched type // We don't care about the individual ciphers in this instance @@ -964,6 +980,7 @@ export class RiskInsightsOrchestratorService { const summary = this.reportService.getApplicationsSummary( criticalApplications, enrichedReports.applicationData, + enrichedReports.summaryData.totalMemberCount, ); return { ...enrichedReports, diff --git a/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/domain/risk-insights-report.service.ts b/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/domain/risk-insights-report.service.ts index 94c9c85f95..37b788a8e3 100644 --- a/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/domain/risk-insights-report.service.ts +++ b/bitwarden_license/bit-common/src/dirt/reports/risk-insights/services/domain/risk-insights-report.service.ts @@ -83,8 +83,8 @@ export class RiskInsightsReportService { getApplicationsSummary( reports: ApplicationHealthReportDetail[], applicationData: OrganizationReportApplication[], + totalMemberCount: number, ): OrganizationReportSummary { - const totalUniqueMembers = getUniqueMembers(reports.flatMap((x) => x.memberDetails)); const atRiskUniqueMembers = getUniqueMembers(reports.flatMap((x) => x.atRiskMemberDetails)); const criticalReports = this.filterApplicationsByCritical(reports, applicationData); @@ -94,7 +94,7 @@ export class RiskInsightsReportService { ); return { - totalMemberCount: totalUniqueMembers.length, + totalMemberCount: totalMemberCount, totalAtRiskMemberCount: atRiskUniqueMembers.length, totalApplicationCount: reports.length, totalAtRiskApplicationCount: reports.filter((app) => app.atRiskPasswordCount > 0).length,