mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-29 04:17:41 +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:
parent
b914260705
commit
5f97f4c4a8
@ -121,7 +121,11 @@ export abstract class OrganizationService {
|
|||||||
get$: (id: string) => Observable<Organization | undefined>;
|
get$: (id: string) => Observable<Organization | undefined>;
|
||||||
get: (id: string) => Promise<Organization>;
|
get: (id: string) => Promise<Organization>;
|
||||||
getAll: (userId?: 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[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,6 +73,10 @@ export class OrganizationService implements InternalOrganizationServiceAbstracti
|
|||||||
return this.organizations$.pipe(mapToSingleOrganization(id));
|
return this.organizations$.pipe(mapToSingleOrganization(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAll$(userId?: UserId): Observable<Organization[]> {
|
||||||
|
return this.getOrganizationsFromState$(userId);
|
||||||
|
}
|
||||||
|
|
||||||
async getAll(userId?: string): Promise<Organization[]> {
|
async getAll(userId?: string): Promise<Organization[]> {
|
||||||
return await firstValueFrom(this.getOrganizationsFromState$(userId as UserId));
|
return await firstValueFrom(this.getOrganizationsFromState$(userId as UserId));
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,8 @@ describe("PolicyService", () => {
|
|||||||
organizationService = mock<OrganizationService>();
|
organizationService = mock<OrganizationService>();
|
||||||
|
|
||||||
activeUserState = stateProvider.activeUser.getFake(POLICIES);
|
activeUserState = stateProvider.activeUser.getFake(POLICIES);
|
||||||
organizationService.organizations$ = of([
|
|
||||||
|
const organizations$ = of([
|
||||||
// User
|
// User
|
||||||
organization("org1", true, true, OrganizationUserStatusType.Confirmed, false),
|
organization("org1", true, true, OrganizationUserStatusType.Confirmed, false),
|
||||||
// Owner
|
// Owner
|
||||||
@ -54,6 +55,10 @@ describe("PolicyService", () => {
|
|||||||
organization("org6", true, true, OrganizationUserStatusType.Confirmed, true),
|
organization("org6", true, true, OrganizationUserStatusType.Confirmed, true),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
organizationService.organizations$ = organizations$;
|
||||||
|
|
||||||
|
organizationService.getAll$.mockReturnValue(organizations$);
|
||||||
|
|
||||||
policyService = new PolicyService(stateProvider, organizationService);
|
policyService = new PolicyService(stateProvider, organizationService);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ export class PolicyService implements InternalPolicyServiceAbstraction {
|
|||||||
map((policies) => policies.filter((p) => p.type === policyType)),
|
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)),
|
map(([policies, organizations]) => this.enforcedPolicyFilter(policies, organizations)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user