From d9fca83e04f4f267f17360b5f97244c4647d47b2 Mon Sep 17 00:00:00 2001 From: Vito Date: Thu, 6 Jul 2017 05:29:41 -0700 Subject: [PATCH] =?UTF-8?q?[ADF-917]=20added=20exlcluded=20files=20into=20?= =?UTF-8?q?app=20config=20to=20prevent=20special=20fi=E2=80=A6=20(#2039)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [ADF 917] added exlcluded files into app config to prevent special files upload --- demo-shell-ng2/app.config-dev.json | 3 +++ demo-shell-ng2/app.config-prod.json | 3 +++ demo-shell-ng2/package-lock.json | 12 ++++------ demo-shell-ng2/package.json | 1 + .../src/services/app-config.service.spec.ts | 12 ++++++++++ ng2-components/ng2-alfresco-upload/README.md | 23 +++++++++++++++++++ .../ng2-alfresco-upload/package-lock.json | 12 ++++------ .../ng2-alfresco-upload/package.json | 5 ++-- .../src/services/upload.service.spec.ts | 20 +++++++++++++--- .../src/services/upload.service.ts | 22 +++++++++++++----- 10 files changed, 86 insertions(+), 27 deletions(-) diff --git a/demo-shell-ng2/app.config-dev.json b/demo-shell-ng2/app.config-dev.json index 460679a49c..d596b1c58b 100644 --- a/demo-shell-ng2/app.config-dev.json +++ b/demo-shell-ng2/app.config-dev.json @@ -7,6 +7,9 @@ "pagination": { "size": 25 }, + "files": { + "excluded": [".DS_Store", "desktop.ini", ".git"] + }, "activiti": { "rest": { "fields": [ diff --git a/demo-shell-ng2/app.config-prod.json b/demo-shell-ng2/app.config-prod.json index ea4bda0fed..fb64e6299f 100644 --- a/demo-shell-ng2/app.config-prod.json +++ b/demo-shell-ng2/app.config-prod.json @@ -7,6 +7,9 @@ "pagination": { "size": 25 }, + "files": { + "excluded": [".DS_Store", "desktop.ini", ".git"] + }, "activiti": { "rest": { "fields": [ diff --git a/demo-shell-ng2/package-lock.json b/demo-shell-ng2/package-lock.json index 73f8529a9f..b3965c8919 100644 --- a/demo-shell-ng2/package-lock.json +++ b/demo-shell-ng2/package-lock.json @@ -412,8 +412,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "base64-arraybuffer": { "version": "0.1.5", @@ -567,8 +566,7 @@ "brace-expansion": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", - "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", - "dev": true + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=" }, "braces": { "version": "1.8.5", @@ -934,8 +932,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "configstore": { "version": "3.1.0", @@ -4986,8 +4983,7 @@ "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==" }, "minimist": { "version": "1.2.0", diff --git a/demo-shell-ng2/package.json b/demo-shell-ng2/package.json index 30be9b33fd..0b88e1eeb4 100644 --- a/demo-shell-ng2/package.json +++ b/demo-shell-ng2/package.json @@ -76,6 +76,7 @@ "material-design-icons": "2.2.3", "material-design-lite": "1.2.1", "md-date-time-picker": "2.2.0", + "minimatch": "3.0.4", "moment": "2.15.1", "ng2-3d-editor": "0.0.15", "ng2-activiti-analytics": "1.6.1", diff --git a/ng2-components/ng2-alfresco-core/src/services/app-config.service.spec.ts b/ng2-components/ng2-alfresco-core/src/services/app-config.service.spec.ts index d930745c7b..1c229e57ae 100644 --- a/ng2-components/ng2-alfresco-core/src/services/app-config.service.spec.ts +++ b/ng2-components/ng2-alfresco-core/src/services/app-config.service.spec.ts @@ -28,6 +28,9 @@ describe('AppConfigService', () => { 'bpmHost': 'http://localhost:4000/ecm', 'application': { 'name': 'Custom Name' + }, + 'files': { + 'excluded': ['exluded'] } }; @@ -88,4 +91,13 @@ describe('AppConfigService', () => { expect(appConfigService.configFile).toBe(name); }); }); + + it('should take excluded file list', () => { + expect(appConfigService.configFile).toBeNull(); + + const name = 'custom.config.json'; + appConfigService.load(name).then(() => { + expect(appConfigService.get('files.excluded')[0]).toBe('exluded'); + }); + }); }); diff --git a/ng2-components/ng2-alfresco-upload/README.md b/ng2-components/ng2-alfresco-upload/README.md index 137faa4880..2d8d18bce0 100644 --- a/ng2-components/ng2-alfresco-upload/README.md +++ b/ng2-components/ng2-alfresco-upload/README.md @@ -191,6 +191,29 @@ This component should be used in combination with upload button or drag & drop a Provides access to various APIs related to file upload features. +### Configuration + +There is the possibility to point out file name or file extension to be excluded from upload process into the app.config.json file, see [here](https://github.com/Alfresco/alfresco-ng2-components/tree/master/ng2-components/ng2-alfresco-core#appconfigservice) for more details. +This will make easy avoiding uploading of system files like : '.DS_Store'. +By default the file already filtered are : '.git', '.DS_Store' and 'desktop.ini'. +It is possible to add any expression for filtering file like '*.txt'.The file name check is done via +[minimatch library](https://www.npmjs.com/package/minimatch) so in file excluded list is possible to add any expression accepted by this library. + +**app.config.json** + +```json +{ + "ecmHost": "http://localhost:3000/ecm", + "bpmHost": "http://localhost:3000/bpm", + "application": { + "name": "Alfresco" + }, + "files": { + "excluded": [".DS_Store", "desktop.ini", ".git"] + } +} +``` + ### Events | Name | Type | Description | diff --git a/ng2-components/ng2-alfresco-upload/package-lock.json b/ng2-components/ng2-alfresco-upload/package-lock.json index cf0d58deb4..2a35ffffc8 100644 --- a/ng2-components/ng2-alfresco-upload/package-lock.json +++ b/ng2-components/ng2-alfresco-upload/package-lock.json @@ -509,8 +509,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "base64-arraybuffer": { "version": "0.1.5", @@ -690,8 +689,7 @@ "brace-expansion": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", - "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", - "dev": true + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=" }, "braces": { "version": "1.8.5", @@ -1046,8 +1044,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "configstore": { "version": "3.1.0", @@ -4466,8 +4463,7 @@ "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==" }, "minimist": { "version": "1.2.0", diff --git a/ng2-components/ng2-alfresco-upload/package.json b/ng2-components/ng2-alfresco-upload/package.json index 60bfe91e7c..a61fe7d65c 100644 --- a/ng2-components/ng2-alfresco-upload/package.json +++ b/ng2-components/ng2-alfresco-upload/package.json @@ -49,15 +49,16 @@ "@angular/core": "4.2.5", "@angular/forms": "4.2.5", "@angular/http": "4.2.5", + "@angular/material": "2.0.0-beta.6", "@angular/platform-browser": "4.2.5", "@angular/platform-browser-dynamic": "4.2.5", "@angular/router": "4.2.5", - "@angular/material": "2.0.0-beta.6", + "@ngx-translate/core": "7.0.0", "alfresco-js-api": "~1.6.1", "core-js": "2.4.1", "hammerjs": "2.0.8", + "minimatch": "3.0.4", "ng2-alfresco-core": "1.6.1", - "@ngx-translate/core": "7.0.0", "reflect-metadata": "0.1.10", "rxjs": "5.1.0", "systemjs": "0.19.27", diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts index 12b9b8129d..9c8ed57e64 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts @@ -31,7 +31,10 @@ describe('UploadService', () => { imports: [ CoreModule.forRoot(), AppConfigModule.forRoot('app.config.json', { - ecmHost: 'http://localhost:9876/ecm' + ecmHost: 'http://localhost:9876/ecm', + files: { + excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git'] + } }) ], providers: [ @@ -82,7 +85,7 @@ describe('UploadService', () => { }); let fileFake = new FileModel( { name: 'fake-name', size: 10 }, - { parentId: '-root-', path: 'fake-dir' } + { parentId: '-root-', path: 'fake-dir' } ); service.addToQueue(fileFake); service.uploadFilesInTheQueue(emitter); @@ -107,7 +110,7 @@ describe('UploadService', () => { }); let fileFake = new FileModel( { name: 'fake-name', size: 10 }, - { parentId: '-root-' } + { parentId: '-root-' } ); service.addToQueue(fileFake); service.uploadFilesInTheQueue(emitter); @@ -193,4 +196,15 @@ describe('UploadService', () => { let file = service.getQueue(); service.cancelUpload(...file); }); + + it('should remove from the queue all the files in the exluded list', () => { + const file1 = new FileModel(new File([''], '.git')); + const file2 = new FileModel(new File([''], '.DS_Store')); + const file3 = new FileModel(new File([''], 'desktop.ini')); + const file4 = new FileModel(new File([''], 'readme.md')); + const file5 = new FileModel(new File([''], 'test.git')); + const result = service.addToQueue(file1, file2, file3, file4, file5); + expect(result.length).toBe(1); + expect(result[0]).toBe(file4); + }); }); diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts index cb50c7985b..08477f522c 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts @@ -17,9 +17,10 @@ import { EventEmitter, Injectable } from '@angular/core'; import { Subject } from 'rxjs/Rx'; -import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { AlfrescoApiService, AppConfigService } from 'ng2-alfresco-core'; import { FileUploadEvent, FileUploadCompleteEvent } from '../events/file.event'; import { FileModel, FileUploadProgress, FileUploadStatus } from '../models/file.model'; +import * as minimatch from 'minimatch'; @Injectable() export class UploadService { @@ -29,6 +30,7 @@ export class UploadService { private totalComplete: number = 0; private totalAborted: number = 0; private activeTask: Promise = null; + private excludedFileList: String[] = []; queueChanged: Subject = new Subject(); fileUpload: Subject = new Subject(); @@ -39,7 +41,8 @@ export class UploadService { fileUploadError: Subject = new Subject(); fileUploadComplete: Subject = new Subject(); - constructor(private apiService: AlfrescoApiService) { + constructor(private apiService: AlfrescoApiService, private appConfigService: AppConfigService) { + this.excludedFileList = this.appConfigService.get('files.excluded'); } /** @@ -71,12 +74,20 @@ export class UploadService { * addToQueue(...[file1, file2, file3]); // pass an array of files */ addToQueue(...files: FileModel[]): FileModel[] { - const allowedFiles = files.filter(f => !f.name.startsWith('.')); + const allowedFiles = files.filter(f => this.filterElement(f)); this.queue = this.queue.concat(allowedFiles); this.queueChanged.next(this.queue); return allowedFiles; } + private filterElement(file: FileModel) { + let isAllowed = true; + if (this.excludedFileList) { + isAllowed = this.excludedFileList.filter(expr => minimatch(file.name, expr)).length === 0; + } + return isAllowed; + } + /** * Pick all the files in the queue that are not been uploaded yet and upload it into the directory folder. * @@ -133,8 +144,8 @@ export class UploadService { private beginUpload(file: FileModel, /* @deprecated */emitter: EventEmitter): any { let opts: any = { - renditions: 'doclib' - }; + renditions: 'doclib' + }; if (file.options.newVersion === true) { opts.overwrite = true; @@ -167,7 +178,6 @@ export class UploadService { .catch(err => { this.onUploadError(file, err); }); - return promise; }