Skip to content

Commit 64364c9

Browse files
authored
Merge pull request #2634 from DSpace/backport-2630-to-dspace-7_x
[Port dspace-7_x] Fix handle redirect not working with custom nameSpace
2 parents 7d5c456 + 68cdd12 commit 64364c9

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/app/core/data/dso-redirect.service.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils
1111
import { Item } from '../shared/item.model';
1212
import { EMBED_SEPARATOR } from './base/base-data.service';
1313
import { HardRedirectService } from '../services/hard-redirect.service';
14+
import { environment } from '../../../environments/environment.test';
15+
import { AppConfig } from '../../../config/app-config.interface';
1416

1517
describe('DsoRedirectService', () => {
1618
let scheduler: TestScheduler;
@@ -56,6 +58,7 @@ describe('DsoRedirectService', () => {
5658
});
5759

5860
service = new DsoRedirectService(
61+
environment as AppConfig,
5962
requestService,
6063
rdbService,
6164
objectCache,
@@ -107,7 +110,7 @@ describe('DsoRedirectService', () => {
107110
redir.subscribe();
108111
scheduler.schedule(() => redir);
109112
scheduler.flush();
110-
expect(redirectService.redirect).toHaveBeenCalledWith('/items/' + remoteData.payload.uuid, 301);
113+
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/items/${remoteData.payload.uuid}`, 301);
111114
});
112115
it('should navigate to entities route with the corresponding entity type', () => {
113116
remoteData.payload.type = 'item';
@@ -124,7 +127,7 @@ describe('DsoRedirectService', () => {
124127
redir.subscribe();
125128
scheduler.schedule(() => redir);
126129
scheduler.flush();
127-
expect(redirectService.redirect).toHaveBeenCalledWith('/entities/publication/' + remoteData.payload.uuid, 301);
130+
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/entities/publication/${remoteData.payload.uuid}`, 301);
128131
});
129132

130133
it('should navigate to collections route', () => {
@@ -133,7 +136,7 @@ describe('DsoRedirectService', () => {
133136
redir.subscribe();
134137
scheduler.schedule(() => redir);
135138
scheduler.flush();
136-
expect(redirectService.redirect).toHaveBeenCalledWith('/collections/' + remoteData.payload.uuid, 301);
139+
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/collections/${remoteData.payload.uuid}`, 301);
137140
});
138141

139142
it('should navigate to communities route', () => {
@@ -142,7 +145,7 @@ describe('DsoRedirectService', () => {
142145
redir.subscribe();
143146
scheduler.schedule(() => redir);
144147
scheduler.flush();
145-
expect(redirectService.redirect).toHaveBeenCalledWith('/communities/' + remoteData.payload.uuid, 301);
148+
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/communities/${remoteData.payload.uuid}`, 301);
146149
});
147150
});
148151

src/app/core/data/dso-redirect.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* http://www.dspace.org/license/
77
*/
88
/* eslint-disable max-classes-per-file */
9-
import { Injectable } from '@angular/core';
9+
import { Injectable, Inject } from '@angular/core';
1010
import { Observable } from 'rxjs';
1111
import { tap } from 'rxjs/operators';
1212
import { hasValue } from '../../shared/empty.util';
@@ -21,6 +21,7 @@ import { DSpaceObject } from '../shared/dspace-object.model';
2121
import { IdentifiableDataService } from './base/identifiable-data.service';
2222
import { getDSORoute } from '../../app-routing-paths';
2323
import { HardRedirectService } from '../services/hard-redirect.service';
24+
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
2425

2526
const ID_ENDPOINT = 'pid';
2627
const UUID_ENDPOINT = 'dso';
@@ -70,6 +71,7 @@ export class DsoRedirectService {
7071
private dataService: DsoByIdOrUUIDDataService;
7172

7273
constructor(
74+
@Inject(APP_CONFIG) protected appConfig: AppConfig,
7375
protected requestService: RequestService,
7476
protected rdbService: RemoteDataBuildService,
7577
protected objectCache: ObjectCacheService,
@@ -98,7 +100,7 @@ export class DsoRedirectService {
98100
let newRoute = getDSORoute(dso);
99101
if (hasValue(newRoute)) {
100102
// Use a "301 Moved Permanently" redirect for SEO purposes
101-
this.hardRedirectService.redirect(newRoute, 301);
103+
this.hardRedirectService.redirect(this.appConfig.ui.nameSpace.replace(/\/$/, '') + newRoute, 301);
102104
}
103105
}
104106
}

0 commit comments

Comments
 (0)