From 582beaf70662a7708e3545d50b43876b02a884bc Mon Sep 17 00:00:00 2001 From: albertboyd5 Date: Mon, 27 Jan 2025 15:25:40 -0600 Subject: [PATCH] [PM-13404] Weak Passwords Report - Sort by password weakness (#12359) * [PM-13404] Weak Passwords Report - Sort by password weakness * [PM-13404] Weak Passwords Report lint error fix * Test signed commit --- .../weak-passwords-report.component.html | 8 ++++++- .../pages/weak-passwords-report.component.ts | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/apps/web/src/app/tools/reports/pages/weak-passwords-report.component.html b/apps/web/src/app/tools/reports/pages/weak-passwords-report.component.html index 9c5b587e60a..76d4398cc0f 100644 --- a/apps/web/src/app/tools/reports/pages/weak-passwords-report.component.html +++ b/apps/web/src/app/tools/reports/pages/weak-passwords-report.component.html @@ -39,7 +39,13 @@ {{ "owner" | i18n }} - + {{ "weakness" | i18n }} diff --git a/apps/web/src/app/tools/reports/pages/weak-passwords-report.component.ts b/apps/web/src/app/tools/reports/pages/weak-passwords-report.component.ts index c374ecd0e4a..8b781b77378 100644 --- a/apps/web/src/app/tools/reports/pages/weak-passwords-report.component.ts +++ b/apps/web/src/app/tools/reports/pages/weak-passwords-report.component.ts @@ -59,6 +59,7 @@ export class WeakPasswordsReportComponent extends CipherReportComponent implemen this.weakPasswordCiphers = []; this.filterStatus = [0]; this.findWeakPasswords(allCiphers); + this.weakPasswordCiphers = this.sortCiphers(this.weakPasswordCiphers, "score", false); } protected findWeakPasswords(ciphers: CipherView[]): void { @@ -112,6 +113,29 @@ export class WeakPasswordsReportComponent extends CipherReportComponent implemen this.filterCiphersByOrg(this.weakPasswordCiphers); } + onSortChange(field: string, event: Event) { + const target = event.target as HTMLInputElement; + const ascending = target.checked; + this.weakPasswordCiphers = this.sortCiphers(this.weakPasswordCiphers, field, ascending); + } + + protected sortCiphers( + ciphers: ReportResult[], + field: string, + ascending: boolean, + ): ReportResult[] { + return ciphers.sort((a, b) => { + const aValue = a[field as keyof ReportResult]; + const bValue = b[field as keyof ReportResult]; + + if (aValue === bValue) { + return 0; + } + const comparison = aValue > bValue ? 1 : -1; + return ascending ? comparison : -comparison; + }); + } + protected canManageCipher(c: CipherView): boolean { // this will only ever be false from the org view; return true;