From 663719490656df07bb410e43f770bcbe3e433a46 Mon Sep 17 00:00:00 2001 From: Simone Ramundi Date: Wed, 17 Apr 2024 12:46:18 +0200 Subject: [PATCH 1/5] [DSC-1601] Fixed issue with icon visibility in FileDownloadLinkComponent --- .../shared/file-download-link/file-download-link.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shared/file-download-link/file-download-link.component.ts b/src/app/shared/file-download-link/file-download-link.component.ts index 025cb2ce537..5de1388c6fd 100644 --- a/src/app/shared/file-download-link/file-download-link.component.ts +++ b/src/app/shared/file-download-link/file-download-link.component.ts @@ -42,7 +42,7 @@ export class FileDownloadLinkComponent implements OnInit { @Input() enableRequestACopy = true; - @Input() showIcon = false; + @Input() showIcon = true; bitstreamPath$: Observable<{ routerLink: string, From 604f37c2c37645dd98e83303502bd726719e6a67 Mon Sep 17 00:00:00 2001 From: Simone Ramundi Date: Sat, 27 Apr 2024 14:33:10 +0200 Subject: [PATCH 2/5] [DSC-1601] - Removed old implementation --- .../shared/file-download-link/file-download-link.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shared/file-download-link/file-download-link.component.ts b/src/app/shared/file-download-link/file-download-link.component.ts index 5de1388c6fd..025cb2ce537 100644 --- a/src/app/shared/file-download-link/file-download-link.component.ts +++ b/src/app/shared/file-download-link/file-download-link.component.ts @@ -42,7 +42,7 @@ export class FileDownloadLinkComponent implements OnInit { @Input() enableRequestACopy = true; - @Input() showIcon = true; + @Input() showIcon = false; bitstreamPath$: Observable<{ routerLink: string, From 0920964cdc3232e96b1d3aaa6a8cb8cee1a05932 Mon Sep 17 00:00:00 2001 From: Simone Ramundi Date: Sat, 27 Apr 2024 14:38:18 +0200 Subject: [PATCH 3/5] [DSC-1601] - Added new implementation when bitstream is restricted --- .../file-section/full-file-section.component.html | 4 ++-- .../file-section/full-file-section.component.ts | 11 ++++++++++- .../themed-file-download-link.component.ts | 4 +++- 3 files changed, 15 insertions(+), 4 deletions(-) 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..b1de9cf4a31 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.ts b/src/app/item-page/full/field-components/file-section/full-file-section.component.ts index 6b66b48a8c6..3663c81bc3f 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 @@ -9,7 +9,7 @@ import { FileSectionComponent } from '../../../simple/field-components/file-sect import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model'; import { PaginatedList } from '../../../../core/data/paginated-list.model'; import { RemoteData } from '../../../../core/data/remote-data'; -import { switchMap, tap } from 'rxjs/operators'; +import { map, switchMap, tap } from 'rxjs/operators'; import { NotificationsService } from '../../../../shared/notifications/notifications.service'; import { TranslateService } from '@ngx-translate/core'; import { hasValue, isEmpty } from '../../../../shared/empty.util'; @@ -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,12 @@ 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).pipe( + map(value => !value), + ); + } + 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 Date: Mon, 29 Apr 2024 11:40:02 +0200 Subject: [PATCH 4/5] [DSC-1601] - Adjusted code for fixing requested --- .../file-section/full-file-section.component.html | 2 +- .../file-section/full-file-section.component.ts | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) 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 b1de9cf4a31..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,7 +34,7 @@
{{"item.page.filesection.original.bundle"
- + {{"item.page.filesection.download" | translate}}
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 3663c81bc3f..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 @@ -9,7 +9,7 @@ import { FileSectionComponent } from '../../../simple/field-components/file-sect import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model'; import { PaginatedList } from '../../../../core/data/paginated-list.model'; import { RemoteData } from '../../../../core/data/remote-data'; -import { map, switchMap, tap } from 'rxjs/operators'; +import { switchMap, tap } from 'rxjs/operators'; import { NotificationsService } from '../../../../shared/notifications/notifications.service'; import { TranslateService } from '@ngx-translate/core'; import { hasValue, isEmpty } from '../../../../shared/empty.util'; @@ -116,9 +116,7 @@ export class FullFileSectionComponent extends FileSectionComponent implements On } canDownload(file: Bitstream): Observable { - return this.authorizationService.isAuthorized(FeatureID.CanDownload, file.self).pipe( - map(value => !value), - ); + return this.authorizationService.isAuthorized(FeatureID.CanDownload, file.self); } ngOnDestroy(): void { From de85023bbcf47939488e7c4b7db0af06f7e3b396 Mon Sep 17 00:00:00 2001 From: Simone Ramundi Date: Mon, 29 Apr 2024 15:36:18 +0200 Subject: [PATCH 5/5] [DSC-1601] - Added test case --- .../full-file-section.component.spec.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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()); + })); }); });