mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 14:23:32 +00:00
[PM-18717] Fix multiple organization situation for Free Families Policy sponsorship (#16611)
* Resolve multiple org situation * Fix multi org policy mismatch issue
This commit is contained in:
@@ -19,12 +19,6 @@ interface EnterpriseOrgStatus {
|
|||||||
|
|
||||||
@Injectable({ providedIn: "root" })
|
@Injectable({ providedIn: "root" })
|
||||||
export class FreeFamiliesPolicyService {
|
export class FreeFamiliesPolicyService {
|
||||||
protected enterpriseOrgStatus: EnterpriseOrgStatus = {
|
|
||||||
isFreeFamilyPolicyEnabled: false,
|
|
||||||
belongToOneEnterpriseOrgs: false,
|
|
||||||
belongToMultipleEnterpriseOrgs: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private policyService: PolicyService,
|
private policyService: PolicyService,
|
||||||
private organizationService: OrganizationService,
|
private organizationService: OrganizationService,
|
||||||
@@ -104,9 +98,11 @@ export class FreeFamiliesPolicyService {
|
|||||||
if (!orgStatus) {
|
if (!orgStatus) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const { belongToOneEnterpriseOrgs, isFreeFamilyPolicyEnabled } = orgStatus;
|
const { isFreeFamilyPolicyEnabled } = orgStatus;
|
||||||
const hasSponsorshipOrgs = organizations.some((org) => org.canManageSponsorships);
|
const hasSponsorshipOrgs = organizations.some((org) => org.canManageSponsorships);
|
||||||
return hasSponsorshipOrgs && !(belongToOneEnterpriseOrgs && isFreeFamilyPolicyEnabled);
|
|
||||||
|
// Hide if ANY organization has the policy enabled
|
||||||
|
return hasSponsorshipOrgs && !isFreeFamilyPolicyEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEnterpriseOrganizationsAndFetchPolicy(): Observable<EnterpriseOrgStatus> {
|
checkEnterpriseOrganizationsAndFetchPolicy(): Observable<EnterpriseOrgStatus> {
|
||||||
@@ -122,16 +118,12 @@ export class FreeFamiliesPolicyService {
|
|||||||
const { belongToOneEnterpriseOrgs, belongToMultipleEnterpriseOrgs } =
|
const { belongToOneEnterpriseOrgs, belongToMultipleEnterpriseOrgs } =
|
||||||
this.evaluateEnterpriseOrganizations(organizations);
|
this.evaluateEnterpriseOrganizations(organizations);
|
||||||
|
|
||||||
if (!belongToOneEnterpriseOrgs) {
|
// Get all enterprise organization IDs
|
||||||
return of({
|
const enterpriseOrgIds = organizations
|
||||||
isFreeFamilyPolicyEnabled: false,
|
.filter((org) => org.canManageSponsorships)
|
||||||
belongToOneEnterpriseOrgs,
|
.map((org) => org.id);
|
||||||
belongToMultipleEnterpriseOrgs,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const organizationId = this.getOrganizationIdForOneEnterprise(organizations);
|
if (enterpriseOrgIds.length === 0) {
|
||||||
if (!organizationId) {
|
|
||||||
return of({
|
return of({
|
||||||
isFreeFamilyPolicyEnabled: false,
|
isFreeFamilyPolicyEnabled: false,
|
||||||
belongToOneEnterpriseOrgs,
|
belongToOneEnterpriseOrgs,
|
||||||
@@ -145,8 +137,8 @@ export class FreeFamiliesPolicyService {
|
|||||||
this.policyService.policiesByType$(PolicyType.FreeFamiliesSponsorshipPolicy, userId),
|
this.policyService.policiesByType$(PolicyType.FreeFamiliesSponsorshipPolicy, userId),
|
||||||
),
|
),
|
||||||
map((policies) => ({
|
map((policies) => ({
|
||||||
isFreeFamilyPolicyEnabled: policies.some(
|
isFreeFamilyPolicyEnabled: enterpriseOrgIds.every((orgId) =>
|
||||||
(policy) => policy.organizationId === organizationId && policy.enabled,
|
policies.some((policy) => policy.organizationId === orgId && policy.enabled),
|
||||||
),
|
),
|
||||||
belongToOneEnterpriseOrgs,
|
belongToOneEnterpriseOrgs,
|
||||||
belongToMultipleEnterpriseOrgs,
|
belongToMultipleEnterpriseOrgs,
|
||||||
@@ -166,9 +158,4 @@ export class FreeFamiliesPolicyService {
|
|||||||
belongToMultipleEnterpriseOrgs: count > 1,
|
belongToMultipleEnterpriseOrgs: count > 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private getOrganizationIdForOneEnterprise(organizations: any[]): string | null {
|
|
||||||
const enterpriseOrganizations = organizations.filter((org) => org.canManageSponsorships);
|
|
||||||
return enterpriseOrganizations.length === 1 ? enterpriseOrganizations[0].id : null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user