Skip to content

Commit 249cac4

Browse files
115427: Fixed edit item pages not redirecting to 404 with invalid id
1 parent e6086e1 commit 249cac4

6 files changed

Lines changed: 14 additions & 28 deletions

File tree

src/app/item-page/full/full-item-page.component.spec.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { BehaviorSubject, of as observableOf } from 'rxjs';
1515
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
1616
import { By } from '@angular/platform-browser';
1717
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
18-
import { AuthService } from '../../core/auth/auth.service';
1918
import { createPaginatedList } from '../../shared/testing/utils.test';
2019
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
2120
import { createRelationshipsObservable } from '../simple/item-types/shared/item.component.spec';
@@ -54,7 +53,6 @@ describe('FullItemPageComponent', () => {
5453
let comp: FullItemPageComponent;
5554
let fixture: ComponentFixture<FullItemPageComponent>;
5655

57-
let authService: AuthService;
5856
let routeStub: ActivatedRouteStub;
5957
let routeData;
6058
let authorizationDataService: AuthorizationDataService;
@@ -75,11 +73,6 @@ describe('FullItemPageComponent', () => {
7573
};
7674

7775
beforeEach(waitForAsync(() => {
78-
authService = jasmine.createSpyObj('authService', {
79-
isAuthenticated: observableOf(true),
80-
setRedirectUrl: {}
81-
});
82-
8376
routeData = {
8477
dso: createSuccessfulRemoteDataObject(mockItem),
8578
};
@@ -117,7 +110,6 @@ describe('FullItemPageComponent', () => {
117110
{ provide: ActivatedRoute, useValue: routeStub },
118111
{ provide: ItemDataService, useValue: {} },
119112
{ provide: MetadataService, useValue: metadataServiceStub },
120-
{ provide: AuthService, useValue: authService },
121113
{ provide: AuthorizationDataService, useValue: authorizationDataService },
122114
{ provide: ServerResponseService, useValue: serverResponseService },
123115
{ provide: SignpostingDataService, useValue: signpostingDataService },

src/app/item-page/full/full-item-page.component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { Item } from '../../core/shared/item.model';
1313

1414
import { fadeInOut } from '../../shared/animations/fade';
1515
import { hasValue } from '../../shared/empty.util';
16-
import { AuthService } from '../../core/auth/auth.service';
1716
import { Location } from '@angular/common';
1817
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
1918
import { ServerResponseService } from '../../core/services/server-response.service';
@@ -49,15 +48,14 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
4948
protected route: ActivatedRoute,
5049
protected router: Router,
5150
protected items: ItemDataService,
52-
protected authService: AuthService,
5351
protected authorizationService: AuthorizationDataService,
5452
protected _location: Location,
5553
protected responseService: ServerResponseService,
5654
protected signpostingDataService: SignpostingDataService,
5755
protected linkHeadService: LinkHeadService,
5856
@Inject(PLATFORM_ID) protected platformId: string,
5957
) {
60-
super(route, router, items, authService, authorizationService, responseService, signpostingDataService, linkHeadService, platformId);
58+
super(route, router, items, authorizationService, responseService, signpostingDataService, linkHeadService, platformId);
6159
}
6260

6361
/*** AoT inheritance fix, will hopefully be resolved in the near future **/

src/app/item-page/item-page.resolver.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
33
import { DSpaceObject } from '../core/shared/dspace-object.model';
44
import { MetadataValueFilter } from '../core/shared/metadata.models';
55
import { first } from 'rxjs/operators';
6-
import { Router } from '@angular/router';
6+
import { Router, RouterModule } from '@angular/router';
77
import { TestBed } from '@angular/core/testing';
8-
import { RouterTestingModule } from '@angular/router/testing';
8+
import { AuthServiceStub } from '../shared/testing/auth-service.stub';
9+
import { AuthService } from '../core/auth/auth.service';
910

1011
describe('ItemPageResolver', () => {
1112
beforeEach(() => {
1213
TestBed.configureTestingModule({
13-
imports: [RouterTestingModule.withRoutes([{
14+
imports: [RouterModule.forRoot([{
1415
path: 'entities/:entity-type/:id',
1516
component: {} as any
1617
}])]
@@ -21,7 +22,8 @@ describe('ItemPageResolver', () => {
2122
let resolver: ItemPageResolver;
2223
let itemService: any;
2324
let store: any;
24-
let router: any;
25+
let router: Router;
26+
let authService: AuthServiceStub;
2527

2628
const uuid = '1234-65487-12354-1235';
2729
let item: DSpaceObject;
@@ -41,7 +43,8 @@ describe('ItemPageResolver', () => {
4143
store = jasmine.createSpyObj('store', {
4244
dispatch: {},
4345
});
44-
resolver = new ItemPageResolver(itemService, store, router);
46+
authService = new AuthServiceStub();
47+
resolver = new ItemPageResolver(itemService, store, router, authService as unknown as AuthService);
4548
});
4649

4750
it('should redirect to the correct route for the entity type', (done) => {

src/app/item-page/item-page.resolver.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { map } from 'rxjs/operators';
99
import { hasValue } from '../shared/empty.util';
1010
import { getItemPageRoute } from './item-page-routing-paths';
1111
import { ItemResolver } from './item.resolver';
12+
import { redirectOn4xx } from '../core/shared/authorized.operators';
13+
import { AuthService } from '../core/auth/auth.service';
1214

1315
/**
1416
* 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 {
1921
constructor(
2022
protected itemService: ItemDataService,
2123
protected store: Store<any>,
22-
protected router: Router
24+
protected router: Router,
25+
protected authService: AuthService,
2326
) {
2427
super(itemService, store, router);
2528
}
@@ -33,6 +36,7 @@ export class ItemPageResolver extends ItemResolver {
3336
*/
3437
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<RemoteData<Item>> {
3538
return super.resolve(route, state).pipe(
39+
redirectOn4xx(this.router, this.authService),
3640
map((rd: RemoteData<Item>) => {
3741
if (rd.hasSucceeded && hasValue(rd.payload)) {
3842
const thisRoute = state.url;

src/app/item-page/simple/item-page.component.spec.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
createSuccessfulRemoteDataObject,
2020
createSuccessfulRemoteDataObject$
2121
} from '../../shared/remote-data.utils';
22-
import { AuthService } from '../../core/auth/auth.service';
2322
import { createPaginatedList } from '../../shared/testing/utils.test';
2423
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
2524
import { ServerResponseService } from '../../core/services/server-response.service';
@@ -57,7 +56,6 @@ const mockSignpostingLinks: SignpostingLink[] = [mocklink, mocklink2];
5756
describe('ItemPageComponent', () => {
5857
let comp: ItemPageComponent;
5958
let fixture: ComponentFixture<ItemPageComponent>;
60-
let authService: AuthService;
6159
let authorizationDataService: AuthorizationDataService;
6260
let serverResponseService: jasmine.SpyObj<ServerResponseService>;
6361
let signpostingDataService: jasmine.SpyObj<SignpostingDataService>;
@@ -74,10 +72,6 @@ describe('ItemPageComponent', () => {
7472
});
7573

7674
beforeEach(waitForAsync(() => {
77-
authService = jasmine.createSpyObj('authService', {
78-
isAuthenticated: observableOf(true),
79-
setRedirectUrl: {}
80-
});
8175
authorizationDataService = jasmine.createSpyObj('authorizationDataService', {
8276
isAuthorized: observableOf(false),
8377
});
@@ -107,7 +101,6 @@ describe('ItemPageComponent', () => {
107101
{ provide: ItemDataService, useValue: {} },
108102
{ provide: MetadataService, useValue: mockMetadataService },
109103
{ provide: Router, useValue: {} },
110-
{ provide: AuthService, useValue: authService },
111104
{ provide: AuthorizationDataService, useValue: authorizationDataService },
112105
{ provide: ServerResponseService, useValue: serverResponseService },
113106
{ provide: SignpostingDataService, useValue: signpostingDataService },

src/app/item-page/simple/item-page.component.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import { Item } from '../../core/shared/item.model';
1111
import { fadeInOut } from '../../shared/animations/fade';
1212
import { getAllSucceededRemoteDataPayload } from '../../core/shared/operators';
1313
import { ViewMode } from '../../core/shared/view-mode.model';
14-
import { AuthService } from '../../core/auth/auth.service';
1514
import { getItemPageRoute } from '../item-page-routing-paths';
16-
import { redirectOn4xx } from '../../core/shared/authorized.operators';
1715
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
1816
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
1917
import { ServerResponseService } from '../../core/services/server-response.service';
@@ -72,7 +70,6 @@ export class ItemPageComponent implements OnInit, OnDestroy {
7270
protected route: ActivatedRoute,
7371
protected router: Router,
7472
protected items: ItemDataService,
75-
protected authService: AuthService,
7673
protected authorizationService: AuthorizationDataService,
7774
protected responseService: ServerResponseService,
7875
protected signpostingDataService: SignpostingDataService,
@@ -88,7 +85,6 @@ export class ItemPageComponent implements OnInit, OnDestroy {
8885
ngOnInit(): void {
8986
this.itemRD$ = this.route.data.pipe(
9087
map((data) => data.dso as RemoteData<Item>),
91-
redirectOn4xx(this.router, this.authService)
9288
);
9389
this.itemPageRoute$ = this.itemRD$.pipe(
9490
getAllSucceededRemoteDataPayload(),

0 commit comments

Comments
 (0)