Skip to content

Commit 938ebca

Browse files
Simone-RamundiAndrea Barbasso
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-1601 (pull request DSpace#1634)
Task/dspace cris 2023 02 x/DSC-1601 Approved-by: Andrea Barbasso
2 parents d2b6c3e + 926f76d commit 938ebca

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/app/item-page/full/field-components/file-section/full-file-section.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ <h5 class="simple-view-element-header">{{"item.page.filesection.original.bundle"
3434
</dl>
3535
</div>
3636
<div *ngIf="!hasNoDownload(file)" class="col-2">
37-
<ds-themed-file-download-link [bitstream]="file" [item]="item">
38-
{{"item.page.filesection.download" | translate}}
37+
<ds-themed-file-download-link [showIcon]="!(canDownload(file) | async)" [bitstream]="file" [item]="item">
38+
{{"item.page.filesection.download" | translate}}
3939
</ds-themed-file-download-link>
4040
</div>
4141
</div>

src/app/item-page/full/field-components/file-section/full-file-section.component.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { APP_CONFIG } from 'src/config/app-config.interface';
2222
import { environment } from 'src/environments/environment';
2323
import { UUIDService } from '../../../../core/shared/uuid.service';
2424
import { getMockUUIDService } from '../../../../shared/mocks/uuid.service.mock';
25+
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
2526

2627
describe('FullFileSectionComponent', () => {
2728
let comp: FullFileSectionComponent;
@@ -58,6 +59,10 @@ describe('FullFileSectionComponent', () => {
5859
findAllByItemAndBundleName: createSuccessfulRemoteDataObject$(createPaginatedList([mockBitstream, mockBitstream, mockBitstream]))
5960
});
6061

62+
const authorizedDataService = jasmine.createSpyObj('authorizedDataService',{
63+
isAuthorized: observableOf(false),
64+
});
65+
6166
const paginationService = new PaginationServiceStub();
6267

6368
beforeEach(waitForAsync(() => {
@@ -75,7 +80,8 @@ describe('FullFileSectionComponent', () => {
7580
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
7681
{ provide: PaginationService, useValue: paginationService },
7782
{ provide: APP_CONFIG, useValue: environment },
78-
{ provide: UUIDService, useValue: getMockUUIDService() }
83+
{ provide: UUIDService, useValue: getMockUUIDService() },
84+
{ provide: AuthorizationDataService, useValue: authorizedDataService },
7985
],
8086

8187
schemas: [NO_ERRORS_SCHEMA]
@@ -98,5 +104,14 @@ describe('FullFileSectionComponent', () => {
98104
const fileNameElement = fixture.debugElement.query(By.css('[data-test="file-name"]')).nativeElement;
99105
expect(fileNameElement.classList).toContain('text-break');
100106
});
107+
108+
it('canDownload should return an observable with false value, if user is not authorized to download bitstream', waitForAsync(() => {
109+
authorizedDataService.isAuthorized.and.returnValue(observableOf(false));
110+
comp.canDownload(mockBitstream).subscribe(canDownload => expect(canDownload).toBeFalse());
111+
}));
112+
it('canDownload should return an observable with true value, if user is authorized to download bitstream', waitForAsync(() => {
113+
authorizedDataService.isAuthorized.and.returnValue(observableOf(true));
114+
comp.canDownload(mockBitstream).subscribe(canDownload => expect(canDownload).toBeTrue());
115+
}));
101116
});
102117
});

src/app/item-page/full/field-components/file-section/full-file-section.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import { PaginationService } from '../../../../core/pagination/pagination.servic
1717
import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service';
1818
import { AppConfig, APP_CONFIG } from 'src/config/app-config.interface';
1919
import { UUIDService } from '../../../../core/shared/uuid.service';
20+
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
21+
import { FeatureID } from '../../../../core/data/feature-authorization/feature-id';
2022

2123
/**
2224
* This component renders the file section of the item
@@ -56,6 +58,7 @@ export class FullFileSectionComponent extends FileSectionComponent implements On
5658
protected paginationService: PaginationService,
5759
public dsoNameService: DSONameService,
5860
protected uuidService: UUIDService,
61+
public authorizationService: AuthorizationDataService,
5962
@Inject(APP_CONFIG) protected appConfig: AppConfig
6063
) {
6164
super(bitstreamDataService, notificationsService, translateService, dsoNameService, appConfig);
@@ -112,6 +115,10 @@ export class FullFileSectionComponent extends FileSectionComponent implements On
112115
return bitstream?.allMetadataValues('bitstream.viewer.provider').includes('nodownload');
113116
}
114117

118+
canDownload(file: Bitstream): Observable<boolean> {
119+
return this.authorizationService.isAuthorized(FeatureID.CanDownload, file.self);
120+
}
121+
115122
ngOnDestroy(): void {
116123
this.paginationService.clearPagination(this.originalOptions.id);
117124
this.paginationService.clearPagination(this.licenseOptions.id);

src/app/shared/file-download-link/themed-file-download-link.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export class ThemedFileDownloadLinkComponent extends ThemedComponent<FileDownloa
2121

2222
@Input() enableRequestACopy: boolean;
2323

24-
protected inAndOutputNames: (keyof FileDownloadLinkComponent & keyof this)[] = ['bitstream', 'item', 'cssClasses', 'isBlank', 'enableRequestACopy'];
24+
@Input() showIcon: boolean;
25+
26+
protected inAndOutputNames: (keyof FileDownloadLinkComponent & keyof this)[] = ['bitstream', 'item', 'cssClasses', 'isBlank', 'enableRequestACopy', 'showIcon'];
2527

2628
protected getComponentName(): string {
2729
return 'FileDownloadLinkComponent';

0 commit comments

Comments
 (0)