-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
reports-home.component.ts
64 lines (56 loc) · 1.9 KB
/
reports-home.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, NavigationEnd, Router } from "@angular/router";
import { filter, map, Observable, startWith, concatMap } from "rxjs";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { ReportVariant, reports, ReportType, ReportEntry } from "../../../tools/reports";
@Component({
selector: "app-org-reports-home",
templateUrl: "reports-home.component.html",
})
export class ReportsHomeComponent implements OnInit {
reports$: Observable<ReportEntry[]>;
homepage$: Observable<boolean>;
constructor(
private route: ActivatedRoute,
private organizationService: OrganizationService,
private router: Router,
) {}
ngOnInit() {
this.homepage$ = this.router.events.pipe(
filter((event) => event instanceof NavigationEnd),
map((event) => (event as NavigationEnd).urlAfterRedirects.endsWith("/reports")),
startWith(true),
);
this.reports$ = this.route.params.pipe(
concatMap((params) => this.organizationService.get$(params.organizationId)),
map((org) => this.buildReports(org.isFreeOrg)),
);
}
private buildReports(upgradeRequired: boolean): ReportEntry[] {
const reportRequiresUpgrade = upgradeRequired
? ReportVariant.RequiresUpgrade
: ReportVariant.Enabled;
return [
{
...reports[ReportType.ExposedPasswords],
variant: reportRequiresUpgrade,
},
{
...reports[ReportType.ReusedPasswords],
variant: reportRequiresUpgrade,
},
{
...reports[ReportType.WeakPasswords],
variant: reportRequiresUpgrade,
},
{
...reports[ReportType.UnsecuredWebsites],
variant: reportRequiresUpgrade,
},
{
...reports[ReportType.Inactive2fa],
variant: reportRequiresUpgrade,
},
];
}
}