Skip to content

Commit

Permalink
Fix handle redirect not working with custom nameSpace
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrevryghem committed Nov 11, 2023
1 parent 18febff commit b894dce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/app/core/data/dso-redirect.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils
import { Item } from '../shared/item.model';
import { EMBED_SEPARATOR } from './base/base-data.service';
import { HardRedirectService } from '../services/hard-redirect.service';
import { environment } from '../../../environments/environment.test';
import { AppConfig } from '../../../config/app-config.interface';

describe('DsoRedirectService', () => {
let scheduler: TestScheduler;
Expand Down Expand Up @@ -56,6 +58,7 @@ describe('DsoRedirectService', () => {
});

service = new DsoRedirectService(
environment as AppConfig,
requestService,
rdbService,
objectCache,
Expand Down Expand Up @@ -107,7 +110,7 @@ describe('DsoRedirectService', () => {
redir.subscribe();
scheduler.schedule(() => redir);
scheduler.flush();
expect(redirectService.redirect).toHaveBeenCalledWith('/items/' + remoteData.payload.uuid, 301);
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/items/${remoteData.payload.uuid}`, 301);
});
it('should navigate to entities route with the corresponding entity type', () => {
remoteData.payload.type = 'item';
Expand All @@ -124,7 +127,7 @@ describe('DsoRedirectService', () => {
redir.subscribe();
scheduler.schedule(() => redir);
scheduler.flush();
expect(redirectService.redirect).toHaveBeenCalledWith('/entities/publication/' + remoteData.payload.uuid, 301);
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/entities/publication/${remoteData.payload.uuid}`, 301);
});

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

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

Expand Down
6 changes: 4 additions & 2 deletions src/app/core/data/dso-redirect.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* http://www.dspace.org/license/
*/
/* eslint-disable max-classes-per-file */
import { Injectable } from '@angular/core';
import { Injectable, Inject } from '@angular/core';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { hasValue } from '../../shared/empty.util';
Expand All @@ -21,6 +21,7 @@ import { DSpaceObject } from '../shared/dspace-object.model';
import { IdentifiableDataService } from './base/identifiable-data.service';
import { getDSORoute } from '../../app-routing-paths';
import { HardRedirectService } from '../services/hard-redirect.service';
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';

const ID_ENDPOINT = 'pid';
const UUID_ENDPOINT = 'dso';
Expand Down Expand Up @@ -70,6 +71,7 @@ export class DsoRedirectService {
private dataService: DsoByIdOrUUIDDataService;

constructor(
@Inject(APP_CONFIG) protected appConfig: AppConfig,
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected objectCache: ObjectCacheService,
Expand Down Expand Up @@ -98,7 +100,7 @@ export class DsoRedirectService {
let newRoute = getDSORoute(dso);
if (hasValue(newRoute)) {
// Use a "301 Moved Permanently" redirect for SEO purposes
this.hardRedirectService.redirect(newRoute, 301);
this.hardRedirectService.redirect(this.appConfig.ui.nameSpace.replace(/\/$/, '') + newRoute, 301);
}
}
}
Expand Down

0 comments on commit b894dce

Please sign in to comment.