[ADF-917] added exlcluded files into app config to prevent special fi… (#2039)

* [ADF 917] added exlcluded files into app config to prevent special files upload
This commit is contained in:
Vito
2017-07-06 05:29:41 -07:00
committed by Eugenio Romano
parent 4bd0f04913
commit d9fca83e04
10 changed files with 86 additions and 27 deletions

View File

@@ -7,6 +7,9 @@
"pagination": { "pagination": {
"size": 25 "size": 25
}, },
"files": {
"excluded": [".DS_Store", "desktop.ini", ".git"]
},
"activiti": { "activiti": {
"rest": { "rest": {
"fields": [ "fields": [

View File

@@ -7,6 +7,9 @@
"pagination": { "pagination": {
"size": 25 "size": 25
}, },
"files": {
"excluded": [".DS_Store", "desktop.ini", ".git"]
},
"activiti": { "activiti": {
"rest": { "rest": {
"fields": [ "fields": [

View File

@@ -412,8 +412,7 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
"dev": true
}, },
"base64-arraybuffer": { "base64-arraybuffer": {
"version": "0.1.5", "version": "0.1.5",
@@ -567,8 +566,7 @@
"brace-expansion": { "brace-expansion": {
"version": "1.1.8", "version": "1.1.8",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI="
"dev": true
}, },
"braces": { "braces": {
"version": "1.8.5", "version": "1.8.5",
@@ -934,8 +932,7 @@
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
"dev": true
}, },
"configstore": { "configstore": {
"version": "3.1.0", "version": "3.1.0",
@@ -4986,8 +4983,7 @@
"minimatch": { "minimatch": {
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA=="
"dev": true
}, },
"minimist": { "minimist": {
"version": "1.2.0", "version": "1.2.0",

View File

@@ -76,6 +76,7 @@
"material-design-icons": "2.2.3", "material-design-icons": "2.2.3",
"material-design-lite": "1.2.1", "material-design-lite": "1.2.1",
"md-date-time-picker": "2.2.0", "md-date-time-picker": "2.2.0",
"minimatch": "3.0.4",
"moment": "2.15.1", "moment": "2.15.1",
"ng2-3d-editor": "0.0.15", "ng2-3d-editor": "0.0.15",
"ng2-activiti-analytics": "1.6.1", "ng2-activiti-analytics": "1.6.1",

View File

@@ -28,6 +28,9 @@ describe('AppConfigService', () => {
'bpmHost': 'http://localhost:4000/ecm', 'bpmHost': 'http://localhost:4000/ecm',
'application': { 'application': {
'name': 'Custom Name' 'name': 'Custom Name'
},
'files': {
'excluded': ['exluded']
} }
}; };
@@ -88,4 +91,13 @@ describe('AppConfigService', () => {
expect(appConfigService.configFile).toBe(name); 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');
});
});
}); });

View File

@@ -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. 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 ### Events
| Name | Type | Description | | Name | Type | Description |

View File

@@ -509,8 +509,7 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
"dev": true
}, },
"base64-arraybuffer": { "base64-arraybuffer": {
"version": "0.1.5", "version": "0.1.5",
@@ -690,8 +689,7 @@
"brace-expansion": { "brace-expansion": {
"version": "1.1.8", "version": "1.1.8",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI="
"dev": true
}, },
"braces": { "braces": {
"version": "1.8.5", "version": "1.8.5",
@@ -1046,8 +1044,7 @@
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
"dev": true
}, },
"configstore": { "configstore": {
"version": "3.1.0", "version": "3.1.0",
@@ -4466,8 +4463,7 @@
"minimatch": { "minimatch": {
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA=="
"dev": true
}, },
"minimist": { "minimist": {
"version": "1.2.0", "version": "1.2.0",

View File

@@ -49,15 +49,16 @@
"@angular/core": "4.2.5", "@angular/core": "4.2.5",
"@angular/forms": "4.2.5", "@angular/forms": "4.2.5",
"@angular/http": "4.2.5", "@angular/http": "4.2.5",
"@angular/material": "2.0.0-beta.6",
"@angular/platform-browser": "4.2.5", "@angular/platform-browser": "4.2.5",
"@angular/platform-browser-dynamic": "4.2.5", "@angular/platform-browser-dynamic": "4.2.5",
"@angular/router": "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", "alfresco-js-api": "~1.6.1",
"core-js": "2.4.1", "core-js": "2.4.1",
"hammerjs": "2.0.8", "hammerjs": "2.0.8",
"minimatch": "3.0.4",
"ng2-alfresco-core": "1.6.1", "ng2-alfresco-core": "1.6.1",
"@ngx-translate/core": "7.0.0",
"reflect-metadata": "0.1.10", "reflect-metadata": "0.1.10",
"rxjs": "5.1.0", "rxjs": "5.1.0",
"systemjs": "0.19.27", "systemjs": "0.19.27",

View File

@@ -31,7 +31,10 @@ describe('UploadService', () => {
imports: [ imports: [
CoreModule.forRoot(), CoreModule.forRoot(),
AppConfigModule.forRoot('app.config.json', { AppConfigModule.forRoot('app.config.json', {
ecmHost: 'http://localhost:9876/ecm' ecmHost: 'http://localhost:9876/ecm',
files: {
excluded: ['.DS_Store', 'desktop.ini', '.git', '*.git']
}
}) })
], ],
providers: [ providers: [
@@ -82,7 +85,7 @@ describe('UploadService', () => {
}); });
let fileFake = new FileModel( let fileFake = new FileModel(
<File>{ name: 'fake-name', size: 10 }, <File>{ name: 'fake-name', size: 10 },
<FileUploadOptions> { parentId: '-root-', path: 'fake-dir' } <FileUploadOptions>{ parentId: '-root-', path: 'fake-dir' }
); );
service.addToQueue(fileFake); service.addToQueue(fileFake);
service.uploadFilesInTheQueue(emitter); service.uploadFilesInTheQueue(emitter);
@@ -107,7 +110,7 @@ describe('UploadService', () => {
}); });
let fileFake = new FileModel( let fileFake = new FileModel(
<File>{ name: 'fake-name', size: 10 }, <File>{ name: 'fake-name', size: 10 },
<FileUploadOptions> { parentId: '-root-' } <FileUploadOptions>{ parentId: '-root-' }
); );
service.addToQueue(fileFake); service.addToQueue(fileFake);
service.uploadFilesInTheQueue(emitter); service.uploadFilesInTheQueue(emitter);
@@ -193,4 +196,15 @@ describe('UploadService', () => {
let file = service.getQueue(); let file = service.getQueue();
service.cancelUpload(...file); 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);
});
}); });

View File

@@ -17,9 +17,10 @@
import { EventEmitter, Injectable } from '@angular/core'; import { EventEmitter, Injectable } from '@angular/core';
import { Subject } from 'rxjs/Rx'; 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 { FileUploadEvent, FileUploadCompleteEvent } from '../events/file.event';
import { FileModel, FileUploadProgress, FileUploadStatus } from '../models/file.model'; import { FileModel, FileUploadProgress, FileUploadStatus } from '../models/file.model';
import * as minimatch from 'minimatch';
@Injectable() @Injectable()
export class UploadService { export class UploadService {
@@ -29,6 +30,7 @@ export class UploadService {
private totalComplete: number = 0; private totalComplete: number = 0;
private totalAborted: number = 0; private totalAborted: number = 0;
private activeTask: Promise<any> = null; private activeTask: Promise<any> = null;
private excludedFileList: String[] = [];
queueChanged: Subject<FileModel[]> = new Subject<FileModel[]>(); queueChanged: Subject<FileModel[]> = new Subject<FileModel[]>();
fileUpload: Subject<FileUploadEvent> = new Subject<FileUploadEvent>(); fileUpload: Subject<FileUploadEvent> = new Subject<FileUploadEvent>();
@@ -39,7 +41,8 @@ export class UploadService {
fileUploadError: Subject<FileUploadEvent> = new Subject<FileUploadEvent>(); fileUploadError: Subject<FileUploadEvent> = new Subject<FileUploadEvent>();
fileUploadComplete: Subject<FileUploadCompleteEvent> = new Subject<FileUploadCompleteEvent>(); fileUploadComplete: Subject<FileUploadCompleteEvent> = new Subject<FileUploadCompleteEvent>();
constructor(private apiService: AlfrescoApiService) { constructor(private apiService: AlfrescoApiService, private appConfigService: AppConfigService) {
this.excludedFileList = <String[]>this.appConfigService.get('files.excluded');
} }
/** /**
@@ -71,12 +74,20 @@ export class UploadService {
* addToQueue(...[file1, file2, file3]); // pass an array of files * addToQueue(...[file1, file2, file3]); // pass an array of files
*/ */
addToQueue(...files: FileModel[]): FileModel[] { 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.queue = this.queue.concat(allowedFiles);
this.queueChanged.next(this.queue); this.queueChanged.next(this.queue);
return allowedFiles; 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. * 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>): any { private beginUpload(file: FileModel, /* @deprecated */emitter: EventEmitter<any>): any {
let opts: any = { let opts: any = {
renditions: 'doclib' renditions: 'doclib'
}; };
if (file.options.newVersion === true) { if (file.options.newVersion === true) {
opts.overwrite = true; opts.overwrite = true;
@@ -167,7 +178,6 @@ export class UploadService {
.catch(err => { .catch(err => {
this.onUploadError(file, err); this.onUploadError(file, err);
}); });
return promise; return promise;
} }