mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 06:13:38 +00:00
Resolve the issue with free bitwarden family redirect (#13672)
This commit is contained in:
@@ -7,7 +7,6 @@ import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
|||||||
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
||||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
|
||||||
|
|
||||||
interface EnterpriseOrgStatus {
|
interface EnterpriseOrgStatus {
|
||||||
isFreeFamilyPolicyEnabled: boolean;
|
isFreeFamilyPolicyEnabled: boolean;
|
||||||
@@ -27,19 +26,8 @@ export class FreeFamiliesPolicyService {
|
|||||||
private policyService: PolicyService,
|
private policyService: PolicyService,
|
||||||
private organizationService: OrganizationService,
|
private organizationService: OrganizationService,
|
||||||
private accountService: AccountService,
|
private accountService: AccountService,
|
||||||
private configService: ConfigService,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
canManageSponsorships$ = this.accountService.activeAccount$.pipe(
|
|
||||||
switchMap((account) => {
|
|
||||||
if (account?.id) {
|
|
||||||
return this.organizationService.canManageSponsorships$(account?.id);
|
|
||||||
} else {
|
|
||||||
return of();
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
organizations$ = this.accountService.activeAccount$.pipe(
|
organizations$ = this.accountService.activeAccount$.pipe(
|
||||||
switchMap((account) => {
|
switchMap((account) => {
|
||||||
if (account?.id) {
|
if (account?.id) {
|
||||||
@@ -57,22 +45,21 @@ export class FreeFamiliesPolicyService {
|
|||||||
private getFreeFamiliesVisibility$(): Observable<boolean> {
|
private getFreeFamiliesVisibility$(): Observable<boolean> {
|
||||||
return combineLatest([
|
return combineLatest([
|
||||||
this.checkEnterpriseOrganizationsAndFetchPolicy(),
|
this.checkEnterpriseOrganizationsAndFetchPolicy(),
|
||||||
this.canManageSponsorships$,
|
this.organizations$,
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map(([orgStatus, canManageSponsorships]) =>
|
map(([orgStatus, organizations]) => this.shouldShowFreeFamilyLink(orgStatus, organizations)),
|
||||||
this.shouldShowFreeFamilyLink(orgStatus, canManageSponsorships),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private shouldShowFreeFamilyLink(
|
private shouldShowFreeFamilyLink(
|
||||||
orgStatus: EnterpriseOrgStatus | null,
|
orgStatus: EnterpriseOrgStatus | null,
|
||||||
canManageSponsorships: boolean,
|
organizations: Organization[],
|
||||||
): boolean {
|
): boolean {
|
||||||
if (!orgStatus) {
|
if (!orgStatus) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const { belongToOneEnterpriseOrgs, isFreeFamilyPolicyEnabled } = orgStatus;
|
const { belongToOneEnterpriseOrgs, isFreeFamilyPolicyEnabled } = orgStatus;
|
||||||
|
const canManageSponsorships = organizations.filter((org) => org.canManageSponsorships);
|
||||||
return canManageSponsorships && !(belongToOneEnterpriseOrgs && isFreeFamilyPolicyEnabled);
|
return canManageSponsorships && !(belongToOneEnterpriseOrgs && isFreeFamilyPolicyEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user