1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-06-25 10:25:36 +02:00

Update Organization and Policy Services to allow the passing of a user id and to prevent hangs waiting on an active user (#8712)

* OrgSvc - add new observable returning getAll$ method which accepts a required user id

* OrgSvc - make user id optional

* PolicySvc - getAll$ should use the new OrgSvc.getAll$ method so that it doesn't hang if there isn't an active user yet but a user id was passed in.

* Fix policy service tests
This commit is contained in:
Jared Snider 2024-04-12 10:21:19 -04:00 committed by GitHub
parent b914260705
commit 5f97f4c4a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 3 deletions

View File

@ -121,7 +121,11 @@ export abstract class OrganizationService {
get$: (id: string) => Observable<Organization | undefined>;
get: (id: string) => Promise<Organization>;
getAll: (userId?: string) => Promise<Organization[]>;
//
/**
* Publishes state for all organizations for the given user id or the active user.
*/
getAll$: (userId?: UserId) => Observable<Organization[]>;
}
/**

View File

@ -73,6 +73,10 @@ export class OrganizationService implements InternalOrganizationServiceAbstracti
return this.organizations$.pipe(mapToSingleOrganization(id));
}
getAll$(userId?: UserId): Observable<Organization[]> {
return this.getOrganizationsFromState$(userId);
}
async getAll(userId?: string): Promise<Organization[]> {
return await firstValueFrom(this.getOrganizationsFromState$(userId as UserId));
}

View File

@ -32,7 +32,8 @@ describe("PolicyService", () => {
organizationService = mock<OrganizationService>();
activeUserState = stateProvider.activeUser.getFake(POLICIES);
organizationService.organizations$ = of([
const organizations$ = of([
// User
organization("org1", true, true, OrganizationUserStatusType.Confirmed, false),
// Owner
@ -54,6 +55,10 @@ describe("PolicyService", () => {
organization("org6", true, true, OrganizationUserStatusType.Confirmed, true),
]);
organizationService.organizations$ = organizations$;
organizationService.getAll$.mockReturnValue(organizations$);
policyService = new PolicyService(stateProvider, organizationService);
});

View File

@ -51,7 +51,7 @@ export class PolicyService implements InternalPolicyServiceAbstraction {
map((policies) => policies.filter((p) => p.type === policyType)),
);
return combineLatest([filteredPolicies$, this.organizationService.organizations$]).pipe(
return combineLatest([filteredPolicies$, this.organizationService.getAll$(userId)]).pipe(
map(([policies, organizations]) => this.enforcedPolicyFilter(policies, organizations)),
);
}