Skip to content

Commit 6d8f69a

Browse files
Fix DSpace#5555: downloads not working from Bitstreams tab and Workspace/Wo… (DSpace#5557)
* Fix DSpace#5555: downloads not working from Bitstreams tab and Workspace/Workflow * Fix DSpace#5555: downloads not working from Workspace/Workflow submissions * Merge main and fix unused Bitstream import
1 parent ed63b75 commit 6d8f69a

4 files changed

Lines changed: 31 additions & 20 deletions

File tree

src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
headers="{{ entry.nameStripped }} {{ bundleName }} actions">
9898
<div class="text-center w-100">
9999
<div class="btn-group relationship-action-buttons">
100-
<a [href]="entry.downloadUrl"
100+
<a [routerLink]="entry.downloadUrl"
101101
[attr.aria-label]="'item.edit.bitstreams.edit.buttons.download' | translate"
102102
class="btn btn-outline-primary btn-sm"
103103
title="{{'item.edit.bitstreams.edit.buttons.download' | translate}}"

src/app/submission/sections/upload/file/section-upload-file.component.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
</div>
2727
<div class="float-end w-15">
2828
<ng-container>
29-
<ds-file-download-link [cssClasses]="'btn btn-link-focus'" [isBlank]="true"
30-
[bitstream]="getBitstream()" [enableRequestACopy]="false" [showAccessStatusBadge]="false">
29+
<button class="btn btn-link-focus"
30+
[attr.aria-label]="'submission.sections.upload.download.title' | translate"
31+
title="{{ 'submission.sections.upload.download.title' | translate }}"
32+
(click)="$event.preventDefault(); downloadFile()">
3133
<i class="fa fa-download fa-2x text-normal" aria-hidden="true"></i>
32-
</ds-file-download-link>
34+
</button>
3335
<button class="btn btn-link-focus"
3436
attr.aria-label="{{'submission.sections.upload.edit.title' | translate}} {{fileName}}"
3537
title="{{ 'submission.sections.upload.edit.title' | translate }} {{fileName}}"

src/app/submission/sections/upload/file/section-upload-file.component.spec.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { AuthorizationDataService } from '@dspace/core/data/feature-authorizatio
1818
import { ItemDataService } from '@dspace/core/data/item-data.service';
1919
import { JsonPatchOperationPathCombiner } from '@dspace/core/json-patch/builder/json-patch-operation-path-combiner';
2020
import { JsonPatchOperationsBuilder } from '@dspace/core/json-patch/builder/json-patch-operations-builder';
21+
import { HardRedirectService } from '@dspace/core/services/hard-redirect.service';
22+
import { FileService } from '@dspace/core/shared/file.service';
2123
import { HALEndpointService } from '@dspace/core/shared/hal-endpoint.service';
2224
import { SubmissionJsonPatchOperationsService } from '@dspace/core/submission/submission-json-patch-operations.service';
2325
import { AuthorizationDataServiceStub } from '@dspace/core/testing/authorization-service.stub';
@@ -37,7 +39,6 @@ import { provideMockStore } from '@ngrx/store/testing';
3739
import { TranslateModule } from '@ngx-translate/core';
3840
import { of } from 'rxjs';
3941

40-
import { ThemedFileDownloadLinkComponent } from '../../../../shared/file-download-link/themed-file-download-link.component';
4142
import { FormBuilderService } from '../../../../shared/form/builder/form-builder.service';
4243
import { FormService } from '../../../../shared/form/form.service';
4344
import { getMockFormService } from '../../../../shared/form/testing/form-service.mock';
@@ -117,6 +118,8 @@ describe('SubmissionSectionUploadFileComponent', () => {
117118
{ provide: SubmissionService, useValue: submissionServiceStub },
118119
{ provide: SectionUploadService, useValue: getMockSectionUploadService() },
119120
{ provide: ThemeService, useValue: getMockThemeService() },
121+
{ provide: FileService, useValue: { retrieveFileDownloadLink: jasmine.createSpy('retrieveFileDownloadLink').and.returnValue(of('https://test-url.com/file')) } },
122+
{ provide: HardRedirectService, useValue: { redirect: jasmine.createSpy('redirect') } },
120123
{ provide: Store, useValue: provideMockStore() },
121124
{ provide: ItemDataService, useValue: {} },
122125
ChangeDetectorRef,
@@ -132,12 +135,9 @@ describe('SubmissionSectionUploadFileComponent', () => {
132135
add: {
133136
schemas: [CUSTOM_ELEMENTS_SCHEMA],
134137
},
135-
remove: {
136-
imports: [
137-
SubmissionSectionUploadFileViewComponent,
138-
ThemedFileDownloadLinkComponent,
139-
],
140-
},
138+
remove: { imports: [
139+
SubmissionSectionUploadFileViewComponent,
140+
] },
141141
})
142142
.compileComponents();
143143
}));
@@ -288,6 +288,15 @@ describe('SubmissionSectionUploadFileComponent', () => {
288288
expect(compAsAny.editBitstreamData).toHaveBeenCalled();
289289
});
290290

291+
it('should call downloadFile and open link in new tab', () => {
292+
spyOn(window, 'open');
293+
comp.fileData = fileData;
294+
295+
comp.downloadFile();
296+
297+
expect(window.open).toHaveBeenCalledWith('https://test-url.com/file', '_blank');
298+
});
299+
291300
});
292301
});
293302

src/app/submission/sections/upload/file/section-upload-file.component.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { FeatureID } from '@dspace/core/data/feature-authorization/feature-id';
1414
import { ItemDataService } from '@dspace/core/data/item-data.service';
1515
import { JsonPatchOperationPathCombiner } from '@dspace/core/json-patch/builder/json-patch-operation-path-combiner';
1616
import { JsonPatchOperationsBuilder } from '@dspace/core/json-patch/builder/json-patch-operations-builder';
17-
import { Bitstream } from '@dspace/core/shared/bitstream.model';
1817
import { followLink } from '@dspace/core/shared/follow-link-config.model';
1918
import { HALEndpointService } from '@dspace/core/shared/hal-endpoint.service';
2019
import { Item } from '@dspace/core/shared/item.model';
@@ -47,10 +46,12 @@ import {
4746
filter,
4847
map,
4948
switchMap,
49+
take,
5050
} from 'rxjs/operators';
5151

52+
import { HardRedirectService } from '../../../../core/services/hard-redirect.service';
53+
import { FileService } from '../../../../core/shared/file.service';
5254
import { BtnDisabledDirective } from '../../../../shared/btn-disabled.directive';
53-
import { ThemedFileDownloadLinkComponent } from '../../../../shared/file-download-link/themed-file-download-link.component';
5455
import { FormService } from '../../../../shared/form/form.service';
5556
import { SubmissionService } from '../../../submission.service';
5657
import { SectionUploadService } from '../section-upload.service';
@@ -69,7 +70,6 @@ import { SubmissionSectionUploadFileViewComponent } from './view/section-upload-
6970
AsyncPipe,
7071
BtnDisabledDirective,
7172
SubmissionSectionUploadFileViewComponent,
72-
ThemedFileDownloadLinkComponent,
7373
TranslateModule,
7474
],
7575
})
@@ -229,6 +229,8 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit,
229229
private operationsService: SubmissionJsonPatchOperationsService,
230230
private submissionService: SubmissionService,
231231
private uploadService: SectionUploadService,
232+
private fileService: FileService,
233+
private hardRedirectService: HardRedirectService,
232234
private authorizationService: AuthorizationDataService,
233235
private halService: HALEndpointService,
234236
private itemDataService: ItemDataService,
@@ -337,13 +339,11 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit,
337339
}
338340

339341
/**
340-
* Build a Bitstream object by the current file uuid
341-
*
342-
* @return Bitstream object
342+
* Download the file using a short-lived token
343343
*/
344-
public getBitstream(): Bitstream {
345-
return Object.assign(new Bitstream(), {
346-
uuid: this.fileData.uuid,
344+
public downloadFile() {
345+
this.fileService.retrieveFileDownloadLink(this.fileData.url).pipe(take(1)).subscribe((link) => {
346+
window.open(link, '_blank');
347347
});
348348
}
349349

0 commit comments

Comments
 (0)