mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 13:23:34 +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" })
|
||||
export class FreeFamiliesPolicyService {
|
||||
protected enterpriseOrgStatus: EnterpriseOrgStatus = {
|
||||
isFreeFamilyPolicyEnabled: false,
|
||||
belongToOneEnterpriseOrgs: false,
|
||||
belongToMultipleEnterpriseOrgs: false,
|
||||
};
|
||||
|
||||
constructor(
|
||||
private policyService: PolicyService,
|
||||
private organizationService: OrganizationService,
|
||||
@@ -104,9 +98,11 @@ export class FreeFamiliesPolicyService {
|
||||
if (!orgStatus) {
|
||||
return false;
|
||||
}
|
||||
const { belongToOneEnterpriseOrgs, isFreeFamilyPolicyEnabled } = orgStatus;
|
||||
const { isFreeFamilyPolicyEnabled } = orgStatus;
|
||||
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> {
|
||||
@@ -122,16 +118,12 @@ export class FreeFamiliesPolicyService {
|
||||
const { belongToOneEnterpriseOrgs, belongToMultipleEnterpriseOrgs } =
|
||||
this.evaluateEnterpriseOrganizations(organizations);
|
||||
|
||||
if (!belongToOneEnterpriseOrgs) {
|
||||
return of({
|
||||
isFreeFamilyPolicyEnabled: false,
|
||||
belongToOneEnterpriseOrgs,
|
||||
belongToMultipleEnterpriseOrgs,
|
||||
});
|
||||
}
|
||||
// Get all enterprise organization IDs
|
||||
const enterpriseOrgIds = organizations
|
||||
.filter((org) => org.canManageSponsorships)
|
||||
.map((org) => org.id);
|
||||
|
||||
const organizationId = this.getOrganizationIdForOneEnterprise(organizations);
|
||||
if (!organizationId) {
|
||||
if (enterpriseOrgIds.length === 0) {
|
||||
return of({
|
||||
isFreeFamilyPolicyEnabled: false,
|
||||
belongToOneEnterpriseOrgs,
|
||||
@@ -145,8 +137,8 @@ export class FreeFamiliesPolicyService {
|
||||
this.policyService.policiesByType$(PolicyType.FreeFamiliesSponsorshipPolicy, userId),
|
||||
),
|
||||
map((policies) => ({
|
||||
isFreeFamilyPolicyEnabled: policies.some(
|
||||
(policy) => policy.organizationId === organizationId && policy.enabled,
|
||||
isFreeFamilyPolicyEnabled: enterpriseOrgIds.every((orgId) =>
|
||||
policies.some((policy) => policy.organizationId === orgId && policy.enabled),
|
||||
),
|
||||
belongToOneEnterpriseOrgs,
|
||||
belongToMultipleEnterpriseOrgs,
|
||||
@@ -166,9 +158,4 @@ export class FreeFamiliesPolicyService {
|
||||
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