Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-1601 (pull request DSpace#1634)
Browse files Browse the repository at this point in the history
Task/dspace cris 2023 02 x/DSC-1601

Approved-by: Andrea Barbasso
  • Loading branch information
Simone-Ramundi authored and Andrea Barbasso committed May 2, 2024
2 parents d2b6c3e + 926f76d commit 938ebca
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ <h5 class="simple-view-element-header">{{"item.page.filesection.original.bundle"
</dl>
</div>
<div *ngIf="!hasNoDownload(file)" class="col-2">
<ds-themed-file-download-link [bitstream]="file" [item]="item">
{{"item.page.filesection.download" | translate}}
<ds-themed-file-download-link [showIcon]="!(canDownload(file) | async)" [bitstream]="file" [item]="item">
{{"item.page.filesection.download" | translate}}
</ds-themed-file-download-link>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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]
Expand All @@ -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());
}));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -112,6 +115,10 @@ export class FullFileSectionComponent extends FileSectionComponent implements On
return bitstream?.allMetadataValues('bitstream.viewer.provider').includes('nodownload');
}

canDownload(file: Bitstream): Observable<boolean> {
return this.authorizationService.isAuthorized(FeatureID.CanDownload, file.self);
}

ngOnDestroy(): void {
this.paginationService.clearPagination(this.originalOptions.id);
this.paginationService.clearPagination(this.licenseOptions.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export class ThemedFileDownloadLinkComponent extends ThemedComponent<FileDownloa

@Input() enableRequestACopy: boolean;

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

protected inAndOutputNames: (keyof FileDownloadLinkComponent & keyof this)[] = ['bitstream', 'item', 'cssClasses', 'isBlank', 'enableRequestACopy', 'showIcon'];

protected getComponentName(): string {
return 'FileDownloadLinkComponent';
Expand Down

0 comments on commit 938ebca

Please sign in to comment.