mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 22:33:35 +00:00
[PM-24689] Handle possible null active account (#16006)
This commit is contained in:
@@ -67,6 +67,13 @@ describe("RestrictedItemTypesService", () => {
|
|||||||
expect(result).toEqual([]);
|
expect(result).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("emits empty array if no account is active", async () => {
|
||||||
|
accountService.activeAccount$ = of(null);
|
||||||
|
|
||||||
|
const result = await firstValueFrom(service.restricted$);
|
||||||
|
expect(result).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
it("emits empty array if no organizations exist", async () => {
|
it("emits empty array if no organizations exist", async () => {
|
||||||
organizationService.organizations$.mockReturnValue(of([]));
|
organizationService.organizations$.mockReturnValue(of([]));
|
||||||
policyService.policiesByType$.mockReturnValue(of([]));
|
policyService.policiesByType$.mockReturnValue(of([]));
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { OrganizationService } from "@bitwarden/common/admin-console/abstraction
|
|||||||
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
|
||||||
import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
import { PolicyType } from "@bitwarden/common/admin-console/enums";
|
||||||
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 { getOptionalUserId } from "@bitwarden/common/auth/services/account.service";
|
||||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||||
@@ -32,13 +32,15 @@ export class RestrictedItemTypesService {
|
|||||||
return of([]);
|
return of([]);
|
||||||
}
|
}
|
||||||
return this.accountService.activeAccount$.pipe(
|
return this.accountService.activeAccount$.pipe(
|
||||||
getUserId,
|
getOptionalUserId,
|
||||||
switchMap((userId) =>
|
switchMap((userId) => {
|
||||||
combineLatest([
|
if (userId == null) {
|
||||||
|
return of([]); // No user logged in, no restrictions
|
||||||
|
}
|
||||||
|
return combineLatest([
|
||||||
this.organizationService.organizations$(userId),
|
this.organizationService.organizations$(userId),
|
||||||
this.policyService.policiesByType$(PolicyType.RestrictedItemTypes, userId),
|
this.policyService.policiesByType$(PolicyType.RestrictedItemTypes, userId),
|
||||||
]),
|
]).pipe(
|
||||||
),
|
|
||||||
map(([orgs, enabledPolicies]) => {
|
map(([orgs, enabledPolicies]) => {
|
||||||
// Helper to extract restricted types, defaulting to [Card]
|
// Helper to extract restricted types, defaulting to [Card]
|
||||||
const restrictedTypes = (p: (typeof enabledPolicies)[number]) =>
|
const restrictedTypes = (p: (typeof enabledPolicies)[number]) =>
|
||||||
@@ -68,6 +70,8 @@ export class RestrictedItemTypesService {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
);
|
||||||
|
}),
|
||||||
distinctUntilChanged(),
|
distinctUntilChanged(),
|
||||||
shareReplay({ bufferSize: 1, refCount: true }),
|
shareReplay({ bufferSize: 1, refCount: true }),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user