diff --git a/src/app/item-page/full/field-components/file-section/full-file-section.component.html b/src/app/item-page/full/field-components/file-section/full-file-section.component.html index 50d84fe22df..463ef32aedf 100644 --- a/src/app/item-page/full/field-components/file-section/full-file-section.component.html +++ b/src/app/item-page/full/field-components/file-section/full-file-section.component.html @@ -34,8 +34,8 @@
{{"item.page.filesection.original.bundle"
- - {{"item.page.filesection.download" | translate}} + + {{"item.page.filesection.download" | translate}}
diff --git a/src/app/item-page/full/field-components/file-section/full-file-section.component.spec.ts b/src/app/item-page/full/field-components/file-section/full-file-section.component.spec.ts index b2e956efafb..37e75d30aa0 100644 --- a/src/app/item-page/full/field-components/file-section/full-file-section.component.spec.ts +++ b/src/app/item-page/full/field-components/file-section/full-file-section.component.spec.ts @@ -22,6 +22,7 @@ import { APP_CONFIG } from 'src/config/app-config.interface'; import { environment } from 'src/environments/environment'; import { UUIDService } from '../../../../core/shared/uuid.service'; import { getMockUUIDService } from '../../../../shared/mocks/uuid.service.mock'; +import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service'; describe('FullFileSectionComponent', () => { let comp: FullFileSectionComponent; @@ -58,6 +59,10 @@ describe('FullFileSectionComponent', () => { findAllByItemAndBundleName: createSuccessfulRemoteDataObject$(createPaginatedList([mockBitstream, mockBitstream, mockBitstream])) }); + const authorizedDataService = jasmine.createSpyObj('authorizedDataService',{ + isAuthorized: observableOf(false), + }); + const paginationService = new PaginationServiceStub(); beforeEach(waitForAsync(() => { @@ -75,7 +80,8 @@ describe('FullFileSectionComponent', () => { { provide: NotificationsService, useValue: new NotificationsServiceStub() }, { provide: PaginationService, useValue: paginationService }, { provide: APP_CONFIG, useValue: environment }, - { provide: UUIDService, useValue: getMockUUIDService() } + { provide: UUIDService, useValue: getMockUUIDService() }, + { provide: AuthorizationDataService, useValue: authorizedDataService }, ], schemas: [NO_ERRORS_SCHEMA] @@ -98,5 +104,14 @@ describe('FullFileSectionComponent', () => { const fileNameElement = fixture.debugElement.query(By.css('[data-test="file-name"]')).nativeElement; expect(fileNameElement.classList).toContain('text-break'); }); + + it('canDownload should return an observable with false value, if user is not authorized to download bitstream', waitForAsync(() => { + authorizedDataService.isAuthorized.and.returnValue(observableOf(false)); + comp.canDownload(mockBitstream).subscribe(canDownload => expect(canDownload).toBeFalse()); + })); + it('canDownload should return an observable with true value, if user is authorized to download bitstream', waitForAsync(() => { + authorizedDataService.isAuthorized.and.returnValue(observableOf(true)); + comp.canDownload(mockBitstream).subscribe(canDownload => expect(canDownload).toBeTrue()); + })); }); }); diff --git a/src/app/item-page/full/field-components/file-section/full-file-section.component.ts b/src/app/item-page/full/field-components/file-section/full-file-section.component.ts index 6b66b48a8c6..6590f340e40 100644 --- a/src/app/item-page/full/field-components/file-section/full-file-section.component.ts +++ b/src/app/item-page/full/field-components/file-section/full-file-section.component.ts @@ -17,6 +17,8 @@ import { PaginationService } from '../../../../core/pagination/pagination.servic import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service'; import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface'; import { UUIDService } from '../../../../core/shared/uuid.service'; +import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service'; +import { FeatureID } from '../../../../core/data/feature-authorization/feature-id'; /** * This component renders the file section of the item @@ -56,6 +58,7 @@ export class FullFileSectionComponent extends FileSectionComponent implements On protected paginationService: PaginationService, public dsoNameService: DSONameService, protected uuidService: UUIDService, + public authorizationService: AuthorizationDataService, @Inject(APP_CONFIG) protected appConfig: AppConfig ) { super(bitstreamDataService, notificationsService, translateService, dsoNameService, appConfig); @@ -112,6 +115,10 @@ export class FullFileSectionComponent extends FileSectionComponent implements On return bitstream?.allMetadataValues('bitstream.viewer.provider').includes('nodownload'); } + canDownload(file: Bitstream): Observable { + return this.authorizationService.isAuthorized(FeatureID.CanDownload, file.self); + } + ngOnDestroy(): void { this.paginationService.clearPagination(this.originalOptions.id); this.paginationService.clearPagination(this.licenseOptions.id); diff --git a/src/app/shared/file-download-link/themed-file-download-link.component.ts b/src/app/shared/file-download-link/themed-file-download-link.component.ts index 4e619b8f28e..989144154d4 100644 --- a/src/app/shared/file-download-link/themed-file-download-link.component.ts +++ b/src/app/shared/file-download-link/themed-file-download-link.component.ts @@ -21,7 +21,9 @@ export class ThemedFileDownloadLinkComponent extends ThemedComponent