Merge branch 'DSC-287-Show-an-error-page-if-the-REST-API-is-not-available' of https://bitbucket.org/4Science/dspace-angular into DSC-287-Show-an-error-page-if-the-REST-API-is-not-available

This commit is contained in:
Rezart Vata
2021-12-01 18:51:01 +01:00
6 changed files with 129 additions and 56 deletions

View File

@@ -81,15 +81,22 @@ services:
# Keep Solr data directory between reboots # Keep Solr data directory between reboots
- solr_data:/var/solr/data - solr_data:/var/solr/data
# Initialize all DSpace Solr cores using the mounted local configsets (see above), then start Solr # 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: entrypoint:
- /bin/bash - /bin/bash
- '-c' - '-c'
- | - |
init-var-solr init-var-solr
precreate-core authority /opt/solr/server/solr/configsets/dspace/authority 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 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 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 precreate-core statistics /opt/solr/server/solr/configsets/dspace/statistics
cp -r -u /opt/solr/server/solr/configsets/dspace/statistics/* statistics
exec solr -f exec solr -f
volumes: volumes:
assetstore: assetstore:

View File

@@ -11,10 +11,12 @@ import {
FORBIDDEN_PATH, FORBIDDEN_PATH,
FORGOT_PASSWORD_PATH, FORGOT_PASSWORD_PATH,
INFO_MODULE_PATH, INFO_MODULE_PATH,
INTERNAL_SERVER_ERROR,
LEGACY_BITSTREAM_MODULE_PATH,
PROFILE_MODULE_PATH, PROFILE_MODULE_PATH,
REGISTER_PATH, REGISTER_PATH,
REQUEST_COPY_MODULE_PATH,
WORKFLOW_ITEM_MODULE_PATH, WORKFLOW_ITEM_MODULE_PATH,
LEGACY_BITSTREAM_MODULE_PATH, REQUEST_COPY_MODULE_PATH,
} from './app-routing-paths'; } from './app-routing-paths';
import { COLLECTION_MODULE_PATH } from './collection-page/collection-page-routing-paths'; import { COLLECTION_MODULE_PATH } from './collection-page/collection-page-routing-paths';
import { COMMUNITY_MODULE_PATH } from './community-page/community-page-routing-paths'; import { COMMUNITY_MODULE_PATH } from './community-page/community-page-routing-paths';
@@ -29,167 +31,171 @@ import { GroupAdministratorGuard } from './core/data/feature-authorization/featu
import { ThemedPageInternalServerErrorComponent } from './page-internal-server-error/themed-page-internal-server-error.component'; import { ThemedPageInternalServerErrorComponent } from './page-internal-server-error/themed-page-internal-server-error.component';
import { ServerCheckGuard } from './core/server-check/server-check.guard'; import { ServerCheckGuard } from './core/server-check/server-check.guard';
@NgModule({ @NgModule({
imports: [ imports: [
RouterModule.forRoot([{ RouterModule.forRoot([
path: '', canActivate: [AuthBlockingGuard], { path: INTERNAL_SERVER_ERROR, component: ThemedPageInternalServerErrorComponent },
{
path: '', canActivate: [ServerCheckGuard, AuthBlockingGuard],
children: [ children: [
{ path: '', redirectTo: '/home', pathMatch: 'full' }, { path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'reload/:rnd', component: ThemedPageNotFoundComponent, pathMatch: 'full', canActivate: [ServerCheckGuard, ReloadGuard] }, {
path: 'reload/:rnd',
component: ThemedPageNotFoundComponent,
pathMatch: 'full',
canActivate: [ReloadGuard]
},
{ {
path: 'home', path: 'home',
loadChildren: () => import('./home-page/home-page.module') loadChildren: () => import('./home-page/home-page.module')
.then((m) => m.HomePageModule), .then((m) => m.HomePageModule),
data: { showBreadcrumbs: false }, data: { showBreadcrumbs: false },
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'community-list', path: 'community-list',
loadChildren: () => import('./community-list-page/community-list-page.module') loadChildren: () => import('./community-list-page/community-list-page.module')
.then((m) => m.CommunityListPageModule), .then((m) => m.CommunityListPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'id', path: 'id',
loadChildren: () => import('./lookup-by-id/lookup-by-id.module') loadChildren: () => import('./lookup-by-id/lookup-by-id.module')
.then((m) => m.LookupIdModule), .then((m) => m.LookupIdModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'handle', path: 'handle',
loadChildren: () => import('./lookup-by-id/lookup-by-id.module') loadChildren: () => import('./lookup-by-id/lookup-by-id.module')
.then((m) => m.LookupIdModule), .then((m) => m.LookupIdModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: REGISTER_PATH, path: REGISTER_PATH,
loadChildren: () => import('./register-page/register-page.module') loadChildren: () => import('./register-page/register-page.module')
.then((m) => m.RegisterPageModule), .then((m) => m.RegisterPageModule),
canActivate: [ServerCheckGuard, SiteRegisterGuard] canActivate: [SiteRegisterGuard]
}, },
{ {
path: FORGOT_PASSWORD_PATH, path: FORGOT_PASSWORD_PATH,
loadChildren: () => import('./forgot-password/forgot-password.module') loadChildren: () => import('./forgot-password/forgot-password.module')
.then((m) => m.ForgotPasswordModule), .then((m) => m.ForgotPasswordModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: COMMUNITY_MODULE_PATH, path: COMMUNITY_MODULE_PATH,
loadChildren: () => import('./community-page/community-page.module') loadChildren: () => import('./community-page/community-page.module')
.then((m) => m.CommunityPageModule), .then((m) => m.CommunityPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: COLLECTION_MODULE_PATH, path: COLLECTION_MODULE_PATH,
loadChildren: () => import('./collection-page/collection-page.module') loadChildren: () => import('./collection-page/collection-page.module')
.then((m) => m.CollectionPageModule), .then((m) => m.CollectionPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: ITEM_MODULE_PATH, path: ITEM_MODULE_PATH,
loadChildren: () => import('./item-page/item-page.module') loadChildren: () => import('./item-page/item-page.module')
.then((m) => m.ItemPageModule), .then((m) => m.ItemPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ path: 'entities/:entity-type', {
path: 'entities/:entity-type',
loadChildren: () => import('./item-page/item-page.module') loadChildren: () => import('./item-page/item-page.module')
.then((m) => m.ItemPageModule), .then((m) => m.ItemPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: LEGACY_BITSTREAM_MODULE_PATH, path: LEGACY_BITSTREAM_MODULE_PATH,
loadChildren: () => import('./bitstream-page/bitstream-page.module') loadChildren: () => import('./bitstream-page/bitstream-page.module')
.then((m) => m.BitstreamPageModule), .then((m) => m.BitstreamPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: BITSTREAM_MODULE_PATH, path: BITSTREAM_MODULE_PATH,
loadChildren: () => import('./bitstream-page/bitstream-page.module') loadChildren: () => import('./bitstream-page/bitstream-page.module')
.then((m) => m.BitstreamPageModule), .then((m) => m.BitstreamPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'mydspace', path: 'mydspace',
loadChildren: () => import('./my-dspace-page/my-dspace-page.module') loadChildren: () => import('./my-dspace-page/my-dspace-page.module')
.then((m) => m.MyDSpacePageModule), .then((m) => m.MyDSpacePageModule),
canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'search', path: 'search',
loadChildren: () => import('./search-page/search-page-routing.module') loadChildren: () => import('./search-page/search-page-routing.module')
.then((m) => m.SearchPageRoutingModule), .then((m) => m.SearchPageRoutingModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'browse', path: 'browse',
loadChildren: () => import('./browse-by/browse-by-page.module') loadChildren: () => import('./browse-by/browse-by-page.module')
.then((m) => m.BrowseByPageModule), .then((m) => m.BrowseByPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: ADMIN_MODULE_PATH, path: ADMIN_MODULE_PATH,
loadChildren: () => import('./admin/admin.module') loadChildren: () => import('./admin/admin.module')
.then((m) => m.AdminModule), .then((m) => m.AdminModule),
canActivate: [ServerCheckGuard, SiteAdministratorGuard, EndUserAgreementCurrentUserGuard] canActivate: [SiteAdministratorGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'login', path: 'login',
loadChildren: () => import('./login-page/login-page.module') loadChildren: () => import('./login-page/login-page.module')
.then((m) => m.LoginPageModule), .then((m) => m.LoginPageModule)
canActivate: [ServerCheckGuard]
}, },
{ {
path: 'logout', path: 'logout',
loadChildren: () => import('./logout-page/logout-page.module') loadChildren: () => import('./logout-page/logout-page.module')
.then((m) => m.LogoutPageModule), .then((m) => m.LogoutPageModule)
canActivate: [ServerCheckGuard]
}, },
{ {
path: 'submit', path: 'submit',
loadChildren: () => import('./submit-page/submit-page.module') loadChildren: () => import('./submit-page/submit-page.module')
.then((m) => m.SubmitPageModule), .then((m) => m.SubmitPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'import-external', path: 'import-external',
loadChildren: () => import('./import-external-page/import-external-page.module') loadChildren: () => import('./import-external-page/import-external-page.module')
.then((m) => m.ImportExternalPageModule), .then((m) => m.ImportExternalPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: 'workspaceitems', path: 'workspaceitems',
loadChildren: () => import('./workspaceitems-edit-page/workspaceitems-edit-page.module') loadChildren: () => import('./workspaceitems-edit-page/workspaceitems-edit-page.module')
.then((m) => m.WorkspaceitemsEditPageModule), .then((m) => m.WorkspaceitemsEditPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: WORKFLOW_ITEM_MODULE_PATH, path: WORKFLOW_ITEM_MODULE_PATH,
loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page.module') loadChildren: () => import('./workflowitems-edit-page/workflowitems-edit-page.module')
.then((m) => m.WorkflowItemsEditPageModule), .then((m) => m.WorkflowItemsEditPageModule),
canActivate: [ServerCheckGuard, EndUserAgreementCurrentUserGuard] canActivate: [EndUserAgreementCurrentUserGuard]
}, },
{ {
path: PROFILE_MODULE_PATH, path: PROFILE_MODULE_PATH,
loadChildren: () => import('./profile-page/profile-page.module') loadChildren: () => import('./profile-page/profile-page.module')
.then((m) => m.ProfilePageModule), .then((m) => m.ProfilePageModule),
canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: PROCESS_MODULE_PATH, path: PROCESS_MODULE_PATH,
loadChildren: () => import('./process-page/process-page.module') loadChildren: () => import('./process-page/process-page.module')
.then((m) => m.ProcessPageModule), .then((m) => m.ProcessPageModule),
canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: INFO_MODULE_PATH, path: INFO_MODULE_PATH,
loadChildren: () => import('./info/info.module').then((m) => m.InfoModule), loadChildren: () => import('./info/info.module').then((m) => m.InfoModule)
canActivate: [ServerCheckGuard]
}, },
{ {
path: REQUEST_COPY_MODULE_PATH, path: REQUEST_COPY_MODULE_PATH,
loadChildren: () => import('./request-copy/request-copy.module').then((m) => m.RequestCopyModule), loadChildren: () => import('./request-copy/request-copy.module').then((m) => m.RequestCopyModule),
canActivate: [ServerCheckGuard, AuthenticatedGuard, EndUserAgreementCurrentUserGuard] canActivate: [AuthenticatedGuard, EndUserAgreementCurrentUserGuard]
}, },
{ {
path: FORBIDDEN_PATH, path: FORBIDDEN_PATH,
@@ -198,18 +204,17 @@ import { ServerCheckGuard } from './core/server-check/server-check.guard';
{ {
path: 'statistics', path: 'statistics',
loadChildren: () => import('./statistics-page/statistics-page-routing.module') loadChildren: () => import('./statistics-page/statistics-page-routing.module')
.then((m) => m.StatisticsPageRoutingModule), .then((m) => m.StatisticsPageRoutingModule)
canActivate: [ServerCheckGuard]
}, },
{ {
path: ACCESS_CONTROL_MODULE_PATH, path: ACCESS_CONTROL_MODULE_PATH,
loadChildren: () => import('./access-control/access-control.module').then((m) => m.AccessControlModule), loadChildren: () => import('./access-control/access-control.module').then((m) => m.AccessControlModule),
canActivate: [ServerCheckGuard, GroupAdministratorGuard], canActivate: [GroupAdministratorGuard],
}, },
{ path: '500', component: ThemedPageInternalServerErrorComponent },
{ path: '**', pathMatch: 'full', component: ThemedPageNotFoundComponent }, { path: '**', pathMatch: 'full', component: ThemedPageNotFoundComponent },
]} ]
],{ }
], {
onSameUrlNavigation: 'reload', onSameUrlNavigation: 'reload',
}) })
], ],

View File

@@ -1,16 +1,63 @@
import { TestBed } from '@angular/core/testing';
import { ServerCheckGuard } from './server-check.guard'; import { ServerCheckGuard } from './server-check.guard';
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
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', () => { describe('ServerCheckGuard', () => {
let guard: ServerCheckGuard; let guard: ServerCheckGuard;
let router: SpyObj<Router>;
let rootDataServiceStub: SpyObj<RootDataService>;
rootDataServiceStub = jasmine.createSpyObj('RootDataService', {
findRoot: jasmine.createSpy('findRoot')
});
router = jasmine.createSpyObj('Router', {
navigateByUrl: jasmine.createSpy('navigateByUrl')
});
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({}); guard = new ServerCheckGuard(router, rootDataServiceStub);
guard = TestBed.inject(ServerCheckGuard); });
afterEach(() => {
router.navigateByUrl.calls.reset();
}); });
it('should be created', () => { it('should be created', () => {
expect(guard).toBeTruthy(); expect(guard).toBeTruthy();
}); });
describe('when root endpoint has succeeded', () => {
beforeEach(() => {
rootDataServiceStub.findRoot.and.returnValue(createSuccessfulRemoteDataObject$<Root>({} as any));
});
it('should not redirect to error page', () => {
guard.canActivate({} as any, {} as any).pipe(
take(1)
).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$<Root>());
});
it('should redirect to error page', () => {
guard.canActivate({} as any, {} as any).pipe(
take(1)
).subscribe((canActivate: boolean) => {
expect(canActivate).toEqual(false);
expect(router.navigateByUrl).toHaveBeenCalledWith(getPageInternalServerErrorRoute());
});
});
});
}); });

View File

@@ -1,26 +1,37 @@
import { Injectable } from '@angular/core'; 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 { Observable } from 'rxjs';
import { RootDataService } from '../data/root-data.service';
import { map, tap } from 'rxjs/operators'; import { map, tap } from 'rxjs/operators';
import { RootDataService } from '../data/root-data.service';
import { RemoteData } from '../data/remote-data'; import { RemoteData } from '../data/remote-data';
import { getPageInternalServerErrorRoute } from '../../app-routing-paths'; import { getPageInternalServerErrorRoute } from '../../app-routing-paths';
import { Router } from '@angular/router'; import { getFirstCompletedRemoteData } from '../shared/operators';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
/**
* A guard that checks if root api endpoint is reachable.
* If not redirect to 500 error page
*/
export class ServerCheckGuard implements CanActivate { export class ServerCheckGuard implements CanActivate {
constructor(private router: Router,private rootDataService: RootDataService) {} constructor(private router: Router, private rootDataService: RootDataService) {
}
/**
* True when root api endpoint is reachable.
*/
canActivate( canActivate(
route: ActivatedRouteSnapshot, route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { state: RouterStateSnapshot): Observable<boolean> {
return this.rootDataService.findRoot().pipe( return this.rootDataService.findRoot().pipe(
map( (res: RemoteData<any>) => res.hasSucceeded ), getFirstCompletedRemoteData(),
tap( (responsehasSucceeded: boolean) => { map((res: RemoteData<any>) => res.hasSucceeded),
if (!responsehasSucceeded) { tap((hasSucceeded: boolean) => {
if (!hasSucceeded) {
this.router.navigateByUrl(getPageInternalServerErrorRoute()); this.router.navigateByUrl(getPageInternalServerErrorRoute());
} }
}), }),

View File

@@ -15,6 +15,7 @@ import { ThemedItemPageComponent } from './simple/themed-item-page.component';
import { ThemedFullItemPageComponent } from './full/themed-full-item-page.component'; import { ThemedFullItemPageComponent } from './full/themed-full-item-page.component';
import { VersionPageComponent } from './version-page/version-page/version-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 { BitstreamRequestACopyPageComponent } from '../shared/bitstream-request-a-copy-page/bitstream-request-a-copy-page.component';
import { REQUEST_COPY_MODULE_PATH } from '../app-routing-paths';
@NgModule({ @NgModule({
imports: [ imports: [
@@ -47,7 +48,7 @@ import { BitstreamRequestACopyPageComponent } from '../shared/bitstream-request-
canActivate: [AuthenticatedGuard] canActivate: [AuthenticatedGuard]
}, },
{ {
path: ':request-a-copy', path: REQUEST_COPY_MODULE_PATH,
component: BitstreamRequestACopyPageComponent, component: BitstreamRequestACopyPageComponent,
} }
], ],

View File

@@ -16,7 +16,7 @@
"500.page-internal-server-error": "Service Unavailable", "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", "500.link.home-page": "Take me to the home page",
@@ -2435,7 +2435,7 @@
"menu.section.icon.control_panel": "Control Panel menu section", "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", "menu.section.icon.edit": "Edit menu section",
@@ -2455,6 +2455,8 @@
"menu.section.icon.statistics_task": "Statistics Task menu section", "menu.section.icon.statistics_task": "Statistics Task menu section",
"menu.section.icon.workflow": "Administer workflow menu section",
"menu.section.icon.unpin": "Unpin sidebar", "menu.section.icon.unpin": "Unpin sidebar",