From bc734524007db391f725b2dd223b8314393e5d42 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Thu, 2 Sep 2021 07:51:04 +1000 Subject: [PATCH] Move policy checks within policyService (#1149) * Refactor: use new policyService methods * Update jslib --- src/app/organizations/manage/people.component.ts | 5 +++-- src/app/settings/organization-plans.component.ts | 12 +----------- src/app/settings/two-factor-setup.component.ts | 3 +-- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/app/organizations/manage/people.component.ts b/src/app/organizations/manage/people.component.ts index 572aae63..aa3a8b8f 100644 --- a/src/app/organizations/manage/people.component.ts +++ b/src/app/organizations/manage/people.component.ts @@ -136,8 +136,9 @@ export class PeopleComponent extends BasePeopleComponent p.organizationId === this.organizationId && p.enabled); + const resetPasswordPolicy = await this.policyService.getPolicyForOrganization(PolicyType.ResetPassword, + this.organizationId); + this.orgResetPasswordPolicyEnabled = resetPasswordPolicy?.enabled; super.load(); } diff --git a/src/app/settings/organization-plans.component.ts b/src/app/settings/organization-plans.component.ts index 3da59ae8..f2e9b2dd 100644 --- a/src/app/settings/organization-plans.component.ts +++ b/src/app/settings/organization-plans.component.ts @@ -268,17 +268,7 @@ export class OrganizationPlansComponent implements OnInit { } private async userHasBlockingSingleOrgPolicy() { - const policies = await this.policyService.getAll(PolicyType.SingleOrg); - const orgs = await this.userService.getAllOrganizations(); - - const orgsWithSingleOrgPolicy = policies - .filter(p => p.enabled && p.type === PolicyType.SingleOrg) - .map(p => p.organizationId); - - return orgs.some(org => org.type !== OrganizationUserType.Owner && - org.type !== OrganizationUserType.Admin && - org.status !== OrganizationUserStatusType.Invited && - orgsWithSingleOrgPolicy.includes(org.id)); + return this.policyService.policyAppliesToUser(PolicyType.SingleOrg); } private async updateOrganization(orgId: string) { diff --git a/src/app/settings/two-factor-setup.component.ts b/src/app/settings/two-factor-setup.component.ts index 17401386..b6b5aef5 100644 --- a/src/app/settings/two-factor-setup.component.ts +++ b/src/app/settings/two-factor-setup.component.ts @@ -168,8 +168,7 @@ export class TwoFactorSetupComponent implements OnInit { private async evaluatePolicies() { if (this.organizationId == null && this.providers.filter(p => p.enabled).length === 1) { - const policies = await this.policyService.getAll(PolicyType.TwoFactorAuthentication); - this.showPolicyWarning = policies != null && policies.some(p => p.enabled); + this.showPolicyWarning = await this.policyService.policyAppliesToUser(PolicyType.TwoFactorAuthentication); } else { this.showPolicyWarning = false; }