Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Refactor orgnaization policy management #1147

Merged
merged 7 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import { ProviderUserType } from 'jslib-common/enums/providerUserType';

import { ValidationService } from 'jslib-angular/services/validation.service';

import { Organization } from 'jslib-common/models/domain/organization';
import {
ProviderOrganizationOrganizationDetailsResponse
} from 'jslib-common/models/response/provider/providerOrganizationResponse';
import { Organization } from 'jslib-common/models/domain/organization';

import { ModalComponent } from 'src/app/modal.component';

Expand Down Expand Up @@ -88,7 +88,7 @@ export class ClientsComponent implements OnInit {
.map(o => o.id));
this.addableOrganizations = candidateOrgs.filter(o => allowedOrgsIds.includes(o.id));

this.showAddExisting = this.addableOrganizations.length != 0;
this.showAddExisting = this.addableOrganizations.length !== 0;
this.loading = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class SetupComponent implements OnInit {

this.providerId = qParams.providerId;
this.token = qParams.token;

// Check if provider exists, redirect if it does
try {
const provider = await this.apiService.getProvider(this.providerId);
Expand Down
26 changes: 25 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,19 @@ import { VaultTimeoutService } from 'jslib-common/abstractions/vaultTimeout.serv

import { ConstantsService } from 'jslib-common/services/constants.service';

import { PolicyListService } from './services/policy-list.service';
import { RouterService } from './services/router.service';

import { DisableSendPolicy } from './organizations/policies/disable-send.component';
import { MasterPasswordPolicy } from './organizations/policies/master-password.component';
import { PasswordGeneratorPolicy } from './organizations/policies/password-generator.component';
import { PersonalOwnershipPolicy } from './organizations/policies/personal-ownership.component';
import { RequireSsoPolicy } from './organizations/policies/require-sso.component';
import { ResetPasswordPolicy } from './organizations/policies/reset-password.component';
import { SendOptionsPolicy } from './organizations/policies/send-options.component';
import { SingleOrgPolicy } from './organizations/policies/single-org.component';
import { TwoFactorAuthenticationPolicy } from './organizations/policies/two-factor-authentication.component';

const BroadcasterSubscriptionId = 'AppComponent';
const IdleTimeout = 60000 * 10; // 10 minutes

Expand All @@ -56,6 +67,7 @@ const IdleTimeout = 60000 * 10; // 10 minutes
templateUrl: 'app.component.html',
})
export class AppComponent implements OnDestroy, OnInit {

toasterConfig: ToasterConfig = new ToasterConfig({
showCloseButton: true,
mouseoverTimerStop: true,
Expand All @@ -80,7 +92,7 @@ export class AppComponent implements OnDestroy, OnInit {
private sanitizer: DomSanitizer, private searchService: SearchService,
private notificationsService: NotificationsService, private routerService: RouterService,
private stateService: StateService, private eventService: EventService,
private policyService: PolicyService) { }
private policyService: PolicyService, protected policyListService: PolicyListService) { }

ngOnInit() {
this.ngZone.runOutsideAngular(() => {
Expand Down Expand Up @@ -170,6 +182,18 @@ export class AppComponent implements OnDestroy, OnInit {
}
});

this.policyListService.addPolicies([
new TwoFactorAuthenticationPolicy(),
new MasterPasswordPolicy(),
new PasswordGeneratorPolicy(),
new SingleOrgPolicy(),
new RequireSsoPolicy(),
new PersonalOwnershipPolicy(),
new DisableSendPolicy(),
new SendOptionsPolicy(),
new ResetPasswordPolicy(),
]);

Comment on lines +185 to +196
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you weren't happy about loading policies here, but I think it's perfect besides being in app.component. We get clear control and vision on what policies are supported & the addPolicies call taking an array is pretty clean.

Just curious, could we not populate the service in policies.component? What about in a constructor for the policy list service?

this.setFullWidth();
}

Expand Down
13 changes: 4 additions & 9 deletions src/app/organizations/manage/policies.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
<app-callout *ngIf="userCanAccessBusinessPortal" [type]="'warning'">
<p>{{'webPoliciesDeprecationWarning' | i18n}}</p>
<button type="button" class="btn btn-outline-secondary"
(click)="goToEnterprisePortal()">{{'businessPortal' | i18n}}</button>
</app-callout>
<div class="page-header d-flex">
<h1>{{'policies' | i18n}}</h1>
</div>
Expand All @@ -13,10 +8,10 @@ <h1>{{'policies' | i18n}}</h1>
<table class="table table-hover table-list" *ngIf="!loading">
<tbody>
<tr *ngFor="let p of policies">
<td *ngIf="p.display">
<a href="#" appStopClick (click)="edit(p)">{{p.name}}</a>
<span class="badge badge-success" *ngIf="p.enabled">{{'enabled' | i18n}}</span>
<small class="text-muted d-block">{{p.description}}</small>
<td *ngIf="p.display(organization)">
<a href="#" appStopClick (click)="edit(p)">{{p.name | i18n}}</a>
<span class="badge badge-success" *ngIf="policiesEnabledMap.get(p.type)">{{'enabled' | i18n}}</span>
<small class="text-muted d-block">{{p.description | i18n}}</small>
</td>
</tr>
</tbody>
Expand Down
96 changes: 18 additions & 78 deletions src/app/organizations/manage/policies.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {

import { PolicyType } from 'jslib-common/enums/policyType';

import { EnvironmentService } from 'jslib-common/abstractions';
import { ApiService } from 'jslib-common/abstractions/api.service';
import { EnvironmentService } from 'jslib-common/abstractions/environment.service';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { UserService } from 'jslib-common/abstractions/user.service';
Expand All @@ -22,8 +22,13 @@ import { PolicyResponse } from 'jslib-common/models/response/policyResponse';

import { ModalComponent } from '../../modal.component';

import { Organization } from 'jslib-common/models/domain/organization';

import { PolicyEditComponent } from './policy-edit.component';

import { PolicyListService } from 'src/app/services/policy-list.service';
import { BasePolicy } from '../policies/base-policy.component';

@Component({
selector: 'app-org-policies',
templateUrl: 'policies.component.html',
Expand All @@ -33,11 +38,11 @@ export class PoliciesComponent implements OnInit {

loading = true;
organizationId: string;
policies: any[];
policies: BasePolicy[];
organization: Organization;

// Remove when removing deprecation warning
enterpriseTokenPromise: Promise<any>;
userCanAccessBusinessPortal = false;

private enterpriseUrl: string;

Expand All @@ -48,81 +53,20 @@ export class PoliciesComponent implements OnInit {
constructor(private apiService: ApiService, private route: ActivatedRoute,
private i18nService: I18nService, private componentFactoryResolver: ComponentFactoryResolver,
private platformUtilsService: PlatformUtilsService, private userService: UserService,
private router: Router, private environmentService: EnvironmentService) { }
private policyListService: PolicyListService, private router: Router,
private environmentService: EnvironmentService) { }

async ngOnInit() {
this.route.parent.parent.params.subscribe(async params => {
this.organizationId = params.organizationId;
const organization = await this.userService.getOrganization(this.organizationId);
if (organization == null || !organization.usePolicies) {
this.organization = await this.userService.getOrganization(this.organizationId);
if (this.organization == null || !this.organization.usePolicies) {
this.router.navigate(['/organizations', this.organizationId]);
return;
}
this.userCanAccessBusinessPortal = organization.canAccessBusinessPortal;
this.policies = [
{
name: this.i18nService.t('twoStepLogin'),
description: this.i18nService.t('twoStepLoginPolicyDesc'),
type: PolicyType.TwoFactorAuthentication,
enabled: false,
display: true,
},
{
name: this.i18nService.t('masterPass'),
description: this.i18nService.t('masterPassPolicyDesc'),
type: PolicyType.MasterPassword,
enabled: false,
display: true,
},
{
name: this.i18nService.t('passwordGenerator'),
description: this.i18nService.t('passwordGeneratorPolicyDesc'),
type: PolicyType.PasswordGenerator,
enabled: false,
display: true,
},
{
name: this.i18nService.t('singleOrg'),
description: this.i18nService.t('singleOrgDesc'),
type: PolicyType.SingleOrg,
enabled: false,
display: true,
},
{
name: this.i18nService.t('requireSso'),
description: this.i18nService.t('requireSsoPolicyDesc'),
type: PolicyType.RequireSso,
enabled: false,
display: organization.useSso,
},
{
name: this.i18nService.t('personalOwnership'),
description: this.i18nService.t('personalOwnershipPolicyDesc'),
type: PolicyType.PersonalOwnership,
enabled: false,
display: true,
},
{
name: this.i18nService.t('disableSend'),
description: this.i18nService.t('disableSendPolicyDesc'),
type: PolicyType.DisableSend,
enabled: false,
display: true,
},
{
name: this.i18nService.t('sendOptions'),
description: this.i18nService.t('sendOptionsPolicyDesc'),
type: PolicyType.SendOptions,
enabled: false,
display: true,
}, {
name: this.i18nService.t('resetPasswordPolicy'),
description: this.i18nService.t('resetPasswordPolicyDescription'),
type: PolicyType.ResetPassword,
enabled: false,
display: organization.useResetPassword,
},
];

this.policies = this.policyListService.getPolicies();

await this.load();

// Handle policies component launch from Event message
Expand Down Expand Up @@ -158,13 +102,11 @@ export class PoliciesComponent implements OnInit {
this.orgPolicies.forEach(op => {
this.policiesEnabledMap.set(op.type, op.enabled);
});
this.policies.forEach(p => {
p.enabled = this.policiesEnabledMap.has(p.type) && this.policiesEnabledMap.get(p.type);
});

this.loading = false;
}

edit(p: any) {
edit(policy: BasePolicy) {
if (this.modal != null) {
this.modal.close();
}
Expand All @@ -174,9 +116,7 @@ export class PoliciesComponent implements OnInit {
const childComponent = this.modal.show<PolicyEditComponent>(
PolicyEditComponent, this.editModalRef);

childComponent.name = p.name;
childComponent.description = p.description;
childComponent.type = p.type;
childComponent.policy = policy;
childComponent.organizationId = this.organizationId;
childComponent.policiesEnabledMap = this.policiesEnabledMap;
childComponent.onSavedPolicy.subscribe(() => {
Expand Down
Loading