Disable personal imports if Personal Ownership policy applies (#1176)

* Disable imports if personal ownership policy set

* Add missing await
This commit is contained in:
Thomas Rittson 2021-09-08 07:19:49 +10:00 committed by GitHub
parent f584950dda
commit dd47eed7c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 9 deletions

View File

@ -9,6 +9,7 @@ import { ToasterService } from 'angular2-toaster';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { ImportService } from 'jslib-common/abstractions/import.service'; import { ImportService } from 'jslib-common/abstractions/import.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { PolicyService } from 'jslib-common/abstractions/policy.service';
import { UserService } from 'jslib-common/abstractions/user.service'; import { UserService } from 'jslib-common/abstractions/user.service';
import { ImportComponent as BaseImportComponent } from '../../tools/import.component'; import { ImportComponent as BaseImportComponent } from '../../tools/import.component';
@ -22,16 +23,17 @@ export class ImportComponent extends BaseImportComponent {
constructor(i18nService: I18nService, toasterService: ToasterService, constructor(i18nService: I18nService, toasterService: ToasterService,
importService: ImportService, router: Router, private route: ActivatedRoute, importService: ImportService, router: Router, private route: ActivatedRoute,
platformUtilsService: PlatformUtilsService, platformUtilsService: PlatformUtilsService, policyService: PolicyService,
private userService: UserService) { private userService: UserService) {
super(i18nService, toasterService, importService, router, platformUtilsService); super(i18nService, toasterService, importService, router, platformUtilsService, policyService);
} }
async ngOnInit() { async ngOnInit() {
this.route.parent.parent.params.subscribe(async params => { this.route.parent.parent.params.subscribe(async params => {
this.organizationId = params.organizationId; this.organizationId = params.organizationId;
this.successNavigate = ['organizations', this.organizationId, 'vault']; this.successNavigate = ['organizations', this.organizationId, 'vault'];
super.ngOnInit(); await super.ngOnInit();
this.importBlockedByPolicy = false;
}); });
const organization = await this.userService.getOrganization(this.organizationId); const organization = await this.userService.getOrganization(this.organizationId);
this.organizationName = organization.name; this.organizationName = organization.name;

View File

@ -1,12 +1,16 @@
<div class="page-header"> <div class="page-header">
<h1>{{'importData' | i18n}}</h1> <h1>{{'importData' | i18n}}</h1>
</div> </div>
<app-callout type="info" *ngIf="importBlockedByPolicy">
{{'personalOwnershipPolicyInEffectImports' | i18n}}
</app-callout>
<form #form (ngSubmit)="submit()" ngNativeValidate> <form #form (ngSubmit)="submit()" ngNativeValidate>
<div class="row"> <div class="row">
<div class="col-6"> <div class="col-6">
<div class="form-group"> <div class="form-group">
<label for="type">1. {{'selectFormat' | i18n}}</label> <label for="type">1. {{'selectFormat' | i18n}}</label>
<select id="type" name="Format" [(ngModel)]="format" class="form-control" required> <select id="type" name="Format" [(ngModel)]="format" class="form-control"
[disabled]="importBlockedByPolicy" required>
<option *ngFor="let o of featuredImportOptions" [ngValue]="o.id">{{o.name}}</option> <option *ngFor="let o of featuredImportOptions" [ngValue]="o.id">{{o.name}}</option>
<ng-container *ngIf="importOptions && importOptions.length"> <ng-container *ngIf="importOptions && importOptions.length">
<option value="-" disabled></option> <option value="-" disabled></option>
@ -240,15 +244,17 @@
<div class="col-6"> <div class="col-6">
<div class="form-group"> <div class="form-group">
<label for="file">2. {{'selectImportFile' | i18n}}</label> <label for="file">2. {{'selectImportFile' | i18n}}</label>
<input type="file" id="file" class="form-control-file" name="file"> <input type="file" id="file" class="form-control-file" name="file" [disabled]="importBlockedByPolicy">
</div> </div>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="fileContents">{{'orCopyPasteFileContents' | i18n}}</label> <label for="fileContents">{{'orCopyPasteFileContents' | i18n}}</label>
<textarea id="fileContents" class="form-control" name="FileContents" [(ngModel)]="fileContents"></textarea> <textarea id="fileContents" class="form-control" name="FileContents" [(ngModel)]="fileContents"
[disabled]="importBlockedByPolicy"></textarea>
</div> </div>
<button type="submit" class="btn btn-primary btn-submit" [disabled]="loading"> <button type="submit" class="btn btn-primary btn-submit" [disabled]="loading || importBlockedByPolicy"
[ngClass]="{manual:importBlockedByPolicy}">
<i class="fa fa-spinner fa-spin" title="{{'loading' | i18n}}" aria-hidden="true"></i> <i class="fa fa-spinner fa-spin" title="{{'loading' | i18n}}" aria-hidden="true"></i>
<span>{{'importData' | i18n}}</span> <span>{{'importData' | i18n}}</span>
</button> </button>

View File

@ -9,6 +9,9 @@ import { ToasterService } from 'angular2-toaster';
import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { ImportOption, ImportService } from 'jslib-common/abstractions/import.service'; import { ImportOption, ImportService } from 'jslib-common/abstractions/import.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { PolicyService } from 'jslib-common/abstractions/policy.service';
import { PolicyType } from 'jslib-common/enums/policyType';
import Swal, { SweetAlertIcon } from 'sweetalert2'; import Swal, { SweetAlertIcon } from 'sweetalert2';
@ -23,15 +26,16 @@ export class ImportComponent implements OnInit {
fileContents: string; fileContents: string;
formPromise: Promise<Error>; formPromise: Promise<Error>;
loading: boolean = false; loading: boolean = false;
importBlockedByPolicy: boolean = false;
protected organizationId: string = null; protected organizationId: string = null;
protected successNavigate: any[] = ['vault']; protected successNavigate: any[] = ['vault'];
constructor(protected i18nService: I18nService, protected toasterService: ToasterService, constructor(protected i18nService: I18nService, protected toasterService: ToasterService,
protected importService: ImportService, protected router: Router, protected importService: ImportService, protected router: Router,
protected platformUtilsService: PlatformUtilsService) { } protected platformUtilsService: PlatformUtilsService, protected policyService: PolicyService) { }
ngOnInit() { async ngOnInit() {
this.setImportOptions(); this.setImportOptions();
this.importOptions.sort((a, b) => { this.importOptions.sort((a, b) => {
if (a.name == null && b.name != null) { if (a.name == null && b.name != null) {
@ -47,9 +51,17 @@ export class ImportComponent implements OnInit {
return this.i18nService.collator ? this.i18nService.collator.compare(a.name, b.name) : return this.i18nService.collator ? this.i18nService.collator.compare(a.name, b.name) :
a.name.localeCompare(b.name); a.name.localeCompare(b.name);
}); });
this.importBlockedByPolicy = await this.policyService.policyAppliesToUser(PolicyType.PersonalOwnership);
} }
async submit() { async submit() {
if (this.importBlockedByPolicy) {
this.platformUtilsService.showToast('error', null,
this.i18nService.t('personalOwnershipPolicyInEffectImports'));
return;
}
this.loading = true; this.loading = true;
const importer = this.importService.getImporter(this.format, this.organizationId); const importer = this.importService.getImporter(this.format, this.organizationId);

View File

@ -3796,6 +3796,9 @@
"personalOwnershipPolicyInEffect": { "personalOwnershipPolicyInEffect": {
"message": "An organization policy is affecting your ownership options." "message": "An organization policy is affecting your ownership options."
}, },
"personalOwnershipPolicyInEffectImports": {
"message": "An organization policy has disabled importing items into your personal vault."
},
"personalOwnershipCheckboxDesc": { "personalOwnershipCheckboxDesc": {
"message": "Disable personal ownership for organization users" "message": "Disable personal ownership for organization users"
}, },