[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
This commit is contained in:
Vito
2021-10-29 17:29:11 +01:00
committed by GitHub
parent 7481001461
commit 622383acf8
2 changed files with 35 additions and 4 deletions

View File

@@ -77,14 +77,20 @@ export class AttachFileWidgetDialogService {
downloadURL(repository: AlfrescoEndpointRepresentation, sourceId: string): Observable<string> { downloadURL(repository: AlfrescoEndpointRepresentation, sourceId: string): Observable<string> {
const { accountIdentifier } = this.constructPayload(repository); const { accountIdentifier } = this.constructPayload(repository);
const contentApi = new ContentApi(this.externalApis[accountIdentifier].getInstance());
if (this.externalApis[accountIdentifier]?.getInstance()?.isLoggedIn()) { if (this.externalApis[accountIdentifier]?.getInstance()) {
return of(contentApi.getContentUrl(sourceId)); const contentApi = new ContentApi(this.externalApis[accountIdentifier].getInstance());
if (this.externalApis[accountIdentifier].getInstance().isLoggedIn()) {
return of(contentApi.getContentUrl(sourceId));
}
} }
return this.showExternalHostLoginDialog(repository).pipe( return this.showExternalHostLoginDialog(repository).pipe(
switchMap(() => of(contentApi.getContentUrl(sourceId))) switchMap(() => {
const contentApi = new ContentApi(this.externalApis[accountIdentifier].getInstance());
return of(contentApi.getContentUrl(sourceId));
})
); );
} }

View File

@@ -600,4 +600,29 @@ describe('AttachFileWidgetComponent', () => {
expect(element.querySelector('#file-1155-icon')).not.toBeNull(); 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 = <FormFieldMetadata> 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<HTMLButtonElement>('#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');
});
}); });