From 9ea67b1b36148099c1835ea852006889ce21b390 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Wed, 10 Nov 2021 09:37:11 +0100 Subject: [PATCH 1/9] [CST-4873] Fix issue with request a copy functionality route --- src/app/item-page/item-page-routing.module.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/item-page/item-page-routing.module.ts b/src/app/item-page/item-page-routing.module.ts index 2c6631dd1a..7d7912bb42 100644 --- a/src/app/item-page/item-page-routing.module.ts +++ b/src/app/item-page/item-page-routing.module.ts @@ -15,6 +15,7 @@ import { ThemedItemPageComponent } from './simple/themed-item-page.component'; import { ThemedFullItemPageComponent } from './full/themed-full-item-page.component'; import { VersionPageComponent } from './version-page/version-page/version-page.component'; import { BitstreamRequestACopyPageComponent } from '../shared/bitstream-request-a-copy-page/bitstream-request-a-copy-page.component'; +import { REQUEST_COPY_MODULE_PATH } from '../app-routing-paths'; @NgModule({ imports: [ @@ -47,7 +48,7 @@ import { BitstreamRequestACopyPageComponent } from '../shared/bitstream-request- canActivate: [AuthenticatedGuard] }, { - path: ':request-a-copy', + path: REQUEST_COPY_MODULE_PATH, component: BitstreamRequestACopyPageComponent, } ], From dd6ec048015424189479dc935b54975fd818c0ef Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Wed, 10 Nov 2021 11:47:39 +0100 Subject: [PATCH 2/9] Fix menu icon i18n messages --- src/assets/i18n/en.json5 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index 4b06895664..5cd42bc24c 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -2430,7 +2430,7 @@ "menu.section.icon.control_panel": "Control Panel menu section", - "menu.section.icon.curation_task": "Curation Task menu section", + "menu.section.icon.curation_tasks": "Curation Task menu section", "menu.section.icon.edit": "Edit menu section", @@ -2450,6 +2450,8 @@ "menu.section.icon.statistics_task": "Statistics Task menu section", + "menu.section.icon.workflow": "Administer workflow menu section", + "menu.section.icon.unpin": "Unpin sidebar", From 2503b39897b26041d305ccf64427f56949ef2b62 Mon Sep 17 00:00:00 2001 From: Tim Donohue Date: Thu, 11 Nov 2021 16:25:19 -0600 Subject: [PATCH 3/9] Sync with DSpace/DSpace docker-compose setup --- docker/docker-compose-rest.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker/docker-compose-rest.yml b/docker/docker-compose-rest.yml index c99e469941..370ccbbdf1 100644 --- a/docker/docker-compose-rest.yml +++ b/docker/docker-compose-rest.yml @@ -81,15 +81,22 @@ services: # Keep Solr data directory between reboots - solr_data:/var/solr/data # Initialize all DSpace Solr cores using the mounted local configsets (see above), then start Solr + # * First, run precreate-core to create the core (if it doesn't yet exist). If exists already, this is a no-op + # * Second, copy updated configs from mounted configsets to this core. If it already existed, this updates core + # to the latest configs. If it's a newly created core, this is a no-op. entrypoint: - /bin/bash - '-c' - | init-var-solr precreate-core authority /opt/solr/server/solr/configsets/dspace/authority + cp -r -u /opt/solr/server/solr/configsets/dspace/authority/* authority precreate-core oai /opt/solr/server/solr/configsets/dspace/oai + cp -r -u /opt/solr/server/solr/configsets/dspace/oai/* oai precreate-core search /opt/solr/server/solr/configsets/dspace/search + cp -r -u /opt/solr/server/solr/configsets/dspace/search/* search precreate-core statistics /opt/solr/server/solr/configsets/dspace/statistics + cp -r -u /opt/solr/server/solr/configsets/dspace/statistics/* statistics exec solr -f volumes: assetstore: From 2151d1af58d7f1acaaefa95d6127d2d2dd0fcdd8 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Mon, 15 Nov 2021 18:49:13 +0100 Subject: [PATCH 4/9] [DSC-287] Fix error message --- src/assets/i18n/en.json5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index ebdb2ef4bc..fede29a047 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -16,7 +16,7 @@ "500.page-internal-server-error": "Service Unavailable", - "500.help": "The server is temporarily unable to service yourrequest due to maintenance downtime or capacityproblems. Please try again later.", + "500.help": "The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.", "500.link.home-page": "Take me to the home page", From 25a51c97644a81cef0504faf11859074711a477b Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Mon, 15 Nov 2021 18:52:33 +0100 Subject: [PATCH 5/9] [DSC-287] Add test to guard --- .../server-check/server-check.guard.spec.ts | 47 +++++++++++++++++-- .../core/server-check/server-check.guard.ts | 20 ++++---- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/app/core/server-check/server-check.guard.spec.ts b/src/app/core/server-check/server-check.guard.spec.ts index fc072cd73c..976021dcdb 100644 --- a/src/app/core/server-check/server-check.guard.spec.ts +++ b/src/app/core/server-check/server-check.guard.spec.ts @@ -1,16 +1,55 @@ -import { TestBed } from '@angular/core/testing'; - import { ServerCheckGuard } from './server-check.guard'; +import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; +import { first } from 'rxjs/operators'; +import { getPageInternalServerErrorRoute } from '../../app-routing-paths'; describe('ServerCheckGuard', () => { let guard: ServerCheckGuard; + let router; + let rootDataServiceStub: any; + + rootDataServiceStub = jasmine.createSpyObj('RootDataService', { + findRoot: jasmine.createSpy('findRoot') + }); + router = jasmine.createSpyObj('Router', { + navigateByUrl: jasmine.createSpy('navigateByUrl') + }); beforeEach(() => { - TestBed.configureTestingModule({}); - guard = TestBed.inject(ServerCheckGuard); + guard = new ServerCheckGuard(router, rootDataServiceStub); }); it('should be created', () => { expect(guard).toBeTruthy(); }); + + describe('when root endpoint has succeeded', () => { + beforeEach(() => { + rootDataServiceStub.findRoot.and.returnValue(createSuccessfulRemoteDataObject$({})); + }); + + it('should not redirect to error page', () => { + guard.canActivate({} as any, {} as any).pipe( + first() + ).subscribe((canActivate: boolean) => { + expect(canActivate).toEqual(true); + expect(router.navigateByUrl).not.toHaveBeenCalled(); + }); + }); + }); + + describe('when root endpoint has not succeeded', () => { + beforeEach(() => { + rootDataServiceStub.findRoot.and.returnValue(createFailedRemoteDataObject$()); + }); + + it('should redirect to error page', () => { + guard.canActivate({} as any, {} as any).pipe( + first() + ).subscribe((canActivate: boolean) => { + expect(canActivate).toEqual(false); + expect(router.navigateByUrl).toHaveBeenCalledWith(getPageInternalServerErrorRoute()); + }); + }); + }); }); diff --git a/src/app/core/server-check/server-check.guard.ts b/src/app/core/server-check/server-check.guard.ts index 32ff57ebb3..478a710567 100644 --- a/src/app/core/server-check/server-check.guard.ts +++ b/src/app/core/server-check/server-check.guard.ts @@ -1,26 +1,30 @@ import { Injectable } from '@angular/core'; -import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router'; +import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router'; + import { Observable } from 'rxjs'; -import { RootDataService } from '../data/root-data.service'; import { map, tap } from 'rxjs/operators'; + +import { RootDataService } from '../data/root-data.service'; import { RemoteData } from '../data/remote-data'; import { getPageInternalServerErrorRoute } from '../../app-routing-paths'; -import { Router } from '@angular/router'; +import { getFirstCompletedRemoteData } from '../shared/operators'; @Injectable({ providedIn: 'root' }) export class ServerCheckGuard implements CanActivate { - constructor(private router: Router,private rootDataService: RootDataService) {} + constructor(private router: Router, private rootDataService: RootDataService) { + } canActivate( route: ActivatedRouteSnapshot, - state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { + state: RouterStateSnapshot): Observable { return this.rootDataService.findRoot().pipe( - map( (res: RemoteData) => res.hasSucceeded ), - tap( (responsehasSucceeded: boolean) => { - if (!responsehasSucceeded) { + getFirstCompletedRemoteData(), + map((res: RemoteData) => res.hasSucceeded), + tap((hasSucceeded: boolean) => { + if (!hasSucceeded) { this.router.navigateByUrl(getPageInternalServerErrorRoute()); } }), From 81c4403ee6c6a37ab5ce99974e997446aca4edca Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Mon, 15 Nov 2021 19:02:10 +0100 Subject: [PATCH 6/9] [DSC-287] reformat app-routing.module code --- src/app/app-routing.module.ts | 363 +++++++++++++++++----------------- 1 file changed, 185 insertions(+), 178 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 7941adc35c..fcf9cd034a 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -11,10 +11,11 @@ import { FORBIDDEN_PATH, FORGOT_PASSWORD_PATH, INFO_MODULE_PATH, + LEGACY_BITSTREAM_MODULE_PATH, PROFILE_MODULE_PATH, REGISTER_PATH, + REQUEST_COPY_MODULE_PATH, WORKFLOW_ITEM_MODULE_PATH, - LEGACY_BITSTREAM_MODULE_PATH, REQUEST_COPY_MODULE_PATH, } from './app-routing-paths'; import { COLLECTION_MODULE_PATH } from './collection-page/collection-page-routing-paths'; import { COMMUNITY_MODULE_PATH } from './community-page/community-page-routing-paths'; @@ -29,187 +30,193 @@ import { GroupAdministratorGuard } from './core/data/feature-authorization/featu import { ThemedPageInternalServerErrorComponent } from './page-internal-server-error/themed-page-internal-server-error.component'; import { ServerCheckGuard } from './core/server-check/server-check.guard'; - @NgModule({ imports: [ RouterModule.forRoot([{ path: '', canActivate: [AuthBlockingGuard], - children: [ - { path: '', redirectTo: '/home', pathMatch: 'full' }, - { path: 'reload/:rnd', component: ThemedPageNotFoundComponent, pathMatch: 'full', canActivate: [ServerCheckGuard, ReloadGuard] }, - { - path: 'home', - loadChildren: () => import('./home-page/home-page.module') - .then((m) => m.HomePageModule), - data: { showBreadcrumbs: false }, - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'community-list', - loadChildren: () => import('./community-list-page/community-list-page.module') - .then((m) => m.CommunityListPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'id', - loadChildren: () => import('./lookup-by-id/lookup-by-id.module') - .then((m) => m.LookupIdModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'handle', - loadChildren: () => import('./lookup-by-id/lookup-by-id.module') - .then((m) => m.LookupIdModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: REGISTER_PATH, - loadChildren: () => import('./register-page/register-page.module') - .then((m) => m.RegisterPageModule), - canActivate: [ServerCheckGuard, SiteRegisterGuard] - }, - { - path: FORGOT_PASSWORD_PATH, - loadChildren: () => import('./forgot-password/forgot-password.module') - .then((m) => m.ForgotPasswordModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: COMMUNITY_MODULE_PATH, - loadChildren: () => import('./community-page/community-page.module') - .then((m) => m.CommunityPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: COLLECTION_MODULE_PATH, - loadChildren: () => import('./collection-page/collection-page.module') - .then((m) => m.CollectionPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: ITEM_MODULE_PATH, - loadChildren: () => import('./item-page/item-page.module') - .then((m) => m.ItemPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { path: 'entities/:entity-type', - loadChildren: () => import('./item-page/item-page.module') - .then((m) => m.ItemPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: LEGACY_BITSTREAM_MODULE_PATH, - loadChildren: () => import('./bitstream-page/bitstream-page.module') - .then((m) => m.BitstreamPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: BITSTREAM_MODULE_PATH, - loadChildren: () => import('./bitstream-page/bitstream-page.module') - .then((m) => m.BitstreamPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'mydspace', - loadChildren: () => import('./my-dspace-page/my-dspace-page.module') - .then((m) => m.MyDSpacePageModule), - canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'search', - loadChildren: () => import('./search-page/search-page-routing.module') - .then((m) => m.SearchPageRoutingModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'browse', - loadChildren: () => import('./browse-by/browse-by-page.module') - .then((m) => m.BrowseByPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: ADMIN_MODULE_PATH, - loadChildren: () => import('./admin/admin.module') - .then((m) => m.AdminModule), - canActivate: [ServerCheckGuard, SiteAdministratorGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'login', - loadChildren: () => import('./login-page/login-page.module') - .then((m) => m.LoginPageModule), - canActivate: [ServerCheckGuard] - }, - { - path: 'logout', - loadChildren: () => import('./logout-page/logout-page.module') - .then((m) => m.LogoutPageModule), - canActivate: [ServerCheckGuard] - }, - { - path: 'submit', - loadChildren: () => import('./submit-page/submit-page.module') - .then((m) => m.SubmitPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'import-external', - loadChildren: () => import('./import-external-page/import-external-page.module') - .then((m) => m.ImportExternalPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'workspaceitems', - loadChildren: () => import('./workspaceitems-edit-page/workspaceitems-edit-page.module') - .then((m) => m.WorkspaceitemsEditPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: WORKFLOW_ITEM_MODULE_PATH, - loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page.module') - .then((m) => m.WorkflowItemsEditPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: PROFILE_MODULE_PATH, - loadChildren: () => import('./profile-page/profile-page.module') - .then((m) => m.ProfilePageModule), - canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: PROCESS_MODULE_PATH, - loadChildren: () => import('./process-page/process-page.module') - .then((m) => m.ProcessPageModule), - canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: INFO_MODULE_PATH, - loadChildren: () => import('./info/info.module').then((m) => m.InfoModule), - canActivate: [ServerCheckGuard] - }, - { - path: REQUEST_COPY_MODULE_PATH, - loadChildren: () => import('./request-copy/request-copy.module').then((m) => m.RequestCopyModule), - canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: FORBIDDEN_PATH, - component: ThemedForbiddenComponent - }, - { - path: 'statistics', - loadChildren: () => import('./statistics-page/statistics-page-routing.module') - .then((m) => m.StatisticsPageRoutingModule), - canActivate: [ServerCheckGuard] - }, - { - path: ACCESS_CONTROL_MODULE_PATH, - loadChildren: () => import('./access-control/access-control.module').then((m) => m.AccessControlModule), - canActivate: [ServerCheckGuard, GroupAdministratorGuard], - }, - { path: '500', component: ThemedPageInternalServerErrorComponent }, - { path: '**', pathMatch: 'full', component: ThemedPageNotFoundComponent }, - ]} - ],{ + children: [ + { path: '', redirectTo: '/home', pathMatch: 'full' }, + { + path: 'reload/:rnd', + component: ThemedPageNotFoundComponent, + pathMatch: 'full', + canActivate: [ServerCheckGuard, ReloadGuard] + }, + { + path: 'home', + loadChildren: () => import('./home-page/home-page.module') + .then((m) => m.HomePageModule), + data: { showBreadcrumbs: false }, + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'community-list', + loadChildren: () => import('./community-list-page/community-list-page.module') + .then((m) => m.CommunityListPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'id', + loadChildren: () => import('./lookup-by-id/lookup-by-id.module') + .then((m) => m.LookupIdModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'handle', + loadChildren: () => import('./lookup-by-id/lookup-by-id.module') + .then((m) => m.LookupIdModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: REGISTER_PATH, + loadChildren: () => import('./register-page/register-page.module') + .then((m) => m.RegisterPageModule), + canActivate: [ServerCheckGuard, SiteRegisterGuard] + }, + { + path: FORGOT_PASSWORD_PATH, + loadChildren: () => import('./forgot-password/forgot-password.module') + .then((m) => m.ForgotPasswordModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: COMMUNITY_MODULE_PATH, + loadChildren: () => import('./community-page/community-page.module') + .then((m) => m.CommunityPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: COLLECTION_MODULE_PATH, + loadChildren: () => import('./collection-page/collection-page.module') + .then((m) => m.CollectionPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: ITEM_MODULE_PATH, + loadChildren: () => import('./item-page/item-page.module') + .then((m) => m.ItemPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'entities/:entity-type', + loadChildren: () => import('./item-page/item-page.module') + .then((m) => m.ItemPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: LEGACY_BITSTREAM_MODULE_PATH, + loadChildren: () => import('./bitstream-page/bitstream-page.module') + .then((m) => m.BitstreamPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: BITSTREAM_MODULE_PATH, + loadChildren: () => import('./bitstream-page/bitstream-page.module') + .then((m) => m.BitstreamPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'mydspace', + loadChildren: () => import('./my-dspace-page/my-dspace-page.module') + .then((m) => m.MyDSpacePageModule), + canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'search', + loadChildren: () => import('./search-page/search-page-routing.module') + .then((m) => m.SearchPageRoutingModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'browse', + loadChildren: () => import('./browse-by/browse-by-page.module') + .then((m) => m.BrowseByPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: ADMIN_MODULE_PATH, + loadChildren: () => import('./admin/admin.module') + .then((m) => m.AdminModule), + canActivate: [ServerCheckGuard, SiteAdministratorGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'login', + loadChildren: () => import('./login-page/login-page.module') + .then((m) => m.LoginPageModule), + canActivate: [ServerCheckGuard] + }, + { + path: 'logout', + loadChildren: () => import('./logout-page/logout-page.module') + .then((m) => m.LogoutPageModule), + canActivate: [ServerCheckGuard] + }, + { + path: 'submit', + loadChildren: () => import('./submit-page/submit-page.module') + .then((m) => m.SubmitPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'import-external', + loadChildren: () => import('./import-external-page/import-external-page.module') + .then((m) => m.ImportExternalPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'workspaceitems', + loadChildren: () => import('./workspaceitems-edit-page/workspaceitems-edit-page.module') + .then((m) => m.WorkspaceitemsEditPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: WORKFLOW_ITEM_MODULE_PATH, + loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page.module') + .then((m) => m.WorkflowItemsEditPageModule), + canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: PROFILE_MODULE_PATH, + loadChildren: () => import('./profile-page/profile-page.module') + .then((m) => m.ProfilePageModule), + canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: PROCESS_MODULE_PATH, + loadChildren: () => import('./process-page/process-page.module') + .then((m) => m.ProcessPageModule), + canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: INFO_MODULE_PATH, + loadChildren: () => import('./info/info.module').then((m) => m.InfoModule), + canActivate: [ServerCheckGuard] + }, + { + path: REQUEST_COPY_MODULE_PATH, + loadChildren: () => import('./request-copy/request-copy.module').then((m) => m.RequestCopyModule), + canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: FORBIDDEN_PATH, + component: ThemedForbiddenComponent + }, + { + path: 'statistics', + loadChildren: () => import('./statistics-page/statistics-page-routing.module') + .then((m) => m.StatisticsPageRoutingModule), + canActivate: [ServerCheckGuard] + }, + { + path: ACCESS_CONTROL_MODULE_PATH, + loadChildren: () => import('./access-control/access-control.module').then((m) => m.AccessControlModule), + canActivate: [ServerCheckGuard, GroupAdministratorGuard], + }, + { path: '500', component: ThemedPageInternalServerErrorComponent }, + { path: '**', pathMatch: 'full', component: ThemedPageNotFoundComponent }, + ] + } + ], { onSameUrlNavigation: 'reload', }) ], From 76ddce723990984fcb5fef3d6647c4a4338ba254 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Tue, 16 Nov 2021 17:38:20 +0100 Subject: [PATCH 7/9] [DSC-287] fix test --- .../server-check/server-check.guard.spec.ts | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/app/core/server-check/server-check.guard.spec.ts b/src/app/core/server-check/server-check.guard.spec.ts index 976021dcdb..a9c03d1cd7 100644 --- a/src/app/core/server-check/server-check.guard.spec.ts +++ b/src/app/core/server-check/server-check.guard.spec.ts @@ -1,12 +1,16 @@ import { ServerCheckGuard } from './server-check.guard'; import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils'; -import { first } from 'rxjs/operators'; +import { take } from 'rxjs/operators'; import { getPageInternalServerErrorRoute } from '../../app-routing-paths'; +import { Router } from '@angular/router'; +import { RootDataService } from '../data/root-data.service'; +import { Root } from '../data/root.model'; +import SpyObj = jasmine.SpyObj; describe('ServerCheckGuard', () => { let guard: ServerCheckGuard; - let router; - let rootDataServiceStub: any; + let router: SpyObj; + let rootDataServiceStub: SpyObj; rootDataServiceStub = jasmine.createSpyObj('RootDataService', { findRoot: jasmine.createSpy('findRoot') @@ -19,18 +23,22 @@ describe('ServerCheckGuard', () => { guard = new ServerCheckGuard(router, rootDataServiceStub); }); + afterEach(() => { + router.navigateByUrl.calls.reset(); + }); + it('should be created', () => { expect(guard).toBeTruthy(); }); describe('when root endpoint has succeeded', () => { beforeEach(() => { - rootDataServiceStub.findRoot.and.returnValue(createSuccessfulRemoteDataObject$({})); + rootDataServiceStub.findRoot.and.returnValue(createSuccessfulRemoteDataObject$({} as any)); }); it('should not redirect to error page', () => { guard.canActivate({} as any, {} as any).pipe( - first() + take(1) ).subscribe((canActivate: boolean) => { expect(canActivate).toEqual(true); expect(router.navigateByUrl).not.toHaveBeenCalled(); @@ -40,12 +48,12 @@ describe('ServerCheckGuard', () => { describe('when root endpoint has not succeeded', () => { beforeEach(() => { - rootDataServiceStub.findRoot.and.returnValue(createFailedRemoteDataObject$()); + rootDataServiceStub.findRoot.and.returnValue(createFailedRemoteDataObject$()); }); it('should redirect to error page', () => { guard.canActivate({} as any, {} as any).pipe( - first() + take(1) ).subscribe((canActivate: boolean) => { expect(canActivate).toEqual(false); expect(router.navigateByUrl).toHaveBeenCalledWith(getPageInternalServerErrorRoute()); From a323aefc2279a5c1184c07cbe0cd1180eeadf809 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Tue, 16 Nov 2021 19:13:57 +0100 Subject: [PATCH 8/9] [DSC-287] change app-routing.module.ts inn order to have ServerCheckGuard configured once --- src/app/app-routing.module.ts | 370 +++++++++++++++++----------------- 1 file changed, 186 insertions(+), 184 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index fcf9cd034a..63fa669206 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -32,190 +32,192 @@ import { ServerCheckGuard } from './core/server-check/server-check.guard'; @NgModule({ imports: [ - RouterModule.forRoot([{ - path: '', canActivate: [AuthBlockingGuard], - children: [ - { path: '', redirectTo: '/home', pathMatch: 'full' }, - { - path: 'reload/:rnd', - component: ThemedPageNotFoundComponent, - pathMatch: 'full', - canActivate: [ServerCheckGuard, ReloadGuard] - }, - { - path: 'home', - loadChildren: () => import('./home-page/home-page.module') - .then((m) => m.HomePageModule), - data: { showBreadcrumbs: false }, - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'community-list', - loadChildren: () => import('./community-list-page/community-list-page.module') - .then((m) => m.CommunityListPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'id', - loadChildren: () => import('./lookup-by-id/lookup-by-id.module') - .then((m) => m.LookupIdModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'handle', - loadChildren: () => import('./lookup-by-id/lookup-by-id.module') - .then((m) => m.LookupIdModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: REGISTER_PATH, - loadChildren: () => import('./register-page/register-page.module') - .then((m) => m.RegisterPageModule), - canActivate: [ServerCheckGuard, SiteRegisterGuard] - }, - { - path: FORGOT_PASSWORD_PATH, - loadChildren: () => import('./forgot-password/forgot-password.module') - .then((m) => m.ForgotPasswordModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: COMMUNITY_MODULE_PATH, - loadChildren: () => import('./community-page/community-page.module') - .then((m) => m.CommunityPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: COLLECTION_MODULE_PATH, - loadChildren: () => import('./collection-page/collection-page.module') - .then((m) => m.CollectionPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: ITEM_MODULE_PATH, - loadChildren: () => import('./item-page/item-page.module') - .then((m) => m.ItemPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'entities/:entity-type', - loadChildren: () => import('./item-page/item-page.module') - .then((m) => m.ItemPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: LEGACY_BITSTREAM_MODULE_PATH, - loadChildren: () => import('./bitstream-page/bitstream-page.module') - .then((m) => m.BitstreamPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: BITSTREAM_MODULE_PATH, - loadChildren: () => import('./bitstream-page/bitstream-page.module') - .then((m) => m.BitstreamPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'mydspace', - loadChildren: () => import('./my-dspace-page/my-dspace-page.module') - .then((m) => m.MyDSpacePageModule), - canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'search', - loadChildren: () => import('./search-page/search-page-routing.module') - .then((m) => m.SearchPageRoutingModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'browse', - loadChildren: () => import('./browse-by/browse-by-page.module') - .then((m) => m.BrowseByPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: ADMIN_MODULE_PATH, - loadChildren: () => import('./admin/admin.module') - .then((m) => m.AdminModule), - canActivate: [ServerCheckGuard, SiteAdministratorGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'login', - loadChildren: () => import('./login-page/login-page.module') - .then((m) => m.LoginPageModule), - canActivate: [ServerCheckGuard] - }, - { - path: 'logout', - loadChildren: () => import('./logout-page/logout-page.module') - .then((m) => m.LogoutPageModule), - canActivate: [ServerCheckGuard] - }, - { - path: 'submit', - loadChildren: () => import('./submit-page/submit-page.module') - .then((m) => m.SubmitPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'import-external', - loadChildren: () => import('./import-external-page/import-external-page.module') - .then((m) => m.ImportExternalPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: 'workspaceitems', - loadChildren: () => import('./workspaceitems-edit-page/workspaceitems-edit-page.module') - .then((m) => m.WorkspaceitemsEditPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: WORKFLOW_ITEM_MODULE_PATH, - loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page.module') - .then((m) => m.WorkflowItemsEditPageModule), - canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: PROFILE_MODULE_PATH, - loadChildren: () => import('./profile-page/profile-page.module') - .then((m) => m.ProfilePageModule), - canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: PROCESS_MODULE_PATH, - loadChildren: () => import('./process-page/process-page.module') - .then((m) => m.ProcessPageModule), - canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: INFO_MODULE_PATH, - loadChildren: () => import('./info/info.module').then((m) => m.InfoModule), - canActivate: [ServerCheckGuard] - }, - { - path: REQUEST_COPY_MODULE_PATH, - loadChildren: () => import('./request-copy/request-copy.module').then((m) => m.RequestCopyModule), - canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] - }, - { - path: FORBIDDEN_PATH, - component: ThemedForbiddenComponent - }, - { - path: 'statistics', - loadChildren: () => import('./statistics-page/statistics-page-routing.module') - .then((m) => m.StatisticsPageRoutingModule), - canActivate: [ServerCheckGuard] - }, - { - path: ACCESS_CONTROL_MODULE_PATH, - loadChildren: () => import('./access-control/access-control.module').then((m) => m.AccessControlModule), - canActivate: [ServerCheckGuard, GroupAdministratorGuard], - }, - { path: '500', component: ThemedPageInternalServerErrorComponent }, - { path: '**', pathMatch: 'full', component: ThemedPageNotFoundComponent }, - ] - } + RouterModule.forRoot([ + { path: '500', component: ThemedPageInternalServerErrorComponent }, + { + path: '', canActivate: [ServerCheckGuard, AuthBlockingGuard], + children: [ + { path: '', redirectTo: '/home', pathMatch: 'full' }, + { + path: 'reload/:rnd', + component: ThemedPageNotFoundComponent, + pathMatch: 'full', + canActivate: [ReloadGuard] + }, + { + path: 'home', + loadChildren: () => import('./home-page/home-page.module') + .then((m) => m.HomePageModule), + data: { showBreadcrumbs: false }, + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: 'community-list', + loadChildren: () => import('./community-list-page/community-list-page.module') + .then((m) => m.CommunityListPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: 'id', + loadChildren: () => import('./lookup-by-id/lookup-by-id.module') + .then((m) => m.LookupIdModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: 'handle', + loadChildren: () => import('./lookup-by-id/lookup-by-id.module') + .then((m) => m.LookupIdModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: REGISTER_PATH, + loadChildren: () => import('./register-page/register-page.module') + .then((m) => m.RegisterPageModule), + canActivate: [SiteRegisterGuard] + }, + { + path: FORGOT_PASSWORD_PATH, + loadChildren: () => import('./forgot-password/forgot-password.module') + .then((m) => m.ForgotPasswordModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: COMMUNITY_MODULE_PATH, + loadChildren: () => import('./community-page/community-page.module') + .then((m) => m.CommunityPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: COLLECTION_MODULE_PATH, + loadChildren: () => import('./collection-page/collection-page.module') + .then((m) => m.CollectionPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: ITEM_MODULE_PATH, + loadChildren: () => import('./item-page/item-page.module') + .then((m) => m.ItemPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: 'entities/:entity-type', + loadChildren: () => import('./item-page/item-page.module') + .then((m) => m.ItemPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: LEGACY_BITSTREAM_MODULE_PATH, + loadChildren: () => import('./bitstream-page/bitstream-page.module') + .then((m) => m.BitstreamPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: BITSTREAM_MODULE_PATH, + loadChildren: () => import('./bitstream-page/bitstream-page.module') + .then((m) => m.BitstreamPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: 'mydspace', + loadChildren: () => import('./my-dspace-page/my-dspace-page.module') + .then((m) => m.MyDSpacePageModule), + canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'search', + loadChildren: () => import('./search-page/search-page-routing.module') + .then((m) => m.SearchPageRoutingModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: 'browse', + loadChildren: () => import('./browse-by/browse-by-page.module') + .then((m) => m.BrowseByPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: ADMIN_MODULE_PATH, + loadChildren: () => import('./admin/admin.module') + .then((m) => m.AdminModule), + canActivate: [SiteAdministratorGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: 'login', + loadChildren: () => import('./login-page/login-page.module') + .then((m) => m.LoginPageModule), + canActivate: [ServerCheckGuard] + }, + { + path: 'logout', + loadChildren: () => import('./logout-page/logout-page.module') + .then((m) => m.LogoutPageModule), + canActivate: [ServerCheckGuard] + }, + { + path: 'submit', + loadChildren: () => import('./submit-page/submit-page.module') + .then((m) => m.SubmitPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: 'import-external', + loadChildren: () => import('./import-external-page/import-external-page.module') + .then((m) => m.ImportExternalPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: 'workspaceitems', + loadChildren: () => import('./workspaceitems-edit-page/workspaceitems-edit-page.module') + .then((m) => m.WorkspaceitemsEditPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: WORKFLOW_ITEM_MODULE_PATH, + loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page.module') + .then((m) => m.WorkflowItemsEditPageModule), + canActivate: [EndUserAgreementCurrentUserGuard] + }, + { + path: PROFILE_MODULE_PATH, + loadChildren: () => import('./profile-page/profile-page.module') + .then((m) => m.ProfilePageModule), + canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: PROCESS_MODULE_PATH, + loadChildren: () => import('./process-page/process-page.module') + .then((m) => m.ProcessPageModule), + canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: INFO_MODULE_PATH, + loadChildren: () => import('./info/info.module').then((m) => m.InfoModule), + canActivate: [ServerCheckGuard] + }, + { + path: REQUEST_COPY_MODULE_PATH, + loadChildren: () => import('./request-copy/request-copy.module').then((m) => m.RequestCopyModule), + canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard] + }, + { + path: FORBIDDEN_PATH, + component: ThemedForbiddenComponent + }, + { + path: 'statistics', + loadChildren: () => import('./statistics-page/statistics-page-routing.module') + .then((m) => m.StatisticsPageRoutingModule), + canActivate: [ServerCheckGuard] + }, + { + path: ACCESS_CONTROL_MODULE_PATH, + loadChildren: () => import('./access-control/access-control.module').then((m) => m.AccessControlModule), + canActivate: [GroupAdministratorGuard], + }, + + { path: '**', pathMatch: 'full', component: ThemedPageNotFoundComponent }, + ] + } ], { onSameUrlNavigation: 'reload', }) From 92e9f79f09d4e6551abcea79c0fc4dc492f33213 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Wed, 17 Nov 2021 09:37:49 +0100 Subject: [PATCH 9/9] [DSC-287] optimize code and add typedoc --- src/app/app-routing.module.ts | 16 ++++++---------- src/app/core/server-check/server-check.guard.ts | 7 +++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 63fa669206..49e96a028a 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -11,6 +11,7 @@ import { FORBIDDEN_PATH, FORGOT_PASSWORD_PATH, INFO_MODULE_PATH, + INTERNAL_SERVER_ERROR, LEGACY_BITSTREAM_MODULE_PATH, PROFILE_MODULE_PATH, REGISTER_PATH, @@ -33,7 +34,7 @@ import { ServerCheckGuard } from './core/server-check/server-check.guard'; @NgModule({ imports: [ RouterModule.forRoot([ - { path: '500', component: ThemedPageInternalServerErrorComponent }, + { path: INTERNAL_SERVER_ERROR, component: ThemedPageInternalServerErrorComponent }, { path: '', canActivate: [ServerCheckGuard, AuthBlockingGuard], children: [ @@ -144,14 +145,12 @@ import { ServerCheckGuard } from './core/server-check/server-check.guard'; { path: 'login', loadChildren: () => import('./login-page/login-page.module') - .then((m) => m.LoginPageModule), - canActivate: [ServerCheckGuard] + .then((m) => m.LoginPageModule) }, { path: 'logout', loadChildren: () => import('./logout-page/logout-page.module') - .then((m) => m.LogoutPageModule), - canActivate: [ServerCheckGuard] + .then((m) => m.LogoutPageModule) }, { path: 'submit', @@ -191,8 +190,7 @@ import { ServerCheckGuard } from './core/server-check/server-check.guard'; }, { path: INFO_MODULE_PATH, - loadChildren: () => import('./info/info.module').then((m) => m.InfoModule), - canActivate: [ServerCheckGuard] + loadChildren: () => import('./info/info.module').then((m) => m.InfoModule) }, { path: REQUEST_COPY_MODULE_PATH, @@ -206,15 +204,13 @@ import { ServerCheckGuard } from './core/server-check/server-check.guard'; { path: 'statistics', loadChildren: () => import('./statistics-page/statistics-page-routing.module') - .then((m) => m.StatisticsPageRoutingModule), - canActivate: [ServerCheckGuard] + .then((m) => m.StatisticsPageRoutingModule) }, { path: ACCESS_CONTROL_MODULE_PATH, loadChildren: () => import('./access-control/access-control.module').then((m) => m.AccessControlModule), canActivate: [GroupAdministratorGuard], }, - { path: '**', pathMatch: 'full', component: ThemedPageNotFoundComponent }, ] } diff --git a/src/app/core/server-check/server-check.guard.ts b/src/app/core/server-check/server-check.guard.ts index 478a710567..b7982eee9a 100644 --- a/src/app/core/server-check/server-check.guard.ts +++ b/src/app/core/server-check/server-check.guard.ts @@ -12,10 +12,17 @@ import { getFirstCompletedRemoteData } from '../shared/operators'; @Injectable({ providedIn: 'root' }) +/** + * A guard that checks if root api endpoint is reachable. + * If not redirect to 500 error page + */ export class ServerCheckGuard implements CanActivate { constructor(private router: Router, private rootDataService: RootDataService) { } + /** + * True when root api endpoint is reachable. + */ canActivate( route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable {