From 1005aadf775eabf4995c43a463f5bdb8c9fc37ec Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 3 Dec 2024 12:10:59 -0500 Subject: [PATCH] logic for generating the report summary --- .../services/risk-insights-report.service.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/bitwarden_license/bit-common/src/tools/reports/risk-insights/services/risk-insights-report.service.ts b/bitwarden_license/bit-common/src/tools/reports/risk-insights/services/risk-insights-report.service.ts index 9420ed63268..662e32468cb 100644 --- a/bitwarden_license/bit-common/src/tools/reports/risk-insights/services/risk-insights-report.service.ts +++ b/bitwarden_license/bit-common/src/tools/reports/risk-insights/services/risk-insights-report.service.ts @@ -10,6 +10,13 @@ import { BadgeVariant } from "@bitwarden/components"; import { MemberCipherDetailsApiService } from "./member-cipher-details-api.service"; +export type ApplicationHealthReportSummary = { + totalMemberCount: number; + totalAtRiskMemberCount: number; + totalPasswordCount: number; + totalAtRiskPasswordCount: number; +}; + export type ApplicationHealthReportDetail = { applicationName: string; passwordCount: number; @@ -111,6 +118,37 @@ export class RiskInsightsReportService { return this.getApplicationHealthReport(cipherHealthUriReport); } + /** + * Gets the summary from the application health report. Returns total members and passwords as well + * as the total at risk members and at risk passwords + * @param reports The previously calculated application health report data + * @returns A summary object containing report totals + */ + generateApplicationsSummary( + reports: ApplicationHealthReportDetail[], + ): ApplicationHealthReportSummary { + const totalMembers = reports.flatMap((x) => x.memberDetails); + const uniqueMembers = this.getUniqueMembers(totalMembers); + + const atRiskMembers = reports.flatMap((x) => x.atRiskMemberDetails); + const uniqueAtRiskMembers = this.getUniqueMembers(atRiskMembers); + + const totalPasswordCount = reports.reduce( + (total, current) => total + current.atRiskPasswordCount, + 0, + ); + const atRiskPasswordCount = reports + .filter((x) => x.atRiskPasswordCount > 0) + .reduce((total, current) => total + current.atRiskPasswordCount, 0); + + return { + totalMemberCount: uniqueMembers.length, + totalAtRiskMemberCount: uniqueAtRiskMembers.length, + totalPasswordCount: totalPasswordCount, + totalAtRiskPasswordCount: atRiskPasswordCount, + }; + } + /** * Associates the members with the ciphers they have access to. Calculates the password health. * Finds the trimmed uris.