diff --git a/lib/core/services/upload.service.spec.ts b/lib/core/services/upload.service.spec.ts index 4614045c9e..6a33c082de 100644 --- a/lib/core/services/upload.service.spec.ts +++ b/lib/core/services/upload.service.spec.ts @@ -216,6 +216,50 @@ describe('UploadService', () => { }); }); + it('should delete node\'s version when cancelling the upload of the new file version', (done) => { + const emitter = new EventEmitter(); + + const emitterDisposable = emitter.subscribe((event) => { + expect(event.value).toEqual('File deleted'); + emitterDisposable.unsubscribe(); + + const deleteRequest = jasmine.Ajax.requests.mostRecent(); + expect(deleteRequest.url).toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/myNodeId/versions/1.1'); + expect(deleteRequest.method).toBe('DELETE'); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 200, + contentType: 'text/plain', + responseText: 'File deleted' + }); + done(); + }); + + const fileFake = new FileModel( {name: 'fake-name', size: 10}, null, 'fakeId'); + service.addToQueue(fileFake); + service.uploadFilesInTheQueue(emitter); + + const file = service.getQueue(); + service.cancelUpload(...file); + + const request = jasmine.Ajax.requests.mostRecent(); + expect(request.url).toBe('http://localhost:9876/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/fakeId/content?include=allowableOperations'); + expect(request.method).toBe('PUT'); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 200, + contentType: 'json', + responseText: { + entry: { + id: 'myNodeId', + properties: { + 'cm:versionLabel': '1.1' + } + } + } + }); + }); + it('If newVersion is set, name should be a param', () => { const uploadFileSpy = spyOn(alfrescoApiService.getInstance().upload, 'uploadFile').and.callThrough(); diff --git a/lib/core/services/upload.service.ts b/lib/core/services/upload.service.ts index db76da0643..4619eed88b 100644 --- a/lib/core/services/upload.service.ts +++ b/lib/core/services/upload.service.ts @@ -275,7 +275,11 @@ export class UploadService { .on('success', (data) => { if (this.abortedFile === file.name) { this.onUploadAborted(file); - this.deleteAbortedNode(data.entry.id); + if (file.id === undefined) { + this.deleteAbortedNode(data.entry.id); + } else { + this.deleteAbortedNodeVersion(data.entry.id, data.entry.properties['cm:versionLabel']); + } if (emitter) { emitter.emit({ value: 'File deleted' }); } @@ -405,6 +409,13 @@ export class UploadService { .then(() => (this.abortedFile = undefined)); } + private deleteAbortedNodeVersion(nodeId: string, versionId: string) { + this.apiService + .getInstance() + .core.versionsApi.deleteVersion(nodeId, versionId) + .then(() => (this.abortedFile = undefined)); + } + private isSaveToAbortFile(file: FileModel): boolean { return ( file.size > MIN_CANCELLABLE_FILE_SIZE &&