mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1653] [ADF-1651] - disabled download for external source and added download for same login content (#5450)
* ADF-1653 - disabled download for external content * ADF-1653 - ADF-1651 - disabled download for external source and added download for same login content * ADF-1653 - using downloadService instead of contentService * improve solution * improve solution * fix unit * add more unti test * fix lint Co-authored-by: Eugenio Romano <eromano@users.noreply.github.com>
This commit is contained in:
@@ -76,12 +76,13 @@
|
||||
</button>
|
||||
<mat-menu #fileActionMenu="matMenu" xPosition="before">
|
||||
<button id="{{'file-'+file.id+'-show-file'}}"
|
||||
[disabled]="file.isExternal"
|
||||
[disabled]="file.isExternal || !file.contentAvailable"
|
||||
mat-menu-item (click)="onAttachFileClicked(file)">
|
||||
<mat-icon>image</mat-icon>
|
||||
<span>{{ 'FORM.FIELD.SHOW_FILE' | translate }}</span>
|
||||
</button>
|
||||
<button id="{{'file-'+file.id+'-download-file'}}"
|
||||
[disabled]="file.isExternal"
|
||||
mat-menu-item (click)="downloadContent(file)">
|
||||
<mat-icon>file_download</mat-icon>
|
||||
<span>{{ 'FORM.FIELD.DOWNLOAD_FILE' | translate }}</span>
|
||||
|
@@ -25,12 +25,13 @@ import {
|
||||
ThumbnailService,
|
||||
ProcessContentService,
|
||||
ActivitiContentService,
|
||||
ContentService,
|
||||
AppConfigValues,
|
||||
AppConfigService
|
||||
AppConfigService,
|
||||
DownloadService,
|
||||
ContentService
|
||||
} from '@alfresco/adf-core';
|
||||
import { ContentNodeDialogService } from '@alfresco/adf-content-services';
|
||||
import { Node, RelatedContentRepresentation } from '@alfresco/js-api';
|
||||
import { Node, RelatedContentRepresentation, NodeChildAssociation } from '@alfresco/js-api';
|
||||
import { from, zip, of, Subject } from 'rxjs';
|
||||
import { mergeMap, takeUntil } from 'rxjs/operators';
|
||||
import { AttachFileWidgetDialogService } from './attach-file-widget-dialog.service';
|
||||
@@ -66,6 +67,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
|
||||
private contentService: ContentService,
|
||||
private contentDialog: ContentNodeDialogService,
|
||||
private appConfigService: AppConfigService,
|
||||
private downloadService: DownloadService,
|
||||
private attachDialogService: AttachFileWidgetDialogService) {
|
||||
super(formService, logger, thumbnails, processContentService);
|
||||
}
|
||||
@@ -131,6 +133,10 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
|
||||
return this.tempFilesList.findIndex((elem) => elem.name === file.name) >= 0;
|
||||
}
|
||||
|
||||
getNodeFromTempFile(file): NodeChildAssociation {
|
||||
return this.tempFilesList.find((elem) => elem.name === file.name);
|
||||
}
|
||||
|
||||
openSelectDialogFromFileSource() {
|
||||
const params = this.field.params;
|
||||
if (this.isDefinedSourceFolder()) {
|
||||
@@ -157,7 +163,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
|
||||
}
|
||||
|
||||
onAttachFileClicked(file: any) {
|
||||
if (file.isExternal) {
|
||||
if (file.isExternal || !file.contentAvailable) {
|
||||
this.logger.info(`The file ${file.name} comes from an external source and cannot be showed at this moment`);
|
||||
return;
|
||||
}
|
||||
@@ -170,11 +176,22 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
|
||||
|
||||
downloadContent(file: any | RelatedContentRepresentation): void {
|
||||
if (this.isTemporaryFile(file)) {
|
||||
this.contentService.downloadBlob((<RelatedContentRepresentation> file).contentBlob, file.name);
|
||||
const fileBlob = (<RelatedContentRepresentation> file).contentBlob;
|
||||
if (fileBlob) {
|
||||
this.downloadService.downloadBlob(fileBlob, file.name);
|
||||
} else {
|
||||
const nodeUploaded: NodeChildAssociation = this.getNodeFromTempFile(file);
|
||||
const nodeUrl = this.contentService.getContentUrl(nodeUploaded.id);
|
||||
this.downloadService.downloadUrl(nodeUrl, file.name);
|
||||
}
|
||||
}
|
||||
if (file.sourceId) {
|
||||
const nodeUrl = this.contentService.getContentUrl(file.sourceId);
|
||||
this.downloadService.downloadUrl(nodeUrl, file.name);
|
||||
} else {
|
||||
this.processContentService.getFileRawContent((<any> file).id).subscribe(
|
||||
(blob: Blob) => {
|
||||
this.contentService.downloadBlob(blob, (<any> file).name);
|
||||
this.downloadService.downloadBlob(blob, (<any> file).name);
|
||||
},
|
||||
() => {
|
||||
this.logger.error('Impossible retrieve content for download');
|
||||
@@ -225,8 +242,8 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements
|
||||
},
|
||||
() => {
|
||||
const previousFiles = this.field.value ? this.field.value : [];
|
||||
this.field.value = [ ...previousFiles, ...filesSaved ];
|
||||
this.field.json.value = [ ...previousFiles, ...filesSaved ];
|
||||
this.field.value = [...previousFiles, ...filesSaved];
|
||||
this.field.json.value = [...previousFiles, ...filesSaved];
|
||||
this.hasFile = true;
|
||||
});
|
||||
}
|
||||
|
@@ -26,8 +26,8 @@ import {
|
||||
ProcessContentService,
|
||||
ActivitiContentService,
|
||||
FormFieldMetadata,
|
||||
ContentService,
|
||||
setupTestBed
|
||||
setupTestBed,
|
||||
DownloadService
|
||||
} from '@alfresco/adf-core';
|
||||
import { ContentNodeDialogService, ContentModule } from '@alfresco/adf-content-services';
|
||||
import { of } from 'rxjs';
|
||||
@@ -40,30 +40,30 @@ const fakeRepositoryListAnswer = [
|
||||
'serviceId': 'alfresco-9999-SHAREME',
|
||||
'metaDataAllowed': true,
|
||||
'name': 'SHAREME',
|
||||
'repositoryUrl' : 'http://localhost:0000/SHAREME'
|
||||
'repositoryUrl': 'http://localhost:0000/SHAREME'
|
||||
},
|
||||
{
|
||||
'authorized': true,
|
||||
'serviceId': 'alfresco-0000-GOKUSHARE',
|
||||
'metaDataAllowed': true,
|
||||
'name': 'GOKUSHARE',
|
||||
'repositoryUrl' : 'http://localhost:0000/GOKUSHARE'
|
||||
'repositoryUrl': 'http://localhost:0000/GOKUSHARE'
|
||||
}];
|
||||
|
||||
const onlyLocalParams = {
|
||||
fileSource : {
|
||||
fileSource: {
|
||||
serviceId: 'local-file'
|
||||
}
|
||||
};
|
||||
|
||||
const allSourceParams = {
|
||||
fileSource : {
|
||||
fileSource: {
|
||||
serviceId: 'all-file-sources'
|
||||
}
|
||||
};
|
||||
|
||||
const definedSourceParams = {
|
||||
fileSource : {
|
||||
fileSource: {
|
||||
serviceId: 'goku-sources',
|
||||
name: 'pippo-baudo',
|
||||
selectedFolder: {
|
||||
@@ -84,10 +84,11 @@ const fakePngUpload = {
|
||||
'id': 1166,
|
||||
'name': 'fake-png.png',
|
||||
'created': '2017-07-25T17:17:37.099Z',
|
||||
'createdBy': {'id': 1001, 'firstName': 'Admin', 'lastName': 'admin', 'email': 'admin'},
|
||||
'createdBy': { 'id': 1001, 'firstName': 'Admin', 'lastName': 'admin', 'email': 'admin' },
|
||||
'relatedContent': false,
|
||||
'contentAvailable': true,
|
||||
'link': false,
|
||||
'isExternal': false,
|
||||
'mimeType': 'image/png',
|
||||
'simpleType': 'image',
|
||||
'previewStatus': 'queued',
|
||||
@@ -98,9 +99,10 @@ const fakePngAnswer = {
|
||||
'id': 1155,
|
||||
'name': 'a_png_file.png',
|
||||
'created': '2017-07-25T17:17:37.099Z',
|
||||
'createdBy': {'id': 1001, 'firstName': 'Admin', 'lastName': 'admin', 'email': 'admin'},
|
||||
'createdBy': { 'id': 1001, 'firstName': 'Admin', 'lastName': 'admin', 'email': 'admin' },
|
||||
'relatedContent': false,
|
||||
'contentAvailable': true,
|
||||
'isExternal': false,
|
||||
'link': false,
|
||||
'mimeType': 'image/png',
|
||||
'simpleType': 'image',
|
||||
@@ -116,7 +118,7 @@ describe('AttachFileWidgetComponent', () => {
|
||||
let activitiContentService: ActivitiContentService;
|
||||
let contentNodeDialogService: ContentNodeDialogService;
|
||||
let processContentService: ProcessContentService;
|
||||
let contentService: ContentService;
|
||||
let downloadService: DownloadService;
|
||||
let formService: FormService;
|
||||
|
||||
setupTestBed({
|
||||
@@ -133,7 +135,7 @@ describe('AttachFileWidgetComponent', () => {
|
||||
activitiContentService = TestBed.get(ActivitiContentService);
|
||||
contentNodeDialogService = TestBed.get(ContentNodeDialogService);
|
||||
processContentService = TestBed.get(ProcessContentService);
|
||||
contentService = TestBed.get(ContentService);
|
||||
downloadService = TestBed.get(DownloadService);
|
||||
formService = TestBed.get(FormService);
|
||||
}));
|
||||
|
||||
@@ -310,7 +312,7 @@ describe('AttachFileWidgetComponent', () => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const inputDebugElement = fixture.debugElement.query(By.css('#attach-file-attach'));
|
||||
inputDebugElement.triggerEventHandler('change', {target: {files: [fakePngAnswer]}});
|
||||
inputDebugElement.triggerEventHandler('change', { target: { files: [fakePngAnswer] } });
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('#file-1155-icon')).not.toBeNull();
|
||||
});
|
||||
@@ -342,7 +344,7 @@ describe('AttachFileWidgetComponent', () => {
|
||||
}));
|
||||
|
||||
it('should download file when download is clicked', async(() => {
|
||||
spyOn(contentService, 'downloadBlob').and.stub();
|
||||
spyOn(downloadService, 'downloadBlob').and.stub();
|
||||
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
|
||||
expect(menuButton).not.toBeNull();
|
||||
menuButton.click();
|
||||
@@ -350,7 +352,7 @@ describe('AttachFileWidgetComponent', () => {
|
||||
const downloadOption: HTMLButtonElement = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-download-file')).nativeElement;
|
||||
downloadOption.click();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(contentService.downloadBlob).toHaveBeenCalled();
|
||||
expect(downloadService.downloadBlob).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -368,6 +370,55 @@ describe('AttachFileWidgetComponent', () => {
|
||||
showOption.click();
|
||||
}));
|
||||
|
||||
it('should not display the show button file when is an external file', async(() => {
|
||||
fakePngAnswer.isExternal = true;
|
||||
spyOn(processContentService, 'getFileRawContent').and.returnValue(of(fakePngAnswer));
|
||||
|
||||
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
|
||||
expect(menuButton).not.toBeNull();
|
||||
menuButton.click();
|
||||
fixture.detectChanges();
|
||||
const showOption: HTMLButtonElement = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-show-file')).nativeElement;
|
||||
expect(showOption.disabled).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should not display the download button file when is an external file', async(() => {
|
||||
fakePngAnswer.isExternal = true;
|
||||
spyOn(processContentService, 'getFileRawContent').and.returnValue(of(fakePngAnswer));
|
||||
|
||||
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
|
||||
expect(menuButton).not.toBeNull();
|
||||
menuButton.click();
|
||||
fixture.detectChanges();
|
||||
const downloadOption: HTMLButtonElement = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-download-file')).nativeElement;
|
||||
expect(downloadOption.disabled).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should display the download button file when is an internal file', async(() => {
|
||||
fakePngAnswer.isExternal = false;
|
||||
spyOn(processContentService, 'getFileRawContent').and.returnValue(of(fakePngAnswer));
|
||||
|
||||
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
|
||||
expect(menuButton).not.toBeNull();
|
||||
menuButton.click();
|
||||
fixture.detectChanges();
|
||||
const downloadOption: HTMLButtonElement = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-download-file')).nativeElement;
|
||||
expect(downloadOption.disabled).toBeFalsy();
|
||||
|
||||
}));
|
||||
|
||||
it('should not display the show button file when there is no contentAvailable', async(() => {
|
||||
fakePngAnswer.contentAvailable = false;
|
||||
spyOn(processContentService, 'getFileRawContent').and.returnValue(of(fakePngAnswer));
|
||||
|
||||
const menuButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#file-1155-option-menu');
|
||||
expect(menuButton).not.toBeNull();
|
||||
menuButton.click();
|
||||
fixture.detectChanges();
|
||||
const showOption: HTMLButtonElement = <HTMLButtonElement> fixture.debugElement.query(By.css('#file-1155-show-file')).nativeElement;
|
||||
expect(showOption.disabled).toBeTruthy();
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user