mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
115427: Fixed edit item pages not redirecting to 404 with invalid id
(cherry picked from commit 249cac4f27
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
2843659416
commit
8b3010be0c
@@ -15,7 +15,6 @@ import { BehaviorSubject, of as observableOf } from 'rxjs';
|
|||||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||||
import { AuthService } from '../../core/auth/auth.service';
|
|
||||||
import { createPaginatedList } from '../../shared/testing/utils.test';
|
import { createPaginatedList } from '../../shared/testing/utils.test';
|
||||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||||
import { createRelationshipsObservable } from '../simple/item-types/shared/item.component.spec';
|
import { createRelationshipsObservable } from '../simple/item-types/shared/item.component.spec';
|
||||||
@@ -54,7 +53,6 @@ describe('FullItemPageComponent', () => {
|
|||||||
let comp: FullItemPageComponent;
|
let comp: FullItemPageComponent;
|
||||||
let fixture: ComponentFixture<FullItemPageComponent>;
|
let fixture: ComponentFixture<FullItemPageComponent>;
|
||||||
|
|
||||||
let authService: AuthService;
|
|
||||||
let routeStub: ActivatedRouteStub;
|
let routeStub: ActivatedRouteStub;
|
||||||
let routeData;
|
let routeData;
|
||||||
let authorizationDataService: AuthorizationDataService;
|
let authorizationDataService: AuthorizationDataService;
|
||||||
@@ -75,11 +73,6 @@ describe('FullItemPageComponent', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
authService = jasmine.createSpyObj('authService', {
|
|
||||||
isAuthenticated: observableOf(true),
|
|
||||||
setRedirectUrl: {}
|
|
||||||
});
|
|
||||||
|
|
||||||
routeData = {
|
routeData = {
|
||||||
dso: createSuccessfulRemoteDataObject(mockItem),
|
dso: createSuccessfulRemoteDataObject(mockItem),
|
||||||
};
|
};
|
||||||
@@ -117,7 +110,6 @@ describe('FullItemPageComponent', () => {
|
|||||||
{ provide: ActivatedRoute, useValue: routeStub },
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
{ provide: ItemDataService, useValue: {} },
|
{ provide: ItemDataService, useValue: {} },
|
||||||
{ provide: MetadataService, useValue: metadataServiceStub },
|
{ provide: MetadataService, useValue: metadataServiceStub },
|
||||||
{ provide: AuthService, useValue: authService },
|
|
||||||
{ provide: AuthorizationDataService, useValue: authorizationDataService },
|
{ provide: AuthorizationDataService, useValue: authorizationDataService },
|
||||||
{ provide: ServerResponseService, useValue: serverResponseService },
|
{ provide: ServerResponseService, useValue: serverResponseService },
|
||||||
{ provide: SignpostingDataService, useValue: signpostingDataService },
|
{ provide: SignpostingDataService, useValue: signpostingDataService },
|
||||||
|
@@ -13,7 +13,6 @@ import { Item } from '../../core/shared/item.model';
|
|||||||
|
|
||||||
import { fadeInOut } from '../../shared/animations/fade';
|
import { fadeInOut } from '../../shared/animations/fade';
|
||||||
import { hasValue } from '../../shared/empty.util';
|
import { hasValue } from '../../shared/empty.util';
|
||||||
import { AuthService } from '../../core/auth/auth.service';
|
|
||||||
import { Location } from '@angular/common';
|
import { Location } from '@angular/common';
|
||||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||||
import { ServerResponseService } from '../../core/services/server-response.service';
|
import { ServerResponseService } from '../../core/services/server-response.service';
|
||||||
@@ -49,7 +48,6 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
|
|||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected items: ItemDataService,
|
protected items: ItemDataService,
|
||||||
protected authService: AuthService,
|
|
||||||
protected authorizationService: AuthorizationDataService,
|
protected authorizationService: AuthorizationDataService,
|
||||||
protected _location: Location,
|
protected _location: Location,
|
||||||
protected responseService: ServerResponseService,
|
protected responseService: ServerResponseService,
|
||||||
@@ -57,7 +55,7 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
|
|||||||
protected linkHeadService: LinkHeadService,
|
protected linkHeadService: LinkHeadService,
|
||||||
@Inject(PLATFORM_ID) protected platformId: string,
|
@Inject(PLATFORM_ID) protected platformId: string,
|
||||||
) {
|
) {
|
||||||
super(route, router, items, authService, authorizationService, responseService, signpostingDataService, linkHeadService, platformId);
|
super(route, router, items, authorizationService, responseService, signpostingDataService, linkHeadService, platformId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** AoT inheritance fix, will hopefully be resolved in the near future **/
|
/*** AoT inheritance fix, will hopefully be resolved in the near future **/
|
||||||
|
@@ -3,14 +3,15 @@ import { createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
|
|||||||
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
||||||
import { MetadataValueFilter } from '../core/shared/metadata.models';
|
import { MetadataValueFilter } from '../core/shared/metadata.models';
|
||||||
import { first } from 'rxjs/operators';
|
import { first } from 'rxjs/operators';
|
||||||
import { Router } from '@angular/router';
|
import { Router, RouterModule } from '@angular/router';
|
||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { AuthServiceStub } from '../shared/testing/auth-service.stub';
|
||||||
|
import { AuthService } from '../core/auth/auth.service';
|
||||||
|
|
||||||
describe('ItemPageResolver', () => {
|
describe('ItemPageResolver', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [RouterTestingModule.withRoutes([{
|
imports: [RouterModule.forRoot([{
|
||||||
path: 'entities/:entity-type/:id',
|
path: 'entities/:entity-type/:id',
|
||||||
component: {} as any
|
component: {} as any
|
||||||
}])]
|
}])]
|
||||||
@@ -21,7 +22,8 @@ describe('ItemPageResolver', () => {
|
|||||||
let resolver: ItemPageResolver;
|
let resolver: ItemPageResolver;
|
||||||
let itemService: any;
|
let itemService: any;
|
||||||
let store: any;
|
let store: any;
|
||||||
let router: any;
|
let router: Router;
|
||||||
|
let authService: AuthServiceStub;
|
||||||
|
|
||||||
const uuid = '1234-65487-12354-1235';
|
const uuid = '1234-65487-12354-1235';
|
||||||
let item: DSpaceObject;
|
let item: DSpaceObject;
|
||||||
@@ -41,7 +43,8 @@ describe('ItemPageResolver', () => {
|
|||||||
store = jasmine.createSpyObj('store', {
|
store = jasmine.createSpyObj('store', {
|
||||||
dispatch: {},
|
dispatch: {},
|
||||||
});
|
});
|
||||||
resolver = new ItemPageResolver(itemService, store, router);
|
authService = new AuthServiceStub();
|
||||||
|
resolver = new ItemPageResolver(itemService, store, router, authService as unknown as AuthService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to the correct route for the entity type', (done) => {
|
it('should redirect to the correct route for the entity type', (done) => {
|
||||||
|
@@ -9,6 +9,8 @@ import { map } from 'rxjs/operators';
|
|||||||
import { hasValue } from '../shared/empty.util';
|
import { hasValue } from '../shared/empty.util';
|
||||||
import { getItemPageRoute } from './item-page-routing-paths';
|
import { getItemPageRoute } from './item-page-routing-paths';
|
||||||
import { ItemResolver } from './item.resolver';
|
import { ItemResolver } from './item.resolver';
|
||||||
|
import { redirectOn4xx } from '../core/shared/authorized.operators';
|
||||||
|
import { AuthService } from '../core/auth/auth.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a resolver that requests a specific item before the route is activated and will redirect to the
|
* This class represents a resolver that requests a specific item before the route is activated and will redirect to the
|
||||||
@@ -19,7 +21,8 @@ export class ItemPageResolver extends ItemResolver {
|
|||||||
constructor(
|
constructor(
|
||||||
protected itemService: ItemDataService,
|
protected itemService: ItemDataService,
|
||||||
protected store: Store<any>,
|
protected store: Store<any>,
|
||||||
protected router: Router
|
protected router: Router,
|
||||||
|
protected authService: AuthService,
|
||||||
) {
|
) {
|
||||||
super(itemService, store, router);
|
super(itemService, store, router);
|
||||||
}
|
}
|
||||||
@@ -33,6 +36,7 @@ export class ItemPageResolver extends ItemResolver {
|
|||||||
*/
|
*/
|
||||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Item>> {
|
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Item>> {
|
||||||
return super.resolve(route, state).pipe(
|
return super.resolve(route, state).pipe(
|
||||||
|
redirectOn4xx(this.router, this.authService),
|
||||||
map((rd: RemoteData<Item>) => {
|
map((rd: RemoteData<Item>) => {
|
||||||
if (rd.hasSucceeded && hasValue(rd.payload)) {
|
if (rd.hasSucceeded && hasValue(rd.payload)) {
|
||||||
const thisRoute = state.url;
|
const thisRoute = state.url;
|
||||||
|
@@ -19,7 +19,6 @@ import {
|
|||||||
createSuccessfulRemoteDataObject,
|
createSuccessfulRemoteDataObject,
|
||||||
createSuccessfulRemoteDataObject$
|
createSuccessfulRemoteDataObject$
|
||||||
} from '../../shared/remote-data.utils';
|
} from '../../shared/remote-data.utils';
|
||||||
import { AuthService } from '../../core/auth/auth.service';
|
|
||||||
import { createPaginatedList } from '../../shared/testing/utils.test';
|
import { createPaginatedList } from '../../shared/testing/utils.test';
|
||||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||||
import { ServerResponseService } from '../../core/services/server-response.service';
|
import { ServerResponseService } from '../../core/services/server-response.service';
|
||||||
@@ -57,7 +56,6 @@ const mockSignpostingLinks: SignpostingLink[] = [mocklink, mocklink2];
|
|||||||
describe('ItemPageComponent', () => {
|
describe('ItemPageComponent', () => {
|
||||||
let comp: ItemPageComponent;
|
let comp: ItemPageComponent;
|
||||||
let fixture: ComponentFixture<ItemPageComponent>;
|
let fixture: ComponentFixture<ItemPageComponent>;
|
||||||
let authService: AuthService;
|
|
||||||
let authorizationDataService: AuthorizationDataService;
|
let authorizationDataService: AuthorizationDataService;
|
||||||
let serverResponseService: jasmine.SpyObj<ServerResponseService>;
|
let serverResponseService: jasmine.SpyObj<ServerResponseService>;
|
||||||
let signpostingDataService: jasmine.SpyObj<SignpostingDataService>;
|
let signpostingDataService: jasmine.SpyObj<SignpostingDataService>;
|
||||||
@@ -74,10 +72,6 @@ describe('ItemPageComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
authService = jasmine.createSpyObj('authService', {
|
|
||||||
isAuthenticated: observableOf(true),
|
|
||||||
setRedirectUrl: {}
|
|
||||||
});
|
|
||||||
authorizationDataService = jasmine.createSpyObj('authorizationDataService', {
|
authorizationDataService = jasmine.createSpyObj('authorizationDataService', {
|
||||||
isAuthorized: observableOf(false),
|
isAuthorized: observableOf(false),
|
||||||
});
|
});
|
||||||
@@ -107,7 +101,6 @@ describe('ItemPageComponent', () => {
|
|||||||
{ provide: ItemDataService, useValue: {} },
|
{ provide: ItemDataService, useValue: {} },
|
||||||
{ provide: MetadataService, useValue: mockMetadataService },
|
{ provide: MetadataService, useValue: mockMetadataService },
|
||||||
{ provide: Router, useValue: {} },
|
{ provide: Router, useValue: {} },
|
||||||
{ provide: AuthService, useValue: authService },
|
|
||||||
{ provide: AuthorizationDataService, useValue: authorizationDataService },
|
{ provide: AuthorizationDataService, useValue: authorizationDataService },
|
||||||
{ provide: ServerResponseService, useValue: serverResponseService },
|
{ provide: ServerResponseService, useValue: serverResponseService },
|
||||||
{ provide: SignpostingDataService, useValue: signpostingDataService },
|
{ provide: SignpostingDataService, useValue: signpostingDataService },
|
||||||
|
@@ -11,9 +11,7 @@ import { Item } from '../../core/shared/item.model';
|
|||||||
import { fadeInOut } from '../../shared/animations/fade';
|
import { fadeInOut } from '../../shared/animations/fade';
|
||||||
import { getAllSucceededRemoteDataPayload } from '../../core/shared/operators';
|
import { getAllSucceededRemoteDataPayload } from '../../core/shared/operators';
|
||||||
import { ViewMode } from '../../core/shared/view-mode.model';
|
import { ViewMode } from '../../core/shared/view-mode.model';
|
||||||
import { AuthService } from '../../core/auth/auth.service';
|
|
||||||
import { getItemPageRoute } from '../item-page-routing-paths';
|
import { getItemPageRoute } from '../item-page-routing-paths';
|
||||||
import { redirectOn4xx } from '../../core/shared/authorized.operators';
|
|
||||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||||
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
||||||
import { ServerResponseService } from '../../core/services/server-response.service';
|
import { ServerResponseService } from '../../core/services/server-response.service';
|
||||||
@@ -72,7 +70,6 @@ export class ItemPageComponent implements OnInit, OnDestroy {
|
|||||||
protected route: ActivatedRoute,
|
protected route: ActivatedRoute,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
protected items: ItemDataService,
|
protected items: ItemDataService,
|
||||||
protected authService: AuthService,
|
|
||||||
protected authorizationService: AuthorizationDataService,
|
protected authorizationService: AuthorizationDataService,
|
||||||
protected responseService: ServerResponseService,
|
protected responseService: ServerResponseService,
|
||||||
protected signpostingDataService: SignpostingDataService,
|
protected signpostingDataService: SignpostingDataService,
|
||||||
@@ -88,7 +85,6 @@ export class ItemPageComponent implements OnInit, OnDestroy {
|
|||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.itemRD$ = this.route.data.pipe(
|
this.itemRD$ = this.route.data.pipe(
|
||||||
map((data) => data.dso as RemoteData<Item>),
|
map((data) => data.dso as RemoteData<Item>),
|
||||||
redirectOn4xx(this.router, this.authService)
|
|
||||||
);
|
);
|
||||||
this.itemPageRoute$ = this.itemRD$.pipe(
|
this.itemPageRoute$ = this.itemRD$.pipe(
|
||||||
getAllSucceededRemoteDataPayload(),
|
getAllSucceededRemoteDataPayload(),
|
||||||
|
Reference in New Issue
Block a user