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 7a189a9c86d..ddeb0f871af 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 63938a6347b..b2d3f3a6b44 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'); + }); });