From 268cf7af21dae0327cc5ef3554034b805db8dab4 Mon Sep 17 00:00:00 2001 From: arditdomi <32884230+arditdomi@users.noreply.github.com> Date: Thu, 13 Aug 2020 09:01:20 +0100 Subject: [PATCH] [AAE-3204] Fix destinationFolder breadcrumb restriction not working (#5984) * [AAE-3204] Fix destinationFolder breadcrumb restriction not working * Remove not needed if-else statement * Fix comments * Fix type definition error while bulding * Fix unit tests --- ...attach-file-cloud-widget.component.spec.ts | 66 +------------------ .../attach-file-cloud-widget.component.ts | 11 +--- .../content-cloud-node-selector.service.ts | 12 ++-- 3 files changed, 11 insertions(+), 78 deletions(-) diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts index 69515d3a56..5e2c704f54 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts @@ -102,22 +102,6 @@ describe('AttachFileCloudWidgetComponent', () => { } }; - const allSourceWithMyFilesParams = { - fileSource: { - name: 'all file sources', - serviceId: 'all-file-sources', - destinationFolderPath: '-my-' - } - }; - - const allSourceWithShareParams = { - fileSource: { - name: 'all file sources', - serviceId: 'all-file-sources', - destinationFolderPath: '-shared-' - } - }; - const allSourceWithWrongAliasParams = { fileSource: { name: 'all file sources', @@ -309,16 +293,14 @@ describe('AttachFileCloudWidgetComponent', () => { }); describe('destinationFolderPath', () => { - - let fetchNodeIdFromRelativePathSpy: jasmine.Spy; let openUploadFileDialogSpy: jasmine.Spy; beforeEach(async(() => { - fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId); openUploadFileDialogSpy = spyOn(contentCloudNodeSelectorService, 'openUploadFileDialog').and.returnValue(of([fakeMinimalNode])); })); - it('should be able to fetch nodeId if destinationFolderPtah defined ', async() => { + it('should be able to fetch nodeId if destinationFolderPath is defined', async() => { + const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId); widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] @@ -342,7 +324,7 @@ describe('AttachFileCloudWidgetComponent', () => { expect(widget.rootNodeId).toEqual('mock-node-id'); }); - it('Should be able to set given alias as rootNodeId if destinationFolderPath contains only alias i.e -root-', async() => { + it('Should be able to set given alias as rootNodeId if the nodeId of the alias is not fetched from the api', async() => { widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] @@ -363,48 +345,6 @@ describe('AttachFileCloudWidgetComponent', () => { expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-root-', 'single', true); }); - it('Should be able to set given alias as rootNodeId if destinationFolderPath contains only alias i.e -my-', async() => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = allSourceWithMyFilesParams; - fixture.detectChanges(); - await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); - await fixture.whenStable(); - fixture.detectChanges(); - - expect(widget.rootNodeId).toEqual('-my-'); - expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'single', true); - }); - - it('Should be able to set given alias as rootNodeId if destinationFolderPath contains only alias i.e -shared-', async() => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = allSourceWithShareParams; - fixture.detectChanges(); - await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); - await fixture.whenStable(); - fixture.detectChanges(); - - expect(widget.rootNodeId).toEqual('-shared-'); - expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-shared-', 'single', true); - }); - it('Should be able to set default alias as rootNodeId if destinationFolderPath contains wrong alias', async() => { widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts index 504a862919..24e70b3135 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts @@ -90,15 +90,10 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i if (this.isAlfrescoAndLocal()) { const destinationFolderPath = this.getAliasAndRelativePathFromDestinationFolderPath(this.field.params.fileSource.destinationFolderPath); + const opts = { relativePath: destinationFolderPath.path }; - if (destinationFolderPath.path) { - const opts = { relativePath: destinationFolderPath.path }; - await this.contentNodeSelectorService.fetchNodeIdFromRelativePath(destinationFolderPath.alias, opts).then((nodeId: string) => { - this.rootNodeId = nodeId ? nodeId : destinationFolderPath.alias; - }); - } else { - this.rootNodeId = destinationFolderPath.alias; - } + const nodeId = await this.contentNodeSelectorService.fetchNodeIdFromRelativePath(destinationFolderPath.alias, opts); + this.rootNodeId = nodeId ? nodeId : destinationFolderPath.alias; } this.contentNodeSelectorService diff --git a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts index 45713d6c72..0ba86c3332 100644 --- a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts @@ -54,13 +54,11 @@ export class ContentCloudNodeSelectorService { } async fetchNodeIdFromRelativePath(alias: string, opts: { relativePath: string }): Promise { - let nodeId = ''; - await this.apiService.getInstance().node.getNode(alias, opts).then(node => { - nodeId = node.entry.id; - }).catch((err) => { - this.handleError(err); - }); - return nodeId; + const nodeEntry: any = await this.apiService.getInstance().node + .getNode(alias, opts) + .catch((err) => this.handleError(err)); + + return nodeEntry?.entry?.id; } private openContentNodeDialog(data: ContentNodeSelectorComponentData, currentPanelClass: string, chosenWidth: string) {