1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-19 02:51:14 +02:00

Fixes and cleanup for policyAppliesToUser (#476)

* Fix canManagePolicies logic to include providers

* Move new logic to isOwner (same as server)

* Refactor policyAppliesToUser

* Use const instead of var

* Fix linting
This commit is contained in:
Thomas Rittson 2021-09-09 07:34:27 +10:00 committed by GitHub
parent bbe8d3df48
commit 5f64d95652
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 12 deletions

View File

@ -89,7 +89,7 @@ export class Organization {
} }
get isOwner() { get isOwner() {
return this.type === OrganizationUserType.Owner; return this.type === OrganizationUserType.Owner || this.isProviderUser;
} }
get canAccessBusinessPortal() { get canAccessBusinessPortal() {

View File

@ -172,21 +172,18 @@ export class PolicyService implements PolicyServiceAbstraction {
} }
async policyAppliesToUser(policyType: PolicyType, policyFilter?: (policy: Policy) => boolean) { async policyAppliesToUser(policyType: PolicyType, policyFilter?: (policy: Policy) => boolean) {
if (policyFilter == null) {
policyFilter = (policy: Policy) => true;
}
const policies = await this.getAll(policyType); const policies = await this.getAll(policyType);
const organizations = await this.userService.getAllOrganizations(); const organizations = await this.userService.getAllOrganizations();
let filteredPolicies;
const filteredPolicies = policies if (policyFilter != null) {
.filter(p => filteredPolicies = policies.filter(p => p.enabled && policyFilter(p));
p.enabled && }
p.type === policyType && else {
policyFilter(p)) filteredPolicies = policies.filter(p => p.enabled);
.map(p => p.organizationId); }
const policySet = new Set(filteredPolicies); const policySet = new Set(filteredPolicies.map(p => p.organizationId));
return organizations.some(o => return organizations.some(o =>
o.enabled && o.enabled &&