From 622383acf8d7791e982d2594939df3874f913ec4 Mon Sep 17 00:00:00 2001 From: Vito Date: Fri, 29 Oct 2021 17:29:11 +0100 Subject: [PATCH] [ACA-3847] - fixed download for external source file (#7254) * [AAE-3847] - added test for check login on external upload * [ACA-3847] - fixed logout/login scenario for external linked file * [ACA-3847] - fixed lint problems --- .../attach-file-widget-dialog.service.ts | 14 ++++++++--- .../attach-file-widget.component.spec.ts | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts index 7a189a9c86..ddeb0f871a 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts @@ -77,14 +77,20 @@ export class AttachFileWidgetDialogService { downloadURL(repository: AlfrescoEndpointRepresentation, sourceId: string): Observable { const { accountIdentifier } = this.constructPayload(repository); - const contentApi = new ContentApi(this.externalApis[accountIdentifier].getInstance()); - if (this.externalApis[accountIdentifier]?.getInstance()?.isLoggedIn()) { - return of(contentApi.getContentUrl(sourceId)); + if (this.externalApis[accountIdentifier]?.getInstance()) { + const contentApi = new ContentApi(this.externalApis[accountIdentifier].getInstance()); + + if (this.externalApis[accountIdentifier].getInstance().isLoggedIn()) { + return of(contentApi.getContentUrl(sourceId)); + } } return this.showExternalHostLoginDialog(repository).pipe( - switchMap(() => of(contentApi.getContentUrl(sourceId))) + switchMap(() => { + const contentApi = new ContentApi(this.externalApis[accountIdentifier].getInstance()); + return of(contentApi.getContentUrl(sourceId)); + }) ); } diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts b/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts index 63938a6347..b2d3f3a6b4 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts @@ -600,4 +600,29 @@ describe('AttachFileWidgetComponent', () => { expect(element.querySelector('#file-1155-icon')).not.toBeNull(); }); + + it('should pass a valid repository id to open the external login', async () => { + widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] }); + widget.field.id = 'attach-external-file-attach'; + widget.field.params = externalDefinedSourceParams; + spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer)); + spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(of(fakePngAnswer)); + const openLoginSpy = spyOn(attachFileWidgetDialogService, 'openLogin').and.returnValue(of([fakeMinimalNode])); + + fixture.detectChanges(); + await fixture.whenStable(); + + const attachButton = element.querySelector('#attach-external-file-attach'); + attachButton.click(); + + fixture.detectChanges(); + await fixture.whenStable(); + + fixture.debugElement.query(By.css('#attach-external')).nativeElement.click(); + + fixture.detectChanges(); + await fixture.whenStable(); + + expect(openLoginSpy).toHaveBeenCalledWith(fakeRepositoryListAnswer[2], undefined, 'alfresco-2000-external'); + }); });