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

View File

@ -1,12 +1,16 @@
<div class="page-header">
<h1>{{'importData' | i18n}}</h1>
</div>
<app-callout type="info" *ngIf="importBlockedByPolicy">
{{'personalOwnershipPolicyInEffectImports' | i18n}}
</app-callout>
<form #form (ngSubmit)="submit()" ngNativeValidate>
<div class="row">
<div class="col-6">
<div class="form-group">
<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>
<ng-container *ngIf="importOptions && importOptions.length">
<option value="-" disabled></option>
@ -240,15 +244,17 @@
<div class="col-6">
<div class="form-group">
<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 class="form-group">
<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>
<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>
<span>{{'importData' | i18n}}</span>
</button>

View File

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

View File

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