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 262450d1bb..c6c85ea4c1 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 @@ -27,7 +27,8 @@ import { FormFieldTypes, FormFieldMetadata, FormService, - DownloadService + DownloadService, + AppConfigService } from '@alfresco/adf-core'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; @@ -43,6 +44,7 @@ describe('AttachFileCloudWidgetComponent', () => { let fixture: ComponentFixture; let element: HTMLInputElement; let contentCloudNodeSelectorService: ContentCloudNodeSelectorService; + let appConfigService: AppConfigService; let processCloudContentService: ProcessCloudContentService; let formService: FormService; let downloadService: DownloadService; @@ -173,6 +175,9 @@ describe('AttachFileCloudWidgetComponent', () => { contentCloudNodeSelectorService = TestBed.inject( ContentCloudNodeSelectorService ); + appConfigService = TestBed.inject( + AppConfigService + ); formService = TestBed.inject(FormService); })); @@ -389,6 +394,21 @@ describe('AttachFileCloudWidgetComponent', () => { expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-root-', 'multiple', true); }); + it('should return the application name in case -appname- placeholder is present', async() => { + appConfigService.config = Object.assign(appConfigService.config, { + 'alfresco-deployed-apps': [ + { + 'name': 'fakeapp' + } + ] + }); + expect(widget.replaceAppNameAliasWithValue('/myfiles/-appname-/folder')).toBe('/myfiles/fakeapp/folder'); + }); + + it('should return the same value in case -appname- placeholder is NOT present', async() => { + expect(widget.replaceAppNameAliasWithValue('/myfiles/fakepath/folder')).toBe('/myfiles/fakepath/folder'); + }); + describe('FilesSource', () => { it('should be able to set myFiles folderId as rootNodeId if fileSource set only to content', async () => { 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 24e70b3135..61d0cf368e 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 @@ -24,7 +24,8 @@ import { ThumbnailService, NotificationService, FormValues, - ContentLinkModel + ContentLinkModel, + AppConfigService } from '@alfresco/adf-core'; import { Node, RelatedContentRepresentation } from '@alfresco/js-api'; import { ContentCloudNodeSelectorService } from '../../../services/content-cloud-node-selector.service'; @@ -53,6 +54,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i static MY_FILES_FOLDER_ID = '-my-'; static ROOT_FOLDER_ID = '-root-'; + static APP_NAME = '-appname-'; static VALID_ALIAS = [AttachFileCloudWidgetComponent.ROOT_FOLDER_ID, AttachFileCloudWidgetComponent.MY_FILES_FOLDER_ID, '-shared-']; typeId = 'AttachFileCloudWidgetComponent'; @@ -64,7 +66,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i thumbnails: ThumbnailService, processCloudContentService: ProcessCloudContentService, notificationService: NotificationService, - private contentNodeSelectorService: ContentCloudNodeSelectorService + private contentNodeSelectorService: ContentCloudNodeSelectorService, + private appConfigService: AppConfigService ) { super(formService, thumbnails, processCloudContentService, notificationService, logger); } @@ -85,6 +88,18 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i this.removeFile(file); } + fetchAppNameFromAppConfig(): string { + return this.appConfigService.get('alfresco-deployed-apps')[0]?.name; + } + + replaceAppNameAliasWithValue(path: string): string { + if (path?.match(AttachFileCloudWidgetComponent.APP_NAME)) { + const appName = this.fetchAppNameFromAppConfig(); + return path.replace(AttachFileCloudWidgetComponent.APP_NAME, appName); + } + return path; + } + async openSelectDialog() { const selectedMode = this.field.params.multiple ? 'multiple' : 'single'; @@ -92,6 +107,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i const destinationFolderPath = this.getAliasAndRelativePathFromDestinationFolderPath(this.field.params.fileSource.destinationFolderPath); const opts = { relativePath: destinationFolderPath.path }; + destinationFolderPath.path = this.replaceAppNameAliasWithValue(destinationFolderPath.path); const nodeId = await this.contentNodeSelectorService.fetchNodeIdFromRelativePath(destinationFolderPath.alias, opts); this.rootNodeId = nodeId ? nodeId : destinationFolderPath.alias; }