mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge pull request #2634 from DSpace/backport-2630-to-dspace-7_x
[Port dspace-7_x] Fix handle redirect not working with custom nameSpace
This commit is contained in:
@@ -11,6 +11,8 @@ import { createSuccessfulRemoteDataObject } from '../../shared/remote-data.utils
|
|||||||
import { Item } from '../shared/item.model';
|
import { Item } from '../shared/item.model';
|
||||||
import { EMBED_SEPARATOR } from './base/base-data.service';
|
import { EMBED_SEPARATOR } from './base/base-data.service';
|
||||||
import { HardRedirectService } from '../services/hard-redirect.service';
|
import { HardRedirectService } from '../services/hard-redirect.service';
|
||||||
|
import { environment } from '../../../environments/environment.test';
|
||||||
|
import { AppConfig } from '../../../config/app-config.interface';
|
||||||
|
|
||||||
describe('DsoRedirectService', () => {
|
describe('DsoRedirectService', () => {
|
||||||
let scheduler: TestScheduler;
|
let scheduler: TestScheduler;
|
||||||
@@ -56,6 +58,7 @@ describe('DsoRedirectService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
service = new DsoRedirectService(
|
service = new DsoRedirectService(
|
||||||
|
environment as AppConfig,
|
||||||
requestService,
|
requestService,
|
||||||
rdbService,
|
rdbService,
|
||||||
objectCache,
|
objectCache,
|
||||||
@@ -107,7 +110,7 @@ describe('DsoRedirectService', () => {
|
|||||||
redir.subscribe();
|
redir.subscribe();
|
||||||
scheduler.schedule(() => redir);
|
scheduler.schedule(() => redir);
|
||||||
scheduler.flush();
|
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', () => {
|
it('should navigate to entities route with the corresponding entity type', () => {
|
||||||
remoteData.payload.type = 'item';
|
remoteData.payload.type = 'item';
|
||||||
@@ -124,7 +127,7 @@ describe('DsoRedirectService', () => {
|
|||||||
redir.subscribe();
|
redir.subscribe();
|
||||||
scheduler.schedule(() => redir);
|
scheduler.schedule(() => redir);
|
||||||
scheduler.flush();
|
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', () => {
|
it('should navigate to collections route', () => {
|
||||||
@@ -133,7 +136,7 @@ describe('DsoRedirectService', () => {
|
|||||||
redir.subscribe();
|
redir.subscribe();
|
||||||
scheduler.schedule(() => redir);
|
scheduler.schedule(() => redir);
|
||||||
scheduler.flush();
|
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', () => {
|
it('should navigate to communities route', () => {
|
||||||
@@ -142,7 +145,7 @@ describe('DsoRedirectService', () => {
|
|||||||
redir.subscribe();
|
redir.subscribe();
|
||||||
scheduler.schedule(() => redir);
|
scheduler.schedule(() => redir);
|
||||||
scheduler.flush();
|
scheduler.flush();
|
||||||
expect(redirectService.redirect).toHaveBeenCalledWith('/communities/' + remoteData.payload.uuid, 301);
|
expect(redirectService.redirect).toHaveBeenCalledWith(`${environment.ui.nameSpace}/communities/${remoteData.payload.uuid}`, 301);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
* http://www.dspace.org/license/
|
* http://www.dspace.org/license/
|
||||||
*/
|
*/
|
||||||
/* eslint-disable max-classes-per-file */
|
/* eslint-disable max-classes-per-file */
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable, Inject } from '@angular/core';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { tap } from 'rxjs/operators';
|
import { tap } from 'rxjs/operators';
|
||||||
import { hasValue } from '../../shared/empty.util';
|
import { hasValue } from '../../shared/empty.util';
|
||||||
@@ -21,6 +21,7 @@ import { DSpaceObject } from '../shared/dspace-object.model';
|
|||||||
import { IdentifiableDataService } from './base/identifiable-data.service';
|
import { IdentifiableDataService } from './base/identifiable-data.service';
|
||||||
import { getDSORoute } from '../../app-routing-paths';
|
import { getDSORoute } from '../../app-routing-paths';
|
||||||
import { HardRedirectService } from '../services/hard-redirect.service';
|
import { HardRedirectService } from '../services/hard-redirect.service';
|
||||||
|
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
|
||||||
|
|
||||||
const ID_ENDPOINT = 'pid';
|
const ID_ENDPOINT = 'pid';
|
||||||
const UUID_ENDPOINT = 'dso';
|
const UUID_ENDPOINT = 'dso';
|
||||||
@@ -70,6 +71,7 @@ export class DsoRedirectService {
|
|||||||
private dataService: DsoByIdOrUUIDDataService;
|
private dataService: DsoByIdOrUUIDDataService;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(APP_CONFIG) protected appConfig: AppConfig,
|
||||||
protected requestService: RequestService,
|
protected requestService: RequestService,
|
||||||
protected rdbService: RemoteDataBuildService,
|
protected rdbService: RemoteDataBuildService,
|
||||||
protected objectCache: ObjectCacheService,
|
protected objectCache: ObjectCacheService,
|
||||||
@@ -98,7 +100,7 @@ export class DsoRedirectService {
|
|||||||
let newRoute = getDSORoute(dso);
|
let newRoute = getDSORoute(dso);
|
||||||
if (hasValue(newRoute)) {
|
if (hasValue(newRoute)) {
|
||||||
// Use a "301 Moved Permanently" redirect for SEO purposes
|
// Use a "301 Moved Permanently" redirect for SEO purposes
|
||||||
this.hardRedirectService.redirect(newRoute, 301);
|
this.hardRedirectService.redirect(this.appConfig.ui.nameSpace.replace(/\/$/, '') + newRoute, 301);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user