From 84dfa3ab057a9d2357ebebb69b15e25d0b868c86 Mon Sep 17 00:00:00 2001 From: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Date: Tue, 10 Dec 2024 21:52:54 +0100 Subject: [PATCH] prevent access to freefamilies page (#12335) --- .../settings/sponsored-families.component.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apps/web/src/app/billing/settings/sponsored-families.component.ts b/apps/web/src/app/billing/settings/sponsored-families.component.ts index a8473ee89b..5e26e80a30 100644 --- a/apps/web/src/app/billing/settings/sponsored-families.component.ts +++ b/apps/web/src/app/billing/settings/sponsored-families.component.ts @@ -10,6 +10,7 @@ import { AsyncValidatorFn, ValidationErrors, } from "@angular/forms"; +import { Router } from "@angular/router"; import { combineLatest, firstValueFrom, map, Observable, Subject, takeUntil } from "rxjs"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; @@ -26,6 +27,8 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; import { ToastService } from "@bitwarden/components"; +import { FreeFamiliesPolicyService } from "../services/free-families-policy.service"; + interface RequestSponsorshipForm { selectedSponsorshipOrgId: FormControl; sponsorshipEmail: FormControl; @@ -62,6 +65,8 @@ export class SponsoredFamiliesComponent implements OnInit, OnDestroy { private toastService: ToastService, private configService: ConfigService, private policyService: PolicyService, + private freeFamiliesPolicyService: FreeFamiliesPolicyService, + private router: Router, ) { this.sponsorshipForm = this.formBuilder.group({ selectedSponsorshipOrgId: new FormControl("", { @@ -86,6 +91,8 @@ export class SponsoredFamiliesComponent implements OnInit, OnDestroy { ); if (this.isFreeFamilyFlagEnabled) { + await this.preventAccessToFreeFamiliesPage(); + this.availableSponsorshipOrgs$ = combineLatest([ this.organizationService.organizations$, this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy), @@ -142,6 +149,17 @@ export class SponsoredFamiliesComponent implements OnInit, OnDestroy { this._destroy.complete(); } + private async preventAccessToFreeFamiliesPage() { + const showFreeFamiliesPage = await firstValueFrom( + this.freeFamiliesPolicyService.showFreeFamilies$, + ); + + if (!showFreeFamiliesPage) { + await this.router.navigate(["/"]); + return; + } + } + submit = async () => { this.formPromise = this.apiService.postCreateSponsorship( this.sponsorshipForm.value.selectedSponsorshipOrgId,