From dd47eed7c7cafdd4dbda06292c03fc91424c78ae Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Wed, 8 Sep 2021 07:19:49 +1000 Subject: [PATCH] Disable personal imports if Personal Ownership policy applies (#1176) * Disable imports if personal ownership policy set * Add missing await --- src/app/organizations/tools/import.component.ts | 8 +++++--- src/app/tools/import.component.html | 14 ++++++++++---- src/app/tools/import.component.ts | 16 ++++++++++++++-- src/locales/en/messages.json | 3 +++ 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/app/organizations/tools/import.component.ts b/src/app/organizations/tools/import.component.ts index e0f0f4d4e0..04c5e8597b 100644 --- a/src/app/organizations/tools/import.component.ts +++ b/src/app/organizations/tools/import.component.ts @@ -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; diff --git a/src/app/tools/import.component.html b/src/app/tools/import.component.html index 578695f36a..c52d4b1d3b 100644 --- a/src/app/tools/import.component.html +++ b/src/app/tools/import.component.html @@ -1,12 +1,16 @@ + + {{'personalOwnershipPolicyInEffectImports' | i18n}} +
- @@ -240,15 +244,17 @@
- +
- +
- diff --git a/src/app/tools/import.component.ts b/src/app/tools/import.component.ts index d6e6bc442b..5149b977d4 100644 --- a/src/app/tools/import.component.ts +++ b/src/app/tools/import.component.ts @@ -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; 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); diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index db7ef380b2..c8c46ec2ed 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -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" },