bitwarden-estensione-browser/apps/web/src/app/admin-console/organizations/reporting/reports-home.component.ts

69 lines
2.1 KiB
TypeScript

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) => this.isReportsHomepageRouteUrl((event as NavigationEnd).urlAfterRedirects)),
startWith(this.isReportsHomepageRouteUrl(this.router.url)),
);
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,
},
];
}
private isReportsHomepageRouteUrl(url: string): boolean {
return url.endsWith("/reports");
}
}