Skip to content

Commit

Permalink
Remove the feature flag (#13102)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyprain-okeke authored Feb 5, 2025
1 parent 25853b2 commit 586cbcc
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 76 deletions.
13 changes: 2 additions & 11 deletions apps/web/src/app/billing/services/free-families-policy.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Injectable } from "@angular/core";
import { combineLatest, filter, from, map, Observable, of, switchMap } from "rxjs";
import { combineLatest, filter, map, Observable, of, switchMap } from "rxjs";

import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";

interface EnterpriseOrgStatus {
Expand Down Expand Up @@ -52,11 +51,7 @@ export class FreeFamiliesPolicyService {
);

get showFreeFamilies$(): Observable<boolean> {
return this.isFreeFamilyFlagEnabled$.pipe(
switchMap((isFreeFamilyFlagEnabled) =>
isFreeFamilyFlagEnabled ? this.getFreeFamiliesVisibility$() : this.canManageSponsorships$,
),
);
return this.getFreeFamiliesVisibility$();
}

private getFreeFamiliesVisibility$(): Observable<boolean> {
Expand Down Expand Up @@ -143,8 +138,4 @@ export class FreeFamiliesPolicyService {
const enterpriseOrganizations = organizations.filter((org) => org.canManageSponsorships);
return enterpriseOrganizations.length === 1 ? enterpriseOrganizations[0].id : null;
}

private get isFreeFamilyFlagEnabled$(): Observable<boolean> {
return from(this.configService.getFeatureFlag(FeatureFlag.DisableFreeFamiliesSponsorship));
}
}
52 changes: 19 additions & 33 deletions apps/web/src/app/billing/settings/sponsored-families.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import { Organization } from "@bitwarden/common/admin-console/models/domain/orga
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { PlanSponsorshipType } from "@bitwarden/common/billing/enums";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
Expand All @@ -41,7 +39,6 @@ interface RequestSponsorshipForm {
})
export class SponsoredFamiliesComponent implements OnInit, OnDestroy {
loading = false;
isFreeFamilyFlagEnabled: boolean;

availableSponsorshipOrgs$: Observable<Organization[]>;
activeSponsorshipOrgs$: Observable<Organization[]>;
Expand All @@ -64,7 +61,6 @@ export class SponsoredFamiliesComponent implements OnInit, OnDestroy {
private formBuilder: FormBuilder,
private accountService: AccountService,
private toastService: ToastService,
private configService: ConfigService,
private policyService: PolicyService,
private freeFamiliesPolicyService: FreeFamiliesPolicyService,
private router: Router,
Expand All @@ -87,37 +83,27 @@ export class SponsoredFamiliesComponent implements OnInit, OnDestroy {
}

async ngOnInit() {
this.isFreeFamilyFlagEnabled = await this.configService.getFeatureFlag(
FeatureFlag.DisableFreeFamiliesSponsorship,
);

const userId = await firstValueFrom(getUserId(this.accountService.activeAccount$));

if (this.isFreeFamilyFlagEnabled) {
await this.preventAccessToFreeFamiliesPage();

this.availableSponsorshipOrgs$ = combineLatest([
this.organizationService.organizations$(userId),
this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId),
]).pipe(
map(([organizations, policies]) =>
organizations
.filter((org) => org.familySponsorshipAvailable)
.map((org) => ({
organization: org,
isPolicyEnabled: policies.some(
(policy) => policy.organizationId === org.id && policy.enabled,
),
}))
.filter(({ isPolicyEnabled }) => !isPolicyEnabled)
.map(({ organization }) => organization),
),
);
} else {
this.availableSponsorshipOrgs$ = this.organizationService
.organizations$(userId)
.pipe(map((orgs) => orgs.filter((o) => o.familySponsorshipAvailable)));
}
await this.preventAccessToFreeFamiliesPage();

this.availableSponsorshipOrgs$ = combineLatest([
this.organizationService.organizations$(userId),
this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId),
]).pipe(
map(([organizations, policies]) =>
organizations
.filter((org) => org.familySponsorshipAvailable)
.map((org) => ({
organization: org,
isPolicyEnabled: policies.some(
(policy) => policy.organizationId === org.id && policy.enabled,
),
}))
.filter(({ isPolicyEnabled }) => !isPolicyEnabled)
.map(({ organization }) => organization),
),
);

this.availableSponsorshipOrgs$.pipe(takeUntil(this._destroy)).subscribe((orgs) => {
if (orgs.length === 1) {
Expand Down
33 changes: 13 additions & 20 deletions apps/web/src/app/billing/settings/sponsoring-org-row.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
Expand All @@ -29,7 +28,6 @@ export class SponsoringOrgRowComponent implements OnInit {
statusMessage = "loading";
statusClass: "tw-text-success" | "tw-text-danger" = "tw-text-success";
isFreeFamilyPolicyEnabled$: Observable<boolean>;
isFreeFamilyFlagEnabled: boolean;
private locale = "";

constructor(
Expand All @@ -52,25 +50,20 @@ export class SponsoringOrgRowComponent implements OnInit {
this.sponsoringOrg.familySponsorshipValidUntil,
this.sponsoringOrg.familySponsorshipLastSyncDate,
);
this.isFreeFamilyFlagEnabled = await this.configService.getFeatureFlag(
FeatureFlag.DisableFreeFamiliesSponsorship,
);

if (this.isFreeFamilyFlagEnabled) {
this.isFreeFamilyPolicyEnabled$ = this.accountService.activeAccount$.pipe(
getUserId,
switchMap((userId) =>
this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId),
),
map(
(policies) =>
Array.isArray(policies) &&
policies.some(
(policy) => policy.organizationId === this.sponsoringOrg.id && policy.enabled,
),
),
);
}
this.isFreeFamilyPolicyEnabled$ = this.accountService.activeAccount$.pipe(
getUserId,
switchMap((userId) =>
this.policyService.getAll$(PolicyType.FreeFamiliesSponsorshipPolicy, userId),
),
map(
(policies) =>
Array.isArray(policies) &&
policies.some(
(policy) => policy.organizationId === this.sponsoringOrg.id && policy.enabled,
),
),
);
}

async revokeSponsorship() {
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/app/layouts/user-layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { WebLayoutModule } from "./web-layout.module";
})
export class UserLayoutComponent implements OnInit {
protected readonly logo = PasswordManagerLogo;
isFreeFamilyFlagEnabled: boolean;
protected hasFamilySponsorshipAvailable$: Observable<boolean>;
protected showSponsoredFamilies$: Observable<boolean>;
protected showSubscription$: Observable<boolean>;
Expand Down
11 changes: 2 additions & 9 deletions bitwarden_license/bit-web/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@ export class AppComponent extends BaseAppComponent implements OnInit {
this.policyListService.addPolicies([
new MaximumVaultTimeoutPolicy(),
new DisablePersonalVaultExportPolicy(),
new FreeFamiliesSponsorshipPolicy(),
new ActivateAutofillPolicy(),
]);

this.configService
.getFeatureFlag(FeatureFlag.DisableFreeFamiliesSponsorship)
.then((isFreeFamilyEnabled) => {
if (isFreeFamilyEnabled) {
this.policyListService.addPolicies([new FreeFamiliesSponsorshipPolicy()]);
}
this.policyListService.addPolicies([new ActivateAutofillPolicy()]);
});

this.configService.getFeatureFlag(FeatureFlag.IdpAutoSubmitLogin).then((enabled) => {
if (
enabled &&
Expand Down
2 changes: 0 additions & 2 deletions libs/common/src/enums/feature-flag.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export enum FeatureFlag {
SecurityTasks = "security-tasks",
NewDeviceVerificationTemporaryDismiss = "new-device-temporary-dismiss",
NewDeviceVerificationPermanentDismiss = "new-device-permanent-dismiss",
DisableFreeFamiliesSponsorship = "PM-12274-disable-free-families-sponsorship",
MacOsNativeCredentialSync = "macos-native-credential-sync",
PM9111ExtensionPersistAddEditForm = "pm-9111-extension-persist-add-edit-form",
PrivateKeyRegeneration = "pm-12241-private-key-regeneration",
Expand Down Expand Up @@ -107,7 +106,6 @@ export const DefaultFeatureFlagValue = {
[FeatureFlag.SecurityTasks]: FALSE,
[FeatureFlag.NewDeviceVerificationTemporaryDismiss]: FALSE,
[FeatureFlag.NewDeviceVerificationPermanentDismiss]: FALSE,
[FeatureFlag.DisableFreeFamiliesSponsorship]: FALSE,
[FeatureFlag.MacOsNativeCredentialSync]: FALSE,
[FeatureFlag.PM9111ExtensionPersistAddEditForm]: FALSE,
[FeatureFlag.PrivateKeyRegeneration]: FALSE,
Expand Down

0 comments on commit 586cbcc

Please sign in to comment.