Skip to content

Commit 2c1422f

Browse files
committed
added repository prefix for bitstream redirecting
1 parent 8a393e3 commit 2c1422f

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

config/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
debug: false
22

3+
ui:
4+
nameSpace: /repository
5+
36
rest:
47
ssl: false
58
host: localhost

src/app/bitstream-page/legacy-bitstream-url-redirect.guard.spec.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { HardRedirectService } from '../core/services/hard-redirect.service';
1010
import { Bitstream } from '../core/shared/bitstream.model';
1111
import { RouterStub } from '../shared/testing/router.stub';
1212
import { legacyBitstreamURLRedirectGuard } from './legacy-bitstream-url-redirect.guard';
13+
import { AppConfig } from '../../config/app-config.interface';
1314

1415
describe('legacyBitstreamURLRedirectGuard', () => {
1516
let resolver: any;
@@ -19,6 +20,7 @@ describe('legacyBitstreamURLRedirectGuard', () => {
1920
let state;
2021
let hardRedirectService: HardRedirectService;
2122
let router: RouterStub;
23+
let appConfig: AppConfig;
2224

2325
let bitstream: Bitstream;
2426

@@ -29,6 +31,11 @@ describe('legacyBitstreamURLRedirectGuard', () => {
2931
};
3032
router = new RouterStub();
3133
hardRedirectService = new BrowserHardRedirectService(window.location);
34+
appConfig = {
35+
ui: {
36+
nameSpace: '/repository'
37+
}
38+
} as AppConfig;
3239
state = {};
3340
bitstream = Object.assign(new Bitstream(), {
3441
uuid: 'bitstream-id',
@@ -60,7 +67,7 @@ describe('legacyBitstreamURLRedirectGuard', () => {
6067
});
6168
});
6269
it(`should call findByItemHandle with the handle, sequence id, and filename from the route`, () => {
63-
resolver(route, state, bitstreamDataService, hardRedirectService, router);
70+
resolver(route, state, bitstreamDataService, hardRedirectService, router, appConfig);
6471
expect(bitstreamDataService.findByItemHandle).toHaveBeenCalledWith(
6572
`${route.params.prefix}/${route.params.suffix}`,
6673
route.params.sequence_id,
@@ -85,7 +92,7 @@ describe('legacyBitstreamURLRedirectGuard', () => {
8592
});
8693
});
8794
it(`should call findByItemHandle with the handle and filename from the route, and the sequence ID from the queryParams`, () => {
88-
resolver(route, state, bitstreamDataService, hardRedirectService, router);
95+
resolver(route, state, bitstreamDataService, hardRedirectService, router, appConfig);
8996
expect(bitstreamDataService.findByItemHandle).toHaveBeenCalledWith(
9097
`${route.params.prefix}/${route.params.suffix}`,
9198
route.queryParams.sequenceId,
@@ -105,7 +112,7 @@ describe('legacyBitstreamURLRedirectGuard', () => {
105112
});
106113
});
107114
it(`should call findByItemHandle with the handle, and filename from the route`, () => {
108-
resolver(route, state, bitstreamDataService, hardRedirectService, router);
115+
resolver(route, state, bitstreamDataService, hardRedirectService, router, appConfig);
109116
expect(bitstreamDataService.findByItemHandle).toHaveBeenCalledWith(
110117
`${route.params.prefix}/${route.params.suffix}`,
111118
undefined,
@@ -122,7 +129,7 @@ describe('legacyBitstreamURLRedirectGuard', () => {
122129
b: remoteDataMocks.ResponsePending,
123130
c: remoteDataMocks.Error,
124131
}));
125-
resolver(route, state, bitstreamDataService, hardRedirectService, router).subscribe(() => {
132+
resolver(route, state, bitstreamDataService, hardRedirectService, router, appConfig).subscribe(() => {
126133
expect(bitstreamDataService.findByItemHandle).toHaveBeenCalled();
127134
expect(router.createUrlTree).toHaveBeenCalledWith([PAGE_NOT_FOUND_PATH]);
128135
});
@@ -135,7 +142,7 @@ describe('legacyBitstreamURLRedirectGuard', () => {
135142
b: remoteDataMocks.ResponsePending,
136143
c: remoteDataMocks.NoContent,
137144
}));
138-
resolver(route, state, bitstreamDataService, hardRedirectService, router).subscribe(() => {
145+
resolver(route, state, bitstreamDataService, hardRedirectService, router, appConfig).subscribe(() => {
139146
expect(bitstreamDataService.findByItemHandle).toHaveBeenCalled();
140147
expect(router.createUrlTree).toHaveBeenCalledWith([PAGE_NOT_FOUND_PATH]);
141148
});
@@ -148,9 +155,9 @@ describe('legacyBitstreamURLRedirectGuard', () => {
148155
b: remoteDataMocks.ResponsePending,
149156
c: remoteDataMocks.Success,
150157
}));
151-
resolver(route, state, bitstreamDataService, hardRedirectService, router).subscribe(() => {
158+
resolver(route, state, bitstreamDataService, hardRedirectService, router, appConfig).subscribe(() => {
152159
expect(bitstreamDataService.findByItemHandle).toHaveBeenCalled();
153-
expect(hardRedirectService.redirect).toHaveBeenCalledWith(new URL(`/bitstreams/${bitstream.uuid}/download`, window.location.origin).href, 301);
160+
expect(hardRedirectService.redirect).toHaveBeenCalledWith(new URL(`/repository/bitstreams/${bitstream.uuid}/download`, window.location.origin).href, 301);
154161
});
155162
});
156163
});

src/app/bitstream-page/legacy-bitstream-url-redirect.guard.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { HardRedirectService } from '../core/services/hard-redirect.service';
1616
import { Bitstream } from '../core/shared/bitstream.model';
1717
import { getFirstCompletedRemoteData } from '../core/shared/operators';
1818
import { hasNoValue } from '../shared/empty.util';
19+
import { APP_CONFIG, AppConfig } from '../../config/app-config.interface';
1920

2021
/**
2122
* Redirects to a bitstream based on the handle of the item, and the sequence id or the filename of the
@@ -30,6 +31,7 @@ export const legacyBitstreamURLRedirectGuard: CanActivateFn = (
3031
bitstreamDataService: BitstreamDataService = inject(BitstreamDataService),
3132
serverHardRedirectService: HardRedirectService = inject(HardRedirectService),
3233
router: Router = inject(Router),
34+
appConfig: AppConfig = inject(APP_CONFIG),
3335
): Observable<UrlTree | boolean> => {
3436
const prefix = route.params.prefix;
3537
const suffix = route.params.suffix;
@@ -46,7 +48,11 @@ export const legacyBitstreamURLRedirectGuard: CanActivateFn = (
4648
getFirstCompletedRemoteData(),
4749
map((rd: RemoteData<Bitstream>) => {
4850
if (rd.hasSucceeded && !rd.hasNoContent) {
49-
serverHardRedirectService.redirect(new URL(`/bitstreams/${rd.payload.uuid}/download`, serverHardRedirectService.getCurrentOrigin()).href, 301);
51+
// Get the UI namespace to construct the correct redirect URL
52+
const { nameSpace } = appConfig.ui;
53+
const namespacePrefix = nameSpace === '/' ? '' : nameSpace;
54+
const redirectPath = `${namespacePrefix}/bitstreams/${rd.payload.uuid}/download`;
55+
serverHardRedirectService.redirect(new URL(redirectPath, serverHardRedirectService.getCurrentOrigin()).href, 301);
5056
return false;
5157
} else {
5258
return router.createUrlTree([PAGE_NOT_FOUND_PATH]);

0 commit comments

Comments
 (0)