1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-14 07:13:32 +00:00

[EC-739 / EC-740] Add null check to policyFilter on PolicyService (#4039)

* [EC-739 / EC-740] Add null check to policyFilter on PolicyService

* [EC-739 / EC-740] Add unit tests for policy filter
This commit is contained in:
Rui Tomé
2022-11-11 15:13:27 +00:00
committed by GitHub
parent d3321ebe1c
commit 235fb8f6ee
2 changed files with 60 additions and 7 deletions

View File

@@ -124,10 +124,7 @@ export class PolicyService implements InternalPolicyServiceAbstraction {
);
}
policyAppliesToActiveUser$(
policyType: PolicyType,
policyFilter: (policy: Policy) => boolean = (p) => true
) {
policyAppliesToActiveUser$(policyType: PolicyType, policyFilter?: (policy: Policy) => boolean) {
return this.policies$.pipe(
concatMap(async (policies) => {
const userId = await this.stateService.getUserId();
@@ -257,12 +254,12 @@ export class PolicyService implements InternalPolicyServiceAbstraction {
private async checkPoliciesThatApplyToUser(
policies: Policy[],
policyType: PolicyType,
policyFilter: (policy: Policy) => boolean = (p) => true,
policyFilter?: (policy: Policy) => boolean,
userId?: string
) {
const organizations = await this.organizationService.getAll(userId);
const filteredPolicies = policies.filter(
(p) => p.type === policyType && p.enabled && policyFilter(p)
(p) => p.type === policyType && p.enabled && (policyFilter == null || policyFilter(p))
);
const policySet = new Set(filteredPolicies.map((p) => p.organizationId));