mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
Merge branch 'main' into CST-4320
# Conflicts: # src/assets/i18n/en.json5
This commit is contained in:
@@ -167,7 +167,6 @@ export class BrowseByMetadataPageComponent implements OnInit {
|
|||||||
* @param value The value of the browse-entry to display items for
|
* @param value The value of the browse-entry to display items for
|
||||||
*/
|
*/
|
||||||
updatePageWithItems(searchOptions: BrowseEntrySearchOptions, value: string) {
|
updatePageWithItems(searchOptions: BrowseEntrySearchOptions, value: string) {
|
||||||
console.log('updatePAge', searchOptions);
|
|
||||||
this.items$ = this.browseService.getBrowseItemsFor(value, searchOptions);
|
this.items$ = this.browseService.getBrowseItemsFor(value, searchOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { delay, distinctUntilChanged, filter, take } from 'rxjs/operators';
|
import { delay, distinctUntilChanged, filter, take, withLatestFrom } from 'rxjs/operators';
|
||||||
import {
|
import {
|
||||||
AfterViewInit,
|
AfterViewInit,
|
||||||
ChangeDetectionStrategy,
|
ChangeDetectionStrategy,
|
||||||
@@ -38,6 +38,8 @@ import { ThemeService } from './shared/theme-support/theme.service';
|
|||||||
import { BASE_THEME_NAME } from './shared/theme-support/theme.constants';
|
import { BASE_THEME_NAME } from './shared/theme-support/theme.constants';
|
||||||
import { DEFAULT_THEME_CONFIG } from './shared/theme-support/theme.effects';
|
import { DEFAULT_THEME_CONFIG } from './shared/theme-support/theme.effects';
|
||||||
import { BreadcrumbsService } from './breadcrumbs/breadcrumbs.service';
|
import { BreadcrumbsService } from './breadcrumbs/breadcrumbs.service';
|
||||||
|
import { IdleModalComponent } from './shared/idle-modal/idle-modal.component';
|
||||||
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-app',
|
selector: 'ds-app',
|
||||||
@@ -70,6 +72,11 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
isThemeLoading$: BehaviorSubject<boolean> = new BehaviorSubject(false);
|
isThemeLoading$: BehaviorSubject<boolean> = new BehaviorSubject(false);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the idle modal is is currently open
|
||||||
|
*/
|
||||||
|
idleModalOpen: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(NativeWindowService) private _window: NativeWindowRef,
|
@Inject(NativeWindowService) private _window: NativeWindowRef,
|
||||||
@Inject(DOCUMENT) private document: any,
|
@Inject(DOCUMENT) private document: any,
|
||||||
@@ -87,6 +94,7 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
private windowService: HostWindowService,
|
private windowService: HostWindowService,
|
||||||
private localeService: LocaleService,
|
private localeService: LocaleService,
|
||||||
private breadcrumbsService: BreadcrumbsService,
|
private breadcrumbsService: BreadcrumbsService,
|
||||||
|
private modalService: NgbModal,
|
||||||
@Optional() private cookiesService: KlaroService,
|
@Optional() private cookiesService: KlaroService,
|
||||||
@Optional() private googleAnalyticsService: GoogleAnalyticsService,
|
@Optional() private googleAnalyticsService: GoogleAnalyticsService,
|
||||||
) {
|
) {
|
||||||
@@ -108,6 +116,11 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isPlatformBrowser(this.platformId)) {
|
||||||
|
this.authService.trackTokenExpiration();
|
||||||
|
this.trackIdleModal();
|
||||||
|
}
|
||||||
|
|
||||||
// Load all the languages that are defined as active from the config file
|
// Load all the languages that are defined as active from the config file
|
||||||
translate.addLangs(environment.languages.filter((LangConfig) => LangConfig.active === true).map((a) => a.code));
|
translate.addLangs(environment.languages.filter((LangConfig) => LangConfig.active === true).map((a) => a.code));
|
||||||
|
|
||||||
@@ -130,7 +143,6 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
console.info(environment);
|
console.info(environment);
|
||||||
}
|
}
|
||||||
this.storeCSSVariables();
|
this.storeCSSVariables();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@@ -229,4 +241,23 @@ export class AppComponent implements OnInit, AfterViewInit {
|
|||||||
};
|
};
|
||||||
head.appendChild(link);
|
head.appendChild(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private trackIdleModal() {
|
||||||
|
const isIdle$ = this.authService.isUserIdle();
|
||||||
|
const isAuthenticated$ = this.authService.isAuthenticated();
|
||||||
|
isIdle$.pipe(withLatestFrom(isAuthenticated$))
|
||||||
|
.subscribe(([userIdle, authenticated]) => {
|
||||||
|
if (userIdle && authenticated) {
|
||||||
|
if (!this.idleModalOpen) {
|
||||||
|
const modalRef = this.modalService.open(IdleModalComponent, { ariaLabelledBy: 'idle-modal.header' });
|
||||||
|
this.idleModalOpen = true;
|
||||||
|
modalRef.componentInstance.response.pipe(take(1)).subscribe((closed: boolean) => {
|
||||||
|
if (closed) {
|
||||||
|
this.idleModalOpen = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -47,6 +47,7 @@ import { ThemedHeaderComponent } from './header/themed-header.component';
|
|||||||
import { ThemedFooterComponent } from './footer/themed-footer.component';
|
import { ThemedFooterComponent } from './footer/themed-footer.component';
|
||||||
import { ThemedBreadcrumbsComponent } from './breadcrumbs/themed-breadcrumbs.component';
|
import { ThemedBreadcrumbsComponent } from './breadcrumbs/themed-breadcrumbs.component';
|
||||||
import { ThemedHeaderNavbarWrapperComponent } from './header-nav-wrapper/themed-header-navbar-wrapper.component';
|
import { ThemedHeaderNavbarWrapperComponent } from './header-nav-wrapper/themed-header-navbar-wrapper.component';
|
||||||
|
import { IdleModalComponent } from './shared/idle-modal/idle-modal.component';
|
||||||
|
|
||||||
export function getBase() {
|
export function getBase() {
|
||||||
return environment.ui.nameSpace;
|
return environment.ui.nameSpace;
|
||||||
@@ -144,6 +145,7 @@ const DECLARATIONS = [
|
|||||||
ThemedBreadcrumbsComponent,
|
ThemedBreadcrumbsComponent,
|
||||||
ForbiddenComponent,
|
ForbiddenComponent,
|
||||||
ThemedForbiddenComponent,
|
ThemedForbiddenComponent,
|
||||||
|
IdleModalComponent
|
||||||
];
|
];
|
||||||
|
|
||||||
const EXPORTS = [
|
const EXPORTS = [
|
||||||
|
@@ -34,7 +34,9 @@ export const AuthActionTypes = {
|
|||||||
RETRIEVE_AUTHENTICATED_EPERSON: type('dspace/auth/RETRIEVE_AUTHENTICATED_EPERSON'),
|
RETRIEVE_AUTHENTICATED_EPERSON: type('dspace/auth/RETRIEVE_AUTHENTICATED_EPERSON'),
|
||||||
RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS: type('dspace/auth/RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS'),
|
RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS: type('dspace/auth/RETRIEVE_AUTHENTICATED_EPERSON_SUCCESS'),
|
||||||
RETRIEVE_AUTHENTICATED_EPERSON_ERROR: type('dspace/auth/RETRIEVE_AUTHENTICATED_EPERSON_ERROR'),
|
RETRIEVE_AUTHENTICATED_EPERSON_ERROR: type('dspace/auth/RETRIEVE_AUTHENTICATED_EPERSON_ERROR'),
|
||||||
REDIRECT_AFTER_LOGIN_SUCCESS: type('dspace/auth/REDIRECT_AFTER_LOGIN_SUCCESS')
|
REDIRECT_AFTER_LOGIN_SUCCESS: type('dspace/auth/REDIRECT_AFTER_LOGIN_SUCCESS'),
|
||||||
|
SET_USER_AS_IDLE: type('dspace/auth/SET_USER_AS_IDLE'),
|
||||||
|
UNSET_USER_AS_IDLE: type('dspace/auth/UNSET_USER_AS_IDLE')
|
||||||
};
|
};
|
||||||
|
|
||||||
/* tslint:disable:max-classes-per-file */
|
/* tslint:disable:max-classes-per-file */
|
||||||
@@ -404,6 +406,24 @@ export class RetrieveAuthenticatedEpersonErrorAction implements Action {
|
|||||||
this.payload = payload ;
|
this.payload = payload ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current user as being idle.
|
||||||
|
* @class SetUserAsIdleAction
|
||||||
|
* @implements {Action}
|
||||||
|
*/
|
||||||
|
export class SetUserAsIdleAction implements Action {
|
||||||
|
public type: string = AuthActionTypes.SET_USER_AS_IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unset the current user as being idle.
|
||||||
|
* @class UnsetUserAsIdleAction
|
||||||
|
* @implements {Action}
|
||||||
|
*/
|
||||||
|
export class UnsetUserAsIdleAction implements Action {
|
||||||
|
public type: string = AuthActionTypes.UNSET_USER_AS_IDLE;
|
||||||
|
}
|
||||||
/* tslint:enable:max-classes-per-file */
|
/* tslint:enable:max-classes-per-file */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -434,4 +454,7 @@ export type AuthActions
|
|||||||
| RetrieveAuthenticatedEpersonErrorAction
|
| RetrieveAuthenticatedEpersonErrorAction
|
||||||
| RetrieveAuthenticatedEpersonSuccessAction
|
| RetrieveAuthenticatedEpersonSuccessAction
|
||||||
| SetRedirectUrlAction
|
| SetRedirectUrlAction
|
||||||
| RedirectAfterLoginSuccessAction;
|
| RedirectAfterLoginSuccessAction
|
||||||
|
| SetUserAsIdleAction
|
||||||
|
| UnsetUserAsIdleAction;
|
||||||
|
|
||||||
|
@@ -1,7 +1,13 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable, NgZone } from '@angular/core';
|
||||||
|
|
||||||
import { combineLatest as observableCombineLatest, Observable, of as observableOf } from 'rxjs';
|
import {
|
||||||
import { catchError, filter, map, switchMap, take, tap } from 'rxjs/operators';
|
combineLatest as observableCombineLatest,
|
||||||
|
Observable,
|
||||||
|
of as observableOf,
|
||||||
|
timer,
|
||||||
|
asyncScheduler, queueScheduler
|
||||||
|
} from 'rxjs';
|
||||||
|
import { catchError, filter, map, switchMap, take, tap, observeOn } from 'rxjs/operators';
|
||||||
// import @ngrx
|
// import @ngrx
|
||||||
import { Actions, Effect, ofType } from '@ngrx/effects';
|
import { Actions, Effect, ofType } from '@ngrx/effects';
|
||||||
import { Action, select, Store } from '@ngrx/store';
|
import { Action, select, Store } from '@ngrx/store';
|
||||||
@@ -37,9 +43,19 @@ import {
|
|||||||
RetrieveAuthMethodsAction,
|
RetrieveAuthMethodsAction,
|
||||||
RetrieveAuthMethodsErrorAction,
|
RetrieveAuthMethodsErrorAction,
|
||||||
RetrieveAuthMethodsSuccessAction,
|
RetrieveAuthMethodsSuccessAction,
|
||||||
RetrieveTokenAction
|
RetrieveTokenAction, SetUserAsIdleAction
|
||||||
} from './auth.actions';
|
} from './auth.actions';
|
||||||
import { hasValue } from '../../shared/empty.util';
|
import { hasValue } from '../../shared/empty.util';
|
||||||
|
import { environment } from '../../../environments/environment';
|
||||||
|
import { RequestActionTypes } from '../data/request.actions';
|
||||||
|
import { NotificationsActionTypes } from '../../shared/notifications/notifications.actions';
|
||||||
|
import { LeaveZoneScheduler } from '../utilities/leave-zone.scheduler';
|
||||||
|
import { EnterZoneScheduler } from '../utilities/enter-zone.scheduler';
|
||||||
|
|
||||||
|
// Action Types that do not break/prevent the user from an idle state
|
||||||
|
const IDLE_TIMER_IGNORE_TYPES: string[]
|
||||||
|
= [...Object.values(AuthActionTypes).filter((t: string) => t !== AuthActionTypes.UNSET_USER_AS_IDLE),
|
||||||
|
...Object.values(RequestActionTypes), ...Object.values(NotificationsActionTypes)];
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthEffects {
|
export class AuthEffects {
|
||||||
@@ -242,13 +258,35 @@ export class AuthEffects {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For any action that is not in {@link IDLE_TIMER_IGNORE_TYPES} that comes in => Start the idleness timer
|
||||||
|
* If the idleness timer runs out (so no un-ignored action come through for that amount of time)
|
||||||
|
* => Return the action to set the user as idle ({@link SetUserAsIdleAction})
|
||||||
|
* @method trackIdleness
|
||||||
|
*/
|
||||||
|
@Effect()
|
||||||
|
public trackIdleness$: Observable<Action> = this.actions$.pipe(
|
||||||
|
filter((action: Action) => !IDLE_TIMER_IGNORE_TYPES.includes(action.type)),
|
||||||
|
// Using switchMap the effect will stop subscribing to the previous timer if a new action comes
|
||||||
|
// in, and start a new timer
|
||||||
|
switchMap(() =>
|
||||||
|
// Start a timer outside of Angular's zone
|
||||||
|
timer(environment.auth.ui.timeUntilIdle, new LeaveZoneScheduler(this.zone, asyncScheduler))
|
||||||
|
),
|
||||||
|
// Re-enter the zone to dispatch the action
|
||||||
|
observeOn(new EnterZoneScheduler(this.zone, queueScheduler)),
|
||||||
|
map(() => new SetUserAsIdleAction()),
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {Actions} actions$
|
* @param {Actions} actions$
|
||||||
|
* @param {NgZone} zone
|
||||||
* @param {AuthService} authService
|
* @param {AuthService} authService
|
||||||
* @param {Store} store
|
* @param {Store} store
|
||||||
*/
|
*/
|
||||||
constructor(private actions$: Actions,
|
constructor(private actions$: Actions,
|
||||||
|
private zone: NgZone,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private store: Store<AppState>) {
|
private store: Store<AppState>) {
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { Observable, of as observableOf, throwError as observableThrowError } from 'rxjs';
|
import { Observable, of as observableOf, throwError as observableThrowError } from 'rxjs';
|
||||||
|
|
||||||
import { catchError, filter, map } from 'rxjs/operators';
|
import { catchError, map } from 'rxjs/operators';
|
||||||
import { Injectable, Injector } from '@angular/core';
|
import { Injectable, Injector } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
HttpErrorResponse,
|
HttpErrorResponse,
|
||||||
@@ -12,14 +12,13 @@ import {
|
|||||||
HttpResponse,
|
HttpResponse,
|
||||||
HttpResponseBase
|
HttpResponseBase
|
||||||
} from '@angular/common/http';
|
} from '@angular/common/http';
|
||||||
import { find } from 'lodash';
|
|
||||||
|
|
||||||
import { AppState } from '../../app.reducer';
|
import { AppState } from '../../app.reducer';
|
||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
import { AuthStatus } from './models/auth-status.model';
|
import { AuthStatus } from './models/auth-status.model';
|
||||||
import { AuthTokenInfo } from './models/auth-token-info.model';
|
import { AuthTokenInfo } from './models/auth-token-info.model';
|
||||||
import { hasValue, isNotEmpty, isNotNull, isUndefined } from '../../shared/empty.util';
|
import { hasValue, isNotEmpty, isNotNull } from '../../shared/empty.util';
|
||||||
import { RedirectWhenTokenExpiredAction, RefreshTokenAction } from './auth.actions';
|
import { RedirectWhenTokenExpiredAction } from './auth.actions';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { AuthMethod } from './models/auth.method';
|
import { AuthMethod } from './models/auth.method';
|
||||||
@@ -28,7 +27,7 @@ import { AuthMethodType } from './models/auth.method-type';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthInterceptor implements HttpInterceptor {
|
export class AuthInterceptor implements HttpInterceptor {
|
||||||
|
|
||||||
// Intercetor is called twice per request,
|
// Interceptor is called twice per request,
|
||||||
// so to prevent RefreshTokenAction is dispatched twice
|
// so to prevent RefreshTokenAction is dispatched twice
|
||||||
// we're creating a refresh token request list
|
// we're creating a refresh token request list
|
||||||
protected refreshTokenRequestUrls = [];
|
protected refreshTokenRequestUrls = [];
|
||||||
@@ -216,23 +215,8 @@ export class AuthInterceptor implements HttpInterceptor {
|
|||||||
let authorization: string;
|
let authorization: string;
|
||||||
|
|
||||||
if (authService.isTokenExpired()) {
|
if (authService.isTokenExpired()) {
|
||||||
authService.setRedirectUrl(this.router.url);
|
|
||||||
// The access token is expired
|
|
||||||
// Redirect to the login route
|
|
||||||
this.store.dispatch(new RedirectWhenTokenExpiredAction('auth.messages.expired'));
|
|
||||||
return observableOf(null);
|
return observableOf(null);
|
||||||
} else if ((!this.isAuthRequest(req) || this.isLogoutResponse(req)) && isNotEmpty(token)) {
|
} else if ((!this.isAuthRequest(req) || this.isLogoutResponse(req)) && isNotEmpty(token)) {
|
||||||
// Intercept a request that is not to the authentication endpoint
|
|
||||||
authService.isTokenExpiring().pipe(
|
|
||||||
filter((isExpiring) => isExpiring))
|
|
||||||
.subscribe(() => {
|
|
||||||
// If the current request url is already in the refresh token request list, skip it
|
|
||||||
if (isUndefined(find(this.refreshTokenRequestUrls, req.url))) {
|
|
||||||
// When a token is about to expire, refresh it
|
|
||||||
this.store.dispatch(new RefreshTokenAction(token));
|
|
||||||
this.refreshTokenRequestUrls.push(req.url);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Get the auth header from the service.
|
// Get the auth header from the service.
|
||||||
authorization = authService.buildAuthHeader(token);
|
authorization = authService.buildAuthHeader(token);
|
||||||
let newHeaders = req.headers.set('authorization', authorization);
|
let newHeaders = req.headers.set('authorization', authorization);
|
||||||
|
@@ -23,7 +23,7 @@ import {
|
|||||||
RetrieveAuthMethodsAction,
|
RetrieveAuthMethodsAction,
|
||||||
RetrieveAuthMethodsErrorAction,
|
RetrieveAuthMethodsErrorAction,
|
||||||
RetrieveAuthMethodsSuccessAction,
|
RetrieveAuthMethodsSuccessAction,
|
||||||
SetRedirectUrlAction
|
SetRedirectUrlAction, SetUserAsIdleAction, UnsetUserAsIdleAction
|
||||||
} from './auth.actions';
|
} from './auth.actions';
|
||||||
import { AuthTokenInfo } from './models/auth-token-info.model';
|
import { AuthTokenInfo } from './models/auth-token-info.model';
|
||||||
import { EPersonMock } from '../../shared/testing/eperson.mock';
|
import { EPersonMock } from '../../shared/testing/eperson.mock';
|
||||||
@@ -44,6 +44,7 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new AuthenticateAction('user', 'password');
|
const action = new AuthenticateAction('user', 'password');
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -53,7 +54,8 @@ describe('authReducer', () => {
|
|||||||
blocking: true,
|
blocking: true,
|
||||||
error: undefined,
|
error: undefined,
|
||||||
loading: true,
|
loading: true,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
@@ -66,7 +68,8 @@ describe('authReducer', () => {
|
|||||||
error: undefined,
|
error: undefined,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new AuthenticationSuccessAction(mockTokenInfo);
|
const action = new AuthenticationSuccessAction(mockTokenInfo);
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -81,7 +84,8 @@ describe('authReducer', () => {
|
|||||||
error: undefined,
|
error: undefined,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new AuthenticationErrorAction(mockError);
|
const action = new AuthenticationErrorAction(mockError);
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -92,7 +96,8 @@ describe('authReducer', () => {
|
|||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
authToken: undefined,
|
authToken: undefined,
|
||||||
error: 'Test error message'
|
error: 'Test error message',
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
@@ -105,7 +110,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
error: undefined,
|
error: undefined,
|
||||||
loading: true,
|
loading: true,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new AuthenticatedAction(mockTokenInfo);
|
const action = new AuthenticatedAction(mockTokenInfo);
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -115,7 +121,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
error: undefined,
|
error: undefined,
|
||||||
loading: true,
|
loading: true,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -127,7 +134,8 @@ describe('authReducer', () => {
|
|||||||
error: undefined,
|
error: undefined,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new AuthenticatedSuccessAction(true, mockTokenInfo, EPersonMock._links.self.href);
|
const action = new AuthenticatedSuccessAction(true, mockTokenInfo, EPersonMock._links.self.href);
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -138,7 +146,8 @@ describe('authReducer', () => {
|
|||||||
error: undefined,
|
error: undefined,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -150,7 +159,8 @@ describe('authReducer', () => {
|
|||||||
error: undefined,
|
error: undefined,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new AuthenticatedErrorAction(mockError);
|
const action = new AuthenticatedErrorAction(mockError);
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -161,7 +171,8 @@ describe('authReducer', () => {
|
|||||||
loaded: true,
|
loaded: true,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -172,6 +183,7 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new CheckAuthenticationTokenAction();
|
const action = new CheckAuthenticationTokenAction();
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -180,6 +192,7 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -190,6 +203,7 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: true,
|
loading: true,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new CheckAuthenticationTokenCookieAction();
|
const action = new CheckAuthenticationTokenCookieAction();
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -198,6 +212,7 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -211,7 +226,8 @@ describe('authReducer', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
userId: EPersonMock.id
|
userId: EPersonMock.id,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const action = new LogOutAction();
|
const action = new LogOutAction();
|
||||||
@@ -229,7 +245,8 @@ describe('authReducer', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
userId: EPersonMock.id
|
userId: EPersonMock.id,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const action = new LogOutSuccessAction();
|
const action = new LogOutSuccessAction();
|
||||||
@@ -243,7 +260,8 @@ describe('authReducer', () => {
|
|||||||
loading: true,
|
loading: true,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
refreshing: false,
|
refreshing: false,
|
||||||
userId: undefined
|
userId: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -257,7 +275,8 @@ describe('authReducer', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
userId: EPersonMock.id
|
userId: EPersonMock.id,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const action = new LogOutErrorAction(mockError);
|
const action = new LogOutErrorAction(mockError);
|
||||||
@@ -270,7 +289,8 @@ describe('authReducer', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
userId: EPersonMock.id
|
userId: EPersonMock.id,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -283,7 +303,8 @@ describe('authReducer', () => {
|
|||||||
error: undefined,
|
error: undefined,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new RetrieveAuthenticatedEpersonSuccessAction(EPersonMock.id);
|
const action = new RetrieveAuthenticatedEpersonSuccessAction(EPersonMock.id);
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -295,7 +316,8 @@ describe('authReducer', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
userId: EPersonMock.id
|
userId: EPersonMock.id,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -307,7 +329,8 @@ describe('authReducer', () => {
|
|||||||
error: undefined,
|
error: undefined,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new RetrieveAuthenticatedEpersonErrorAction(mockError);
|
const action = new RetrieveAuthenticatedEpersonErrorAction(mockError);
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -318,7 +341,8 @@ describe('authReducer', () => {
|
|||||||
loaded: true,
|
loaded: true,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -332,7 +356,8 @@ describe('authReducer', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
userId: EPersonMock.id
|
userId: EPersonMock.id,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const newTokenInfo = new AuthTokenInfo('Refreshed token');
|
const newTokenInfo = new AuthTokenInfo('Refreshed token');
|
||||||
const action = new RefreshTokenAction(newTokenInfo);
|
const action = new RefreshTokenAction(newTokenInfo);
|
||||||
@@ -346,7 +371,8 @@ describe('authReducer', () => {
|
|||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
userId: EPersonMock.id,
|
userId: EPersonMock.id,
|
||||||
refreshing: true
|
refreshing: true,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -361,7 +387,8 @@ describe('authReducer', () => {
|
|||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
userId: EPersonMock.id,
|
userId: EPersonMock.id,
|
||||||
refreshing: true
|
refreshing: true,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const newTokenInfo = new AuthTokenInfo('Refreshed token');
|
const newTokenInfo = new AuthTokenInfo('Refreshed token');
|
||||||
const action = new RefreshTokenSuccessAction(newTokenInfo);
|
const action = new RefreshTokenSuccessAction(newTokenInfo);
|
||||||
@@ -375,7 +402,8 @@ describe('authReducer', () => {
|
|||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
userId: EPersonMock.id,
|
userId: EPersonMock.id,
|
||||||
refreshing: false
|
refreshing: false,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -390,7 +418,8 @@ describe('authReducer', () => {
|
|||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
userId: EPersonMock.id,
|
userId: EPersonMock.id,
|
||||||
refreshing: true
|
refreshing: true,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new RefreshTokenErrorAction();
|
const action = new RefreshTokenErrorAction();
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -403,7 +432,8 @@ describe('authReducer', () => {
|
|||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
refreshing: false,
|
refreshing: false,
|
||||||
userId: undefined
|
userId: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -417,7 +447,8 @@ describe('authReducer', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
info: undefined,
|
info: undefined,
|
||||||
userId: EPersonMock.id
|
userId: EPersonMock.id,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
@@ -428,7 +459,8 @@ describe('authReducer', () => {
|
|||||||
loading: false,
|
loading: false,
|
||||||
error: undefined,
|
error: undefined,
|
||||||
info: 'Message',
|
info: 'Message',
|
||||||
userId: undefined
|
userId: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -450,6 +482,7 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new AddAuthenticationMessageAction('Message');
|
const action = new AddAuthenticationMessageAction('Message');
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -458,7 +491,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
info: 'Message'
|
info: 'Message',
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -470,7 +504,8 @@ describe('authReducer', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
error: 'Error',
|
error: 'Error',
|
||||||
info: 'Message'
|
info: 'Message',
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new ResetAuthenticationMessagesAction();
|
const action = new ResetAuthenticationMessagesAction();
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -480,7 +515,8 @@ describe('authReducer', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
error: undefined,
|
error: undefined,
|
||||||
info: undefined
|
info: undefined,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -490,7 +526,8 @@ describe('authReducer', () => {
|
|||||||
authenticated: false,
|
authenticated: false,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false
|
loading: false,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new SetRedirectUrlAction('redirect.url');
|
const action = new SetRedirectUrlAction('redirect.url');
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -499,7 +536,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
redirectUrl: 'redirect.url'
|
redirectUrl: 'redirect.url',
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -510,7 +548,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
authMethods: []
|
authMethods: [],
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const action = new RetrieveAuthMethodsAction(new AuthStatus(), true);
|
const action = new RetrieveAuthMethodsAction(new AuthStatus(), true);
|
||||||
const newState = authReducer(initialState, action);
|
const newState = authReducer(initialState, action);
|
||||||
@@ -519,7 +558,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
authMethods: []
|
authMethods: [],
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -530,7 +570,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
authMethods: []
|
authMethods: [],
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const authMethods = [
|
const authMethods = [
|
||||||
new AuthMethod(AuthMethodType.Password),
|
new AuthMethod(AuthMethodType.Password),
|
||||||
@@ -543,7 +584,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
authMethods: authMethods
|
authMethods: authMethods,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -554,7 +596,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
authMethods: []
|
authMethods: [],
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
const authMethods = [
|
const authMethods = [
|
||||||
new AuthMethod(AuthMethodType.Password),
|
new AuthMethod(AuthMethodType.Password),
|
||||||
@@ -567,7 +610,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
authMethods: authMethods
|
authMethods: authMethods,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -578,7 +622,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
authMethods: []
|
authMethods: [],
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const action = new RetrieveAuthMethodsErrorAction(false);
|
const action = new RetrieveAuthMethodsErrorAction(false);
|
||||||
@@ -588,7 +633,50 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
authMethods: [new AuthMethod(AuthMethodType.Password)]
|
authMethods: [new AuthMethod(AuthMethodType.Password)],
|
||||||
|
idle: false
|
||||||
|
};
|
||||||
|
expect(newState).toEqual(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should properly set the state, in response to a SET_USER_AS_IDLE action', () => {
|
||||||
|
initialState = {
|
||||||
|
authenticated: true,
|
||||||
|
loaded: true,
|
||||||
|
blocking: false,
|
||||||
|
loading: false,
|
||||||
|
idle: false
|
||||||
|
};
|
||||||
|
|
||||||
|
const action = new SetUserAsIdleAction();
|
||||||
|
const newState = authReducer(initialState, action);
|
||||||
|
state = {
|
||||||
|
authenticated: true,
|
||||||
|
loaded: true,
|
||||||
|
blocking: false,
|
||||||
|
loading: false,
|
||||||
|
idle: true
|
||||||
|
};
|
||||||
|
expect(newState).toEqual(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should properly set the state, in response to a UNSET_USER_AS_IDLE action', () => {
|
||||||
|
initialState = {
|
||||||
|
authenticated: true,
|
||||||
|
loaded: true,
|
||||||
|
blocking: false,
|
||||||
|
loading: false,
|
||||||
|
idle: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const action = new UnsetUserAsIdleAction();
|
||||||
|
const newState = authReducer(initialState, action);
|
||||||
|
state = {
|
||||||
|
authenticated: true,
|
||||||
|
loaded: true,
|
||||||
|
blocking: false,
|
||||||
|
loading: false,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
@@ -599,7 +687,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: true,
|
loading: true,
|
||||||
authMethods: []
|
authMethods: [],
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const action = new RetrieveAuthMethodsErrorAction(true);
|
const action = new RetrieveAuthMethodsErrorAction(true);
|
||||||
@@ -609,7 +698,8 @@ describe('authReducer', () => {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
authMethods: [new AuthMethod(AuthMethodType.Password)]
|
authMethods: [new AuthMethod(AuthMethodType.Password)],
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
expect(newState).toEqual(state);
|
expect(newState).toEqual(state);
|
||||||
});
|
});
|
||||||
|
@@ -59,6 +59,9 @@ export interface AuthState {
|
|||||||
// all authentication Methods enabled at the backend
|
// all authentication Methods enabled at the backend
|
||||||
authMethods?: AuthMethod[];
|
authMethods?: AuthMethod[];
|
||||||
|
|
||||||
|
// true when the current user is idle
|
||||||
|
idle: boolean;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,7 +72,8 @@ const initialState: AuthState = {
|
|||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: true,
|
blocking: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
authMethods: []
|
authMethods: [],
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -189,6 +193,7 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut
|
|||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
authToken: (action as RefreshTokenSuccessAction).payload,
|
authToken: (action as RefreshTokenSuccessAction).payload,
|
||||||
refreshing: false,
|
refreshing: false,
|
||||||
|
blocking: false
|
||||||
});
|
});
|
||||||
|
|
||||||
case AuthActionTypes.ADD_MESSAGE:
|
case AuthActionTypes.ADD_MESSAGE:
|
||||||
@@ -234,6 +239,16 @@ export function authReducer(state: any = initialState, action: AuthActions): Aut
|
|||||||
blocking: true,
|
blocking: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
case AuthActionTypes.SET_USER_AS_IDLE:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
idle: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
case AuthActionTypes.UNSET_USER_AS_IDLE:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
idle: false,
|
||||||
|
});
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,11 @@ import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.util
|
|||||||
import { authMethodsMock } from '../../shared/testing/auth-service.stub';
|
import { authMethodsMock } from '../../shared/testing/auth-service.stub';
|
||||||
import { AuthMethod } from './models/auth.method';
|
import { AuthMethod } from './models/auth.method';
|
||||||
import { HardRedirectService } from '../services/hard-redirect.service';
|
import { HardRedirectService } from '../services/hard-redirect.service';
|
||||||
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { getMockTranslateService } from '../../shared/mocks/translate.service.mock';
|
||||||
|
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
|
||||||
|
import { SetUserAsIdleAction, UnsetUserAsIdleAction } from './auth.actions';
|
||||||
|
|
||||||
describe('AuthService test', () => {
|
describe('AuthService test', () => {
|
||||||
|
|
||||||
@@ -47,6 +52,7 @@ describe('AuthService test', () => {
|
|||||||
let token: AuthTokenInfo;
|
let token: AuthTokenInfo;
|
||||||
let authenticatedState;
|
let authenticatedState;
|
||||||
let unAuthenticatedState;
|
let unAuthenticatedState;
|
||||||
|
let idleState;
|
||||||
let linkService;
|
let linkService;
|
||||||
let hardRedirectService;
|
let hardRedirectService;
|
||||||
|
|
||||||
@@ -64,14 +70,24 @@ describe('AuthService test', () => {
|
|||||||
loaded: true,
|
loaded: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
authToken: token,
|
authToken: token,
|
||||||
user: EPersonMock
|
user: EPersonMock,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
unAuthenticatedState = {
|
unAuthenticatedState = {
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
loaded: true,
|
loaded: true,
|
||||||
loading: false,
|
loading: false,
|
||||||
authToken: undefined,
|
authToken: undefined,
|
||||||
user: undefined
|
user: undefined,
|
||||||
|
idle: false
|
||||||
|
};
|
||||||
|
idleState = {
|
||||||
|
authenticated: true,
|
||||||
|
loaded: true,
|
||||||
|
loading: false,
|
||||||
|
authToken: token,
|
||||||
|
user: EPersonMock,
|
||||||
|
idle: true
|
||||||
};
|
};
|
||||||
authRequest = new AuthRequestServiceStub();
|
authRequest = new AuthRequestServiceStub();
|
||||||
routeStub = new ActivatedRouteStub();
|
routeStub = new ActivatedRouteStub();
|
||||||
@@ -107,6 +123,8 @@ describe('AuthService test', () => {
|
|||||||
{ provide: Store, useValue: mockStore },
|
{ provide: Store, useValue: mockStore },
|
||||||
{ provide: EPersonDataService, useValue: mockEpersonDataService },
|
{ provide: EPersonDataService, useValue: mockEpersonDataService },
|
||||||
{ provide: HardRedirectService, useValue: hardRedirectService },
|
{ provide: HardRedirectService, useValue: hardRedirectService },
|
||||||
|
{ provide: NotificationsService, useValue: NotificationsServiceStub },
|
||||||
|
{ provide: TranslateService, useValue: getMockTranslateService() },
|
||||||
CookieService,
|
CookieService,
|
||||||
AuthService
|
AuthService
|
||||||
],
|
],
|
||||||
@@ -180,6 +198,26 @@ describe('AuthService test', () => {
|
|||||||
expect(authMethods.length).toBe(2);
|
expect(authMethods.length).toBe(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('setIdle true', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
authService.setIdle(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('store should dispatch SetUserAsIdleAction', () => {
|
||||||
|
expect(mockStore.dispatch).toHaveBeenCalledWith(new SetUserAsIdleAction());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setIdle false', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
authService.setIdle(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('store should dispatch UnsetUserAsIdleAction', () => {
|
||||||
|
expect(mockStore.dispatch).toHaveBeenCalledWith(new UnsetUserAsIdleAction());
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('', () => {
|
describe('', () => {
|
||||||
@@ -207,13 +245,13 @@ describe('AuthService test', () => {
|
|||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(inject([CookieService, AuthRequestService, Store, Router, RouteService], (cookieService: CookieService, authReqService: AuthRequestService, store: Store<AppState>, router: Router, routeService: RouteService) => {
|
beforeEach(inject([CookieService, AuthRequestService, Store, Router, RouteService], (cookieService: CookieService, authReqService: AuthRequestService, store: Store<AppState>, router: Router, routeService: RouteService, notificationsService: NotificationsService, translateService: TranslateService) => {
|
||||||
store
|
store
|
||||||
.subscribe((state) => {
|
.subscribe((state) => {
|
||||||
(state as any).core = Object.create({});
|
(state as any).core = Object.create({});
|
||||||
(state as any).core.auth = authenticatedState;
|
(state as any).core.auth = authenticatedState;
|
||||||
});
|
});
|
||||||
authService = new AuthService({}, window, undefined, authReqService, mockEpersonDataService, router, routeService, cookieService, store, hardRedirectService);
|
authService = new AuthService({}, window, undefined, authReqService, mockEpersonDataService, router, routeService, cookieService, store, hardRedirectService, notificationsService, translateService);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should return true when user is logged in', () => {
|
it('should return true when user is logged in', () => {
|
||||||
@@ -250,6 +288,12 @@ describe('AuthService test', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('isUserIdle should return false when user is not yet idle', () => {
|
||||||
|
authService.isUserIdle().subscribe((status: boolean) => {
|
||||||
|
expect(status).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('', () => {
|
describe('', () => {
|
||||||
@@ -277,7 +321,7 @@ describe('AuthService test', () => {
|
|||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(inject([ClientCookieService, AuthRequestService, Store, Router, RouteService], (cookieService: ClientCookieService, authReqService: AuthRequestService, store: Store<AppState>, router: Router, routeService: RouteService) => {
|
beforeEach(inject([ClientCookieService, AuthRequestService, Store, Router, RouteService], (cookieService: ClientCookieService, authReqService: AuthRequestService, store: Store<AppState>, router: Router, routeService: RouteService, notificationsService: NotificationsService, translateService: TranslateService) => {
|
||||||
const expiredToken: AuthTokenInfo = new AuthTokenInfo('test_token');
|
const expiredToken: AuthTokenInfo = new AuthTokenInfo('test_token');
|
||||||
expiredToken.expires = Date.now() - (1000 * 60 * 60);
|
expiredToken.expires = Date.now() - (1000 * 60 * 60);
|
||||||
authenticatedState = {
|
authenticatedState = {
|
||||||
@@ -292,7 +336,7 @@ describe('AuthService test', () => {
|
|||||||
(state as any).core = Object.create({});
|
(state as any).core = Object.create({});
|
||||||
(state as any).core.auth = authenticatedState;
|
(state as any).core.auth = authenticatedState;
|
||||||
});
|
});
|
||||||
authService = new AuthService({}, window, undefined, authReqService, mockEpersonDataService, router, routeService, cookieService, store, hardRedirectService);
|
authService = new AuthService({}, window, undefined, authReqService, mockEpersonDataService, router, routeService, cookieService, store, hardRedirectService, notificationsService, translateService);
|
||||||
storage = (authService as any).storage;
|
storage = (authService as any).storage;
|
||||||
routeServiceMock = TestBed.inject(RouteService);
|
routeServiceMock = TestBed.inject(RouteService);
|
||||||
routerStub = TestBed.inject(Router);
|
routerStub = TestBed.inject(Router);
|
||||||
@@ -493,13 +537,13 @@ describe('AuthService test', () => {
|
|||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(inject([CookieService, AuthRequestService, Store, Router, RouteService], (cookieService: CookieService, authReqService: AuthRequestService, store: Store<AppState>, router: Router, routeService: RouteService) => {
|
beforeEach(inject([CookieService, AuthRequestService, Store, Router, RouteService], (cookieService: CookieService, authReqService: AuthRequestService, store: Store<AppState>, router: Router, routeService: RouteService, notificationsService: NotificationsService, translateService: TranslateService) => {
|
||||||
store
|
store
|
||||||
.subscribe((state) => {
|
.subscribe((state) => {
|
||||||
(state as any).core = Object.create({});
|
(state as any).core = Object.create({});
|
||||||
(state as any).core.auth = unAuthenticatedState;
|
(state as any).core.auth = unAuthenticatedState;
|
||||||
});
|
});
|
||||||
authService = new AuthService({}, window, undefined, authReqService, mockEpersonDataService, router, routeService, cookieService, store, hardRedirectService);
|
authService = new AuthService({}, window, undefined, authReqService, mockEpersonDataService, router, routeService, cookieService, store, hardRedirectService, notificationsService, translateService);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should return null for the shortlived token', () => {
|
it('should return null for the shortlived token', () => {
|
||||||
@@ -508,4 +552,44 @@ describe('AuthService test', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when user is idle', () => {
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
init();
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
StoreModule.forRoot({ authReducer }, {
|
||||||
|
runtimeChecks: {
|
||||||
|
strictStateImmutability: false,
|
||||||
|
strictActionImmutability: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: AuthRequestService, useValue: authRequest },
|
||||||
|
{ provide: REQUEST, useValue: {} },
|
||||||
|
{ provide: Router, useValue: routerStub },
|
||||||
|
{ provide: RouteService, useValue: routeServiceStub },
|
||||||
|
{ provide: RemoteDataBuildService, useValue: linkService },
|
||||||
|
CookieService,
|
||||||
|
AuthService
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(inject([CookieService, AuthRequestService, Store, Router, RouteService], (cookieService: CookieService, authReqService: AuthRequestService, store: Store<AppState>, router: Router, routeService: RouteService, notificationsService: NotificationsService, translateService: TranslateService) => {
|
||||||
|
store
|
||||||
|
.subscribe((state) => {
|
||||||
|
(state as any).core = Object.create({});
|
||||||
|
(state as any).core.auth = idleState;
|
||||||
|
});
|
||||||
|
authService = new AuthService({}, window, undefined, authReqService, mockEpersonDataService, router, routeService, cookieService, store, hardRedirectService, notificationsService, translateService);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('isUserIdle should return true when user is not idle', () => {
|
||||||
|
authService.isUserIdle().subscribe((status: boolean) => {
|
||||||
|
expect(status).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -29,14 +29,17 @@ import {
|
|||||||
getRedirectUrl,
|
getRedirectUrl,
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
isAuthenticatedLoaded,
|
isAuthenticatedLoaded,
|
||||||
|
isIdle,
|
||||||
isTokenRefreshing
|
isTokenRefreshing
|
||||||
} from './selectors';
|
} from './selectors';
|
||||||
import { AppState } from '../../app.reducer';
|
import { AppState } from '../../app.reducer';
|
||||||
import {
|
import {
|
||||||
CheckAuthenticationTokenAction,
|
CheckAuthenticationTokenAction, RefreshTokenAction,
|
||||||
ResetAuthenticationMessagesAction,
|
ResetAuthenticationMessagesAction,
|
||||||
RetrieveAuthMethodsAction,
|
RetrieveAuthMethodsAction,
|
||||||
SetRedirectUrlAction
|
SetRedirectUrlAction,
|
||||||
|
SetUserAsIdleAction,
|
||||||
|
UnsetUserAsIdleAction
|
||||||
} from './auth.actions';
|
} from './auth.actions';
|
||||||
import { NativeWindowRef, NativeWindowService } from '../services/window.service';
|
import { NativeWindowRef, NativeWindowService } from '../services/window.service';
|
||||||
import { Base64EncodeUrl } from '../../shared/utils/encode-decode.util';
|
import { Base64EncodeUrl } from '../../shared/utils/encode-decode.util';
|
||||||
@@ -46,6 +49,9 @@ import { getAllSucceededRemoteDataPayload } from '../shared/operators';
|
|||||||
import { AuthMethod } from './models/auth.method';
|
import { AuthMethod } from './models/auth.method';
|
||||||
import { HardRedirectService } from '../services/hard-redirect.service';
|
import { HardRedirectService } from '../services/hard-redirect.service';
|
||||||
import { RemoteData } from '../data/remote-data';
|
import { RemoteData } from '../data/remote-data';
|
||||||
|
import { environment } from '../../../environments/environment';
|
||||||
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
export const LOGIN_ROUTE = '/login';
|
export const LOGIN_ROUTE = '/login';
|
||||||
export const LOGOUT_ROUTE = '/logout';
|
export const LOGOUT_ROUTE = '/logout';
|
||||||
@@ -64,6 +70,11 @@ export class AuthService {
|
|||||||
*/
|
*/
|
||||||
protected _authenticated: boolean;
|
protected _authenticated: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timer to track time until token refresh
|
||||||
|
*/
|
||||||
|
private tokenRefreshTimer;
|
||||||
|
|
||||||
constructor(@Inject(REQUEST) protected req: any,
|
constructor(@Inject(REQUEST) protected req: any,
|
||||||
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
||||||
@Optional() @Inject(RESPONSE) private response: any,
|
@Optional() @Inject(RESPONSE) private response: any,
|
||||||
@@ -73,7 +84,9 @@ export class AuthService {
|
|||||||
protected routeService: RouteService,
|
protected routeService: RouteService,
|
||||||
protected storage: CookieService,
|
protected storage: CookieService,
|
||||||
protected store: Store<AppState>,
|
protected store: Store<AppState>,
|
||||||
protected hardRedirectService: HardRedirectService
|
protected hardRedirectService: HardRedirectService,
|
||||||
|
private notificationService: NotificationsService,
|
||||||
|
private translateService: TranslateService
|
||||||
) {
|
) {
|
||||||
this.store.pipe(
|
this.store.pipe(
|
||||||
select(isAuthenticated),
|
select(isAuthenticated),
|
||||||
@@ -187,7 +200,7 @@ export class AuthService {
|
|||||||
return this.store.pipe(
|
return this.store.pipe(
|
||||||
select(getAuthenticatedUserId),
|
select(getAuthenticatedUserId),
|
||||||
hasValueOperator(),
|
hasValueOperator(),
|
||||||
switchMap((id: string) => this.epersonService.findById(id) ),
|
switchMap((id: string) => this.epersonService.findById(id)),
|
||||||
getAllSucceededRemoteDataPayload()
|
getAllSucceededRemoteDataPayload()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -298,7 +311,7 @@ export class AuthService {
|
|||||||
*/
|
*/
|
||||||
public getToken(): AuthTokenInfo {
|
public getToken(): AuthTokenInfo {
|
||||||
let token: AuthTokenInfo;
|
let token: AuthTokenInfo;
|
||||||
this.store.pipe(select(getAuthenticationToken))
|
this.store.pipe(take(1), select(getAuthenticationToken))
|
||||||
.subscribe((authTokenInfo: AuthTokenInfo) => {
|
.subscribe((authTokenInfo: AuthTokenInfo) => {
|
||||||
// Retrieve authentication token info and check if is valid
|
// Retrieve authentication token info and check if is valid
|
||||||
token = authTokenInfo || null;
|
token = authTokenInfo || null;
|
||||||
@@ -306,6 +319,44 @@ export class AuthService {
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that checks when the session token from store expires and refreshes it when needed
|
||||||
|
*/
|
||||||
|
public trackTokenExpiration(): void {
|
||||||
|
let token: AuthTokenInfo;
|
||||||
|
let currentlyRefreshingToken = false;
|
||||||
|
this.store.pipe(select(getAuthenticationToken)).subscribe((authTokenInfo: AuthTokenInfo) => {
|
||||||
|
// If new token is undefined an it wasn't previously => Refresh failed
|
||||||
|
if (currentlyRefreshingToken && token !== undefined && authTokenInfo === undefined) {
|
||||||
|
// Token refresh failed => Error notification => 10 second wait => Page reloads & user logged out
|
||||||
|
this.notificationService.error(this.translateService.get('auth.messages.token-refresh-failed'));
|
||||||
|
setTimeout(() => this.navigateToRedirectUrl(this.hardRedirectService.getCurrentRoute()), 10000);
|
||||||
|
currentlyRefreshingToken = false;
|
||||||
|
}
|
||||||
|
// If new token.expires is different => Refresh succeeded
|
||||||
|
if (currentlyRefreshingToken && authTokenInfo !== undefined && token.expires !== authTokenInfo.expires) {
|
||||||
|
currentlyRefreshingToken = false;
|
||||||
|
}
|
||||||
|
// Check if/when token needs to be refreshed
|
||||||
|
if (!currentlyRefreshingToken) {
|
||||||
|
token = authTokenInfo || null;
|
||||||
|
if (token !== undefined && token !== null) {
|
||||||
|
let timeLeftBeforeRefresh = token.expires - new Date().getTime() - environment.auth.rest.timeLeftBeforeTokenRefresh;
|
||||||
|
if (timeLeftBeforeRefresh < 0) {
|
||||||
|
timeLeftBeforeRefresh = 0;
|
||||||
|
}
|
||||||
|
if (hasValue(this.tokenRefreshTimer)) {
|
||||||
|
clearTimeout(this.tokenRefreshTimer);
|
||||||
|
}
|
||||||
|
this.tokenRefreshTimer = setTimeout(() => {
|
||||||
|
this.store.dispatch(new RefreshTokenAction(token));
|
||||||
|
currentlyRefreshingToken = true;
|
||||||
|
}, timeLeftBeforeRefresh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a token is next to be expired
|
* Check if a token is next to be expired
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
@@ -346,7 +397,7 @@ export class AuthService {
|
|||||||
|
|
||||||
// Set the cookie expire date
|
// Set the cookie expire date
|
||||||
const expires = new Date(expireDate);
|
const expires = new Date(expireDate);
|
||||||
const options: CookieAttributes = { expires: expires };
|
const options: CookieAttributes = {expires: expires};
|
||||||
|
|
||||||
// Save cookie with the token
|
// Save cookie with the token
|
||||||
return this.storage.set(TOKENITEM, token, options);
|
return this.storage.set(TOKENITEM, token, options);
|
||||||
@@ -396,11 +447,14 @@ export class AuthService {
|
|||||||
* @param redirectUrl
|
* @param redirectUrl
|
||||||
*/
|
*/
|
||||||
public navigateToRedirectUrl(redirectUrl: string) {
|
public navigateToRedirectUrl(redirectUrl: string) {
|
||||||
let url = `/reload/${new Date().getTime()}`;
|
// Don't do redirect if already on reload url
|
||||||
if (isNotEmpty(redirectUrl) && !redirectUrl.startsWith(LOGIN_ROUTE)) {
|
if (!hasValue(redirectUrl) || !redirectUrl.includes('/reload/')) {
|
||||||
url += `?redirect=${encodeURIComponent(redirectUrl)}`;
|
let url = `/reload/${new Date().getTime()}`;
|
||||||
|
if (isNotEmpty(redirectUrl) && !redirectUrl.startsWith(LOGIN_ROUTE)) {
|
||||||
|
url += `?redirect=${encodeURIComponent(redirectUrl)}`;
|
||||||
|
}
|
||||||
|
this.hardRedirectService.redirect(url);
|
||||||
}
|
}
|
||||||
this.hardRedirectService.redirect(url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -435,7 +489,7 @@ export class AuthService {
|
|||||||
|
|
||||||
// Set the cookie expire date
|
// Set the cookie expire date
|
||||||
const expires = new Date(expireDate);
|
const expires = new Date(expireDate);
|
||||||
const options: CookieAttributes = { expires: expires };
|
const options: CookieAttributes = {expires: expires};
|
||||||
this.storage.set(REDIRECT_COOKIE, url, options);
|
this.storage.set(REDIRECT_COOKIE, url, options);
|
||||||
this.store.dispatch(new SetRedirectUrlAction(isNotUndefined(url) ? url : ''));
|
this.store.dispatch(new SetRedirectUrlAction(isNotUndefined(url) ? url : ''));
|
||||||
}
|
}
|
||||||
@@ -528,4 +582,24 @@ export class AuthService {
|
|||||||
return new RetrieveAuthMethodsAction(authStatus, false);
|
return new RetrieveAuthMethodsAction(authStatus, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if current user is idle
|
||||||
|
* @returns {Observable<boolean>}
|
||||||
|
*/
|
||||||
|
public isUserIdle(): Observable<boolean> {
|
||||||
|
return this.store.pipe(select(isIdle));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set idle of auth state
|
||||||
|
* @returns {Observable<boolean>}
|
||||||
|
*/
|
||||||
|
public setIdle(idle: boolean): void {
|
||||||
|
if (idle) {
|
||||||
|
this.store.dispatch(new SetUserAsIdleAction());
|
||||||
|
} else {
|
||||||
|
this.store.dispatch(new UnsetUserAsIdleAction());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -115,6 +115,14 @@ const _getRedirectUrl = (state: AuthState) => state.redirectUrl;
|
|||||||
|
|
||||||
const _getAuthenticationMethods = (state: AuthState) => state.authMethods;
|
const _getAuthenticationMethods = (state: AuthState) => state.authMethods;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the user is idle.
|
||||||
|
* @function _isIdle
|
||||||
|
* @param {State} state
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
const _isIdle = (state: AuthState) => state.idle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the authentication methods enabled at the backend
|
* Returns the authentication methods enabled at the backend
|
||||||
* @function getAuthenticationMethods
|
* @function getAuthenticationMethods
|
||||||
@@ -231,3 +239,12 @@ export const getRegistrationError = createSelector(getAuthState, _getRegistratio
|
|||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
export const getRedirectUrl = createSelector(getAuthState, _getRedirectUrl);
|
export const getRedirectUrl = createSelector(getAuthState, _getRedirectUrl);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the user is idle
|
||||||
|
* @function isIdle
|
||||||
|
* @param {AuthState} state
|
||||||
|
* @param {any} props
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
export const isIdle = createSelector(getAuthState, _isIdle);
|
||||||
|
19
src/app/core/utilities/enter-zone.scheduler.ts
Normal file
19
src/app/core/utilities/enter-zone.scheduler.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { SchedulerLike, Subscription } from 'rxjs';
|
||||||
|
import { NgZone } from '@angular/core';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An RXJS scheduler that will re-enter the Angular zone to run what's scheduled
|
||||||
|
*/
|
||||||
|
export class EnterZoneScheduler implements SchedulerLike {
|
||||||
|
constructor(private zone: NgZone, private scheduler: SchedulerLike) { }
|
||||||
|
|
||||||
|
schedule(...args: any[]): Subscription {
|
||||||
|
return this.zone.run(() =>
|
||||||
|
this.scheduler.schedule.apply(this.scheduler, args)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
now (): number {
|
||||||
|
return this.scheduler.now();
|
||||||
|
}
|
||||||
|
}
|
19
src/app/core/utilities/leave-zone.scheduler.ts
Normal file
19
src/app/core/utilities/leave-zone.scheduler.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { SchedulerLike, Subscription } from 'rxjs';
|
||||||
|
import { NgZone } from '@angular/core';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An RXJS scheduler that will run what's scheduled outside of the Angular zone
|
||||||
|
*/
|
||||||
|
export class LeaveZoneScheduler implements SchedulerLike {
|
||||||
|
constructor(private zone: NgZone, private scheduler: SchedulerLike) { }
|
||||||
|
|
||||||
|
schedule(...args: any[]): Subscription {
|
||||||
|
return this.zone.runOutsideAngular(() =>
|
||||||
|
this.scheduler.schedule.apply(this.scheduler, args)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
now (): number {
|
||||||
|
return this.scheduler.now();
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { Component, Inject, OnInit, Optional, Input } from '@angular/core';
|
import { Component, Inject, OnInit, Input } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
import { combineLatest as combineLatestObservable, Observable, of } from 'rxjs';
|
import { combineLatest as combineLatestObservable, Observable, of } from 'rxjs';
|
||||||
@@ -18,8 +18,6 @@ import { HostWindowService } from '../shared/host-window.service';
|
|||||||
import { ThemeConfig } from '../../config/theme.model';
|
import { ThemeConfig } from '../../config/theme.model';
|
||||||
import { Angulartics2DSpace } from '../statistics/angulartics/dspace-provider';
|
import { Angulartics2DSpace } from '../statistics/angulartics/dspace-provider';
|
||||||
import { environment } from '../../environments/environment';
|
import { environment } from '../../environments/environment';
|
||||||
import { LocaleService } from '../core/locale/locale.service';
|
|
||||||
import { KlaroService } from '../shared/cookies/klaro.service';
|
|
||||||
import { slideSidebarPadding } from '../shared/animations/slide';
|
import { slideSidebarPadding } from '../shared/animations/slide';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -58,9 +56,7 @@ export class RootComponent implements OnInit {
|
|||||||
private router: Router,
|
private router: Router,
|
||||||
private cssService: CSSVariableService,
|
private cssService: CSSVariableService,
|
||||||
private menuService: MenuService,
|
private menuService: MenuService,
|
||||||
private windowService: HostWindowService,
|
private windowService: HostWindowService
|
||||||
private localeService: LocaleService,
|
|
||||||
@Optional() private cookiesService: KlaroService
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,7 +44,8 @@ describe('AuthNavMenuComponent', () => {
|
|||||||
authenticated: false,
|
authenticated: false,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false
|
loading: false,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
authState = {
|
authState = {
|
||||||
authenticated: true,
|
authenticated: true,
|
||||||
@@ -52,7 +53,8 @@ describe('AuthNavMenuComponent', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
authToken: new AuthTokenInfo('test_token'),
|
authToken: new AuthTokenInfo('test_token'),
|
||||||
userId: EPersonMock.id
|
userId: EPersonMock.id,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,7 +37,8 @@ describe('UserMenuComponent', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
authToken: new AuthTokenInfo('test_token'),
|
authToken: new AuthTokenInfo('test_token'),
|
||||||
userId: EPersonMock.id
|
userId: EPersonMock.id,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
authStateLoading = {
|
authStateLoading = {
|
||||||
authenticated: true,
|
authenticated: true,
|
||||||
@@ -45,7 +46,8 @@ describe('UserMenuComponent', () => {
|
|||||||
blocking: false,
|
blocking: false,
|
||||||
loading: true,
|
loading: true,
|
||||||
authToken: null,
|
authToken: null,
|
||||||
userId: EPersonMock.id
|
userId: EPersonMock.id,
|
||||||
|
idle: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
src/app/shared/idle-modal/idle-modal.component.html
Normal file
18
src/app/shared/idle-modal/idle-modal.component.html
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<div>
|
||||||
|
<div class="modal-header" id="idle-modal.header">{{ "idle-modal.header" | translate }}
|
||||||
|
<button type="button" class="close" (click)="closePressed()" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>{{ "idle-modal.info" | translate:{timeToExpire: timeToExpire} }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="cancel btn btn-danger" (click)="logOutPressed()" aria-label="Log out">
|
||||||
|
<i class="fas fa-sign-out-alt"></i> {{ "idle-modal.log-out" | translate }}
|
||||||
|
</button>
|
||||||
|
<button type="button" class="confirm btn btn-primary" (click)="extendSessionPressed()" aria-label="Extend session" ngbAutofocus>
|
||||||
|
<i class="fas fa-redo-alt"></i> {{ "idle-modal.extend-session" | translate }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
135
src/app/shared/idle-modal/idle-modal.component.spec.ts
Normal file
135
src/app/shared/idle-modal/idle-modal.component.spec.ts
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
|
||||||
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { IdleModalComponent } from './idle-modal.component';
|
||||||
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import { LogOutAction } from '../../core/auth/auth.actions';
|
||||||
|
|
||||||
|
describe('IdleModalComponent', () => {
|
||||||
|
let component: IdleModalComponent;
|
||||||
|
let fixture: ComponentFixture<IdleModalComponent>;
|
||||||
|
let debugElement: DebugElement;
|
||||||
|
|
||||||
|
let modalStub;
|
||||||
|
let authServiceStub;
|
||||||
|
let storeStub;
|
||||||
|
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
modalStub = jasmine.createSpyObj('modalStub', ['close']);
|
||||||
|
authServiceStub = jasmine.createSpyObj('authService', ['setIdle']);
|
||||||
|
storeStub = jasmine.createSpyObj('store', ['dispatch']);
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot()],
|
||||||
|
declarations: [IdleModalComponent],
|
||||||
|
providers: [
|
||||||
|
{ provide: NgbActiveModal, useValue: modalStub },
|
||||||
|
{ provide: AuthService, useValue: authServiceStub },
|
||||||
|
{ provide: Store, useValue: storeStub }
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(IdleModalComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
debugElement = fixture.debugElement;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('extendSessionPressed', () => {
|
||||||
|
beforeEach(fakeAsync(() => {
|
||||||
|
spyOn(component.response, 'next');
|
||||||
|
component.extendSessionPressed();
|
||||||
|
}));
|
||||||
|
it('should set idle to false', () => {
|
||||||
|
expect(authServiceStub.setIdle).toHaveBeenCalledWith(false);
|
||||||
|
});
|
||||||
|
it('should close the modal', () => {
|
||||||
|
expect(modalStub.close).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
it('response \'closed\' should have true as next', () => {
|
||||||
|
expect(component.response.next).toHaveBeenCalledWith(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('logOutPressed', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
component.logOutPressed();
|
||||||
|
});
|
||||||
|
it('should close the modal', () => {
|
||||||
|
expect(modalStub.close).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
it('should send logout action', () => {
|
||||||
|
expect(storeStub.dispatch).toHaveBeenCalledWith(new LogOutAction());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('closePressed', () => {
|
||||||
|
beforeEach(fakeAsync(() => {
|
||||||
|
spyOn(component.response, 'next');
|
||||||
|
component.closePressed();
|
||||||
|
}));
|
||||||
|
it('should set idle to false', () => {
|
||||||
|
expect(authServiceStub.setIdle).toHaveBeenCalledWith(false);
|
||||||
|
});
|
||||||
|
it('should close the modal', () => {
|
||||||
|
expect(modalStub.close).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
it('response \'closed\' should have true as next', () => {
|
||||||
|
expect(component.response.next).toHaveBeenCalledWith(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the click method emits on extend session button', () => {
|
||||||
|
beforeEach(fakeAsync(() => {
|
||||||
|
spyOn(component, 'extendSessionPressed');
|
||||||
|
debugElement.query(By.css('button.confirm')).triggerEventHandler('click', {
|
||||||
|
preventDefault: () => {/**/
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tick();
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
it('should call the extendSessionPressed method on the component', () => {
|
||||||
|
expect(component.extendSessionPressed).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the click method emits on log out button', () => {
|
||||||
|
beforeEach(fakeAsync(() => {
|
||||||
|
spyOn(component, 'logOutPressed');
|
||||||
|
debugElement.query(By.css('button.cancel')).triggerEventHandler('click', {
|
||||||
|
preventDefault: () => {/**/
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tick();
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
it('should call the logOutPressed method on the component', () => {
|
||||||
|
expect(component.logOutPressed).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the click method emits on close button', () => {
|
||||||
|
beforeEach(fakeAsync(() => {
|
||||||
|
spyOn(component, 'closePressed');
|
||||||
|
debugElement.query(By.css('.close')).triggerEventHandler('click', {
|
||||||
|
preventDefault: () => {/**/
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tick();
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
it('should call the closePressed method on the component', () => {
|
||||||
|
expect(component.closePressed).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
89
src/app/shared/idle-modal/idle-modal.component.ts
Normal file
89
src/app/shared/idle-modal/idle-modal.component.ts
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
import { Component, OnInit, Output } from '@angular/core';
|
||||||
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import { environment } from '../../../environments/environment';
|
||||||
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
|
import { Subject } from 'rxjs';
|
||||||
|
import { hasValue } from '../empty.util';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import { AppState } from '../../app.reducer';
|
||||||
|
import { LogOutAction } from '../../core/auth/auth.actions';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'ds-idle-modal',
|
||||||
|
templateUrl: 'idle-modal.component.html',
|
||||||
|
})
|
||||||
|
export class IdleModalComponent implements OnInit {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Total time of idleness before session expires (in minutes)
|
||||||
|
* (environment.auth.ui.timeUntilIdle + environment.auth.ui.idleGracePeriod / 1000 / 60)
|
||||||
|
*/
|
||||||
|
timeToExpire: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timer to track time grace period
|
||||||
|
*/
|
||||||
|
private graceTimer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event fired when the modal is closed
|
||||||
|
*/
|
||||||
|
@Output()
|
||||||
|
response: Subject<boolean> = new Subject();
|
||||||
|
|
||||||
|
constructor(private activeModal: NgbActiveModal,
|
||||||
|
private authService: AuthService,
|
||||||
|
private store: Store<AppState>) {
|
||||||
|
this.timeToExpire = (environment.auth.ui.timeUntilIdle + environment.auth.ui.idleGracePeriod) / 1000 / 60; // ms => min
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
if (hasValue(this.graceTimer)) {
|
||||||
|
clearTimeout(this.graceTimer);
|
||||||
|
}
|
||||||
|
this.graceTimer = setTimeout(() => {
|
||||||
|
this.logOutPressed();
|
||||||
|
}, environment.auth.ui.idleGracePeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When extend session is pressed
|
||||||
|
*/
|
||||||
|
extendSessionPressed() {
|
||||||
|
this.extendSessionAndCloseModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close modal and logout
|
||||||
|
*/
|
||||||
|
logOutPressed() {
|
||||||
|
this.closeModal();
|
||||||
|
this.store.dispatch(new LogOutAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When close is pressed
|
||||||
|
*/
|
||||||
|
closePressed() {
|
||||||
|
this.extendSessionAndCloseModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the modal and extend session
|
||||||
|
*/
|
||||||
|
extendSessionAndCloseModal() {
|
||||||
|
if (hasValue(this.graceTimer)) {
|
||||||
|
clearTimeout(this.graceTimer);
|
||||||
|
}
|
||||||
|
this.authService.setIdle(false);
|
||||||
|
this.closeModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the modal and set the response to true so RootComponent knows the modal was closed
|
||||||
|
*/
|
||||||
|
closeModal() {
|
||||||
|
this.activeModal.close();
|
||||||
|
this.response.next(true);
|
||||||
|
}
|
||||||
|
}
|
@@ -19,4 +19,11 @@ export class AuthServiceMock {
|
|||||||
|
|
||||||
public setRedirectUrl(url: string) {
|
public setRedirectUrl(url: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public trackTokenExpiration(): void {
|
||||||
|
}
|
||||||
|
|
||||||
|
public isUserIdle(): Observable<boolean> {
|
||||||
|
return observableOf(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,8 @@ export class SectionsServiceStub {
|
|||||||
isSectionEnabled = jasmine.createSpy('isSectionEnabled');
|
isSectionEnabled = jasmine.createSpy('isSectionEnabled');
|
||||||
isSectionReadOnly = jasmine.createSpy('isSectionReadOnly');
|
isSectionReadOnly = jasmine.createSpy('isSectionReadOnly');
|
||||||
isSectionAvailable = jasmine.createSpy('isSectionAvailable');
|
isSectionAvailable = jasmine.createSpy('isSectionAvailable');
|
||||||
|
isSectionTypeAvailable = jasmine.createSpy('isSectionTypeAvailable');
|
||||||
|
isSectionType = jasmine.createSpy('isSectionType');
|
||||||
addSection = jasmine.createSpy('addSection');
|
addSection = jasmine.createSpy('addSection');
|
||||||
removeSection = jasmine.createSpy('removeSection');
|
removeSection = jasmine.createSpy('removeSection');
|
||||||
updateSectionData = jasmine.createSpy('updateSectionData');
|
updateSectionData = jasmine.createSpy('updateSectionData');
|
||||||
|
@@ -120,7 +120,7 @@ describe('SubmissionFormCollectionComponent Component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const sectionsService: any = jasmine.createSpyObj('sectionsService', {
|
const sectionsService: any = jasmine.createSpyObj('sectionsService', {
|
||||||
isSectionAvailable: of(true)
|
isSectionTypeAvailable: of(true)
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
|
@@ -28,6 +28,7 @@ import { CollectionDataService } from '../../../core/data/collection-data.servic
|
|||||||
import { CollectionDropdownComponent } from '../../../shared/collection-dropdown/collection-dropdown.component';
|
import { CollectionDropdownComponent } from '../../../shared/collection-dropdown/collection-dropdown.component';
|
||||||
import { SectionsService } from '../../sections/sections.service';
|
import { SectionsService } from '../../sections/sections.service';
|
||||||
import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
|
import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators';
|
||||||
|
import { SectionsType } from '../../sections/sections-type';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This component allows to show the current collection the submission belonging to and to change it.
|
* This component allows to show the current collection the submission belonging to and to change it.
|
||||||
@@ -142,7 +143,7 @@ export class SubmissionFormCollectionComponent implements OnChanges, OnInit {
|
|||||||
*/
|
*/
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.pathCombiner = new JsonPatchOperationPathCombiner('sections', 'collection');
|
this.pathCombiner = new JsonPatchOperationPathCombiner('sections', 'collection');
|
||||||
this.available$ = this.sectionsService.isSectionAvailable(this.submissionId, 'collection');
|
this.available$ = this.sectionsService.isSectionTypeAvailable(this.submissionId, SectionsType.collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -3,7 +3,6 @@
|
|||||||
<div *ngIf="(uploadEnabled$ | async)" class="w-100">
|
<div *ngIf="(uploadEnabled$ | async)" class="w-100">
|
||||||
<ds-submission-upload-files [submissionId]="submissionId"
|
<ds-submission-upload-files [submissionId]="submissionId"
|
||||||
[collectionId]="collectionId"
|
[collectionId]="collectionId"
|
||||||
[sectionId]="'upload'"
|
|
||||||
[uploadFilesOptions]="uploadFilesOptions"></ds-submission-upload-files>
|
[uploadFilesOptions]="uploadFilesOptions"></ds-submission-upload-files>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -83,7 +83,6 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
|||||||
const html = `
|
const html = `
|
||||||
<ds-submission-upload-files [submissionId]="submissionId"
|
<ds-submission-upload-files [submissionId]="submissionId"
|
||||||
[collectionId]="collectionId"
|
[collectionId]="collectionId"
|
||||||
[sectionId]="'upload'"
|
|
||||||
[uploadFilesOptions]="uploadFilesOptions"></ds-submission-upload-files>`;
|
[uploadFilesOptions]="uploadFilesOptions"></ds-submission-upload-files>`;
|
||||||
|
|
||||||
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
|
||||||
@@ -108,11 +107,11 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
|||||||
compAsAny = comp;
|
compAsAny = comp;
|
||||||
submissionServiceStub = TestBed.inject(SubmissionService as any);
|
submissionServiceStub = TestBed.inject(SubmissionService as any);
|
||||||
sectionsServiceStub = TestBed.inject(SectionsService as any);
|
sectionsServiceStub = TestBed.inject(SectionsService as any);
|
||||||
|
sectionsServiceStub.isSectionTypeAvailable.and.returnValue(observableOf(true));
|
||||||
notificationsServiceStub = TestBed.inject(NotificationsService as any);
|
notificationsServiceStub = TestBed.inject(NotificationsService as any);
|
||||||
translateService = TestBed.inject(TranslateService);
|
translateService = TestBed.inject(TranslateService);
|
||||||
comp.submissionId = submissionId;
|
comp.submissionId = submissionId;
|
||||||
comp.collectionId = collectionId;
|
comp.collectionId = collectionId;
|
||||||
comp.sectionId = 'upload';
|
|
||||||
comp.uploadFilesOptions = Object.assign(new UploaderOptions(),{
|
comp.uploadFilesOptions = Object.assign(new UploaderOptions(),{
|
||||||
url: '',
|
url: '',
|
||||||
authToken: null,
|
authToken: null,
|
||||||
@@ -133,7 +132,7 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should init uploadEnabled properly', () => {
|
it('should init uploadEnabled properly', () => {
|
||||||
sectionsServiceStub.isSectionAvailable.and.returnValue(hot('-a-b', {
|
sectionsServiceStub.isSectionTypeAvailable.and.returnValue(hot('-a-b', {
|
||||||
a: false,
|
a: false,
|
||||||
b: true
|
b: true
|
||||||
}));
|
}));
|
||||||
@@ -149,53 +148,54 @@ describe('SubmissionUploadFilesComponent Component', () => {
|
|||||||
expect(compAsAny.uploadEnabled).toBeObservable(expected);
|
expect(compAsAny.uploadEnabled).toBeObservable(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show a success notification and call updateSectionData on upload complete', () => {
|
describe('on upload complete', () => {
|
||||||
|
beforeEach(() => {
|
||||||
const expectedErrors: any = mockUploadResponse1ParsedErrors;
|
sectionsServiceStub.isSectionType.and.callFake((_, sectionId, __) => observableOf(sectionId === 'upload'));
|
||||||
compAsAny.uploadEnabled = observableOf(true);
|
compAsAny.uploadEnabled = observableOf(true);
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
comp.onCompleteItem(Object.assign({}, uploadRestResponse, { sections: mockSectionsData }));
|
|
||||||
|
|
||||||
Object.keys(mockSectionsData).forEach((sectionId) => {
|
|
||||||
expect(sectionsServiceStub.updateSectionData).toHaveBeenCalledWith(
|
|
||||||
submissionId,
|
|
||||||
sectionId,
|
|
||||||
mockSectionsData[sectionId],
|
|
||||||
expectedErrors[sectionId]
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(notificationsServiceStub.success).toHaveBeenCalled();
|
it('should show a success notification and call updateSectionData if successful', () => {
|
||||||
|
const expectedErrors: any = mockUploadResponse1ParsedErrors;
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
});
|
comp.onCompleteItem(Object.assign({}, uploadRestResponse, { sections: mockSectionsData }));
|
||||||
|
|
||||||
it('should show an error notification and call updateSectionData on upload complete', () => {
|
Object.keys(mockSectionsData).forEach((sectionId) => {
|
||||||
|
expect(sectionsServiceStub.updateSectionData).toHaveBeenCalledWith(
|
||||||
|
submissionId,
|
||||||
|
sectionId,
|
||||||
|
mockSectionsData[sectionId],
|
||||||
|
expectedErrors[sectionId]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
const responseErrors = mockUploadResponse2Errors;
|
expect(notificationsServiceStub.success).toHaveBeenCalled();
|
||||||
|
|
||||||
const expectedErrors: any = mockUploadResponse2ParsedErrors;
|
|
||||||
compAsAny.uploadEnabled = observableOf(true);
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
comp.onCompleteItem(Object.assign({}, uploadRestResponse, {
|
|
||||||
sections: mockSectionsData,
|
|
||||||
errors: responseErrors.errors
|
|
||||||
}));
|
|
||||||
|
|
||||||
Object.keys(mockSectionsData).forEach((sectionId) => {
|
|
||||||
expect(sectionsServiceStub.updateSectionData).toHaveBeenCalledWith(
|
|
||||||
submissionId,
|
|
||||||
sectionId,
|
|
||||||
mockSectionsData[sectionId],
|
|
||||||
expectedErrors[sectionId]
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(notificationsServiceStub.success).not.toHaveBeenCalled();
|
it('should show an error notification and call updateSectionData if unsuccessful', () => {
|
||||||
|
const responseErrors = mockUploadResponse2Errors;
|
||||||
|
const expectedErrors: any = mockUploadResponse2ParsedErrors;
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
comp.onCompleteItem(Object.assign({}, uploadRestResponse, {
|
||||||
|
sections: mockSectionsData,
|
||||||
|
errors: responseErrors.errors
|
||||||
|
}));
|
||||||
|
|
||||||
|
Object.keys(mockSectionsData).forEach((sectionId) => {
|
||||||
|
expect(sectionsServiceStub.updateSectionData).toHaveBeenCalledWith(
|
||||||
|
submissionId,
|
||||||
|
sectionId,
|
||||||
|
mockSectionsData[sectionId],
|
||||||
|
expectedErrors[sectionId]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(notificationsServiceStub.success).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -208,7 +208,6 @@ class TestComponent {
|
|||||||
|
|
||||||
submissionId = mockSubmissionId;
|
submissionId = mockSubmissionId;
|
||||||
collectionId = mockSubmissionCollectionId;
|
collectionId = mockSubmissionCollectionId;
|
||||||
sectionId = 'upload';
|
|
||||||
uploadFilesOptions = Object.assign(new UploaderOptions(), {
|
uploadFilesOptions = Object.assign(new UploaderOptions(), {
|
||||||
url: '',
|
url: '',
|
||||||
authToken: null,
|
authToken: null,
|
||||||
|
@@ -2,7 +2,7 @@ import { Component, Input, OnChanges } from '@angular/core';
|
|||||||
|
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { Observable, of as observableOf, Subscription } from 'rxjs';
|
import { Observable, of as observableOf, Subscription } from 'rxjs';
|
||||||
import { first } from 'rxjs/operators';
|
import { first, take } from 'rxjs/operators';
|
||||||
|
|
||||||
import { SectionsService } from '../../sections/sections.service';
|
import { SectionsService } from '../../sections/sections.service';
|
||||||
import { hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util';
|
import { hasValue, isEmpty, isNotEmpty } from '../../../shared/empty.util';
|
||||||
@@ -13,6 +13,7 @@ import { UploaderOptions } from '../../../shared/uploader/uploader-options.model
|
|||||||
import parseSectionErrors from '../../utils/parseSectionErrors';
|
import parseSectionErrors from '../../utils/parseSectionErrors';
|
||||||
import { SubmissionJsonPatchOperationsService } from '../../../core/submission/submission-json-patch-operations.service';
|
import { SubmissionJsonPatchOperationsService } from '../../../core/submission/submission-json-patch-operations.service';
|
||||||
import { WorkspaceItem } from '../../../core/submission/models/workspaceitem.model';
|
import { WorkspaceItem } from '../../../core/submission/models/workspaceitem.model';
|
||||||
|
import { SectionsType } from '../../sections/sections-type';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This component represents the drop zone that provides to add files to the submission.
|
* This component represents the drop zone that provides to add files to the submission.
|
||||||
@@ -35,12 +36,6 @@ export class SubmissionUploadFilesComponent implements OnChanges {
|
|||||||
*/
|
*/
|
||||||
@Input() submissionId: string;
|
@Input() submissionId: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* The upload section id
|
|
||||||
* @type {string}
|
|
||||||
*/
|
|
||||||
@Input() sectionId: string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The uploader configuration options
|
* The uploader configuration options
|
||||||
* @type {UploaderOptions}
|
* @type {UploaderOptions}
|
||||||
@@ -110,7 +105,7 @@ export class SubmissionUploadFilesComponent implements OnChanges {
|
|||||||
* Check if upload functionality is enabled
|
* Check if upload functionality is enabled
|
||||||
*/
|
*/
|
||||||
ngOnChanges() {
|
ngOnChanges() {
|
||||||
this.uploadEnabled = this.sectionService.isSectionAvailable(this.submissionId, this.sectionId);
|
this.uploadEnabled = this.sectionService.isSectionTypeAvailable(this.submissionId, SectionsType.Upload);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,14 +131,18 @@ export class SubmissionUploadFilesComponent implements OnChanges {
|
|||||||
.forEach((sectionId) => {
|
.forEach((sectionId) => {
|
||||||
const sectionData = normalizeSectionData(sections[sectionId]);
|
const sectionData = normalizeSectionData(sections[sectionId]);
|
||||||
const sectionErrors = errorsList[sectionId];
|
const sectionErrors = errorsList[sectionId];
|
||||||
if (sectionId === 'upload') {
|
this.sectionService.isSectionType(this.submissionId, sectionId, SectionsType.Upload)
|
||||||
// Look for errors on upload
|
.pipe(take(1))
|
||||||
if ((isEmpty(sectionErrors))) {
|
.subscribe((isUpload) => {
|
||||||
this.notificationsService.success(null, this.translate.get('submission.sections.upload.upload-successful'));
|
if (isUpload) {
|
||||||
} else {
|
// Look for errors on upload
|
||||||
this.notificationsService.error(null, this.translate.get('submission.sections.upload.upload-failed'));
|
if ((isEmpty(sectionErrors))) {
|
||||||
}
|
this.notificationsService.success(null, this.translate.get('submission.sections.upload.upload-successful'));
|
||||||
}
|
} else {
|
||||||
|
this.notificationsService.error(null, this.translate.get('submission.sections.upload.upload-failed'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
this.sectionService.updateSectionData(this.submissionId, sectionId, sectionData, sectionErrors);
|
this.sectionService.updateSectionData(this.submissionId, sectionId, sectionData, sectionErrors);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -334,6 +334,38 @@ describe('SectionsService test suite', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isSectionType', () => {
|
||||||
|
it('should return true if the section matches the provided type', () => {
|
||||||
|
store.select.and.returnValue(observableOf(submissionState));
|
||||||
|
|
||||||
|
const expected = cold('(b|)', {
|
||||||
|
b: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(service.isSectionType(submissionId, 'upload', SectionsType.Upload)).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if the section doesn\'t match the provided type', () => {
|
||||||
|
store.select.and.returnValue(observableOf(submissionState));
|
||||||
|
|
||||||
|
const expected = cold('(b|)', {
|
||||||
|
b: false
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(service.isSectionType(submissionId, sectionId, SectionsType.Upload)).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if the provided sectionId doesn\'t exist', () => {
|
||||||
|
store.select.and.returnValue(observableOf(submissionState));
|
||||||
|
|
||||||
|
const expected = cold('(b|)', {
|
||||||
|
b: false
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(service.isSectionType(submissionId, 'no-such-id', SectionsType.Upload)).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('addSection', () => {
|
describe('addSection', () => {
|
||||||
it('should dispatch a new EnableSectionAction a move target to new section', () => {
|
it('should dispatch a new EnableSectionAction a move target to new section', () => {
|
||||||
|
|
||||||
|
@@ -328,6 +328,22 @@ export class SectionsService {
|
|||||||
distinctUntilChanged());
|
distinctUntilChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if given section id is of a given section type
|
||||||
|
* @param submissionId
|
||||||
|
* @param sectionId
|
||||||
|
* @param sectionType
|
||||||
|
*/
|
||||||
|
public isSectionType(submissionId: string, sectionId: string, sectionType: SectionsType): Observable<boolean> {
|
||||||
|
return this.store.select(submissionObjectFromIdSelector(submissionId)).pipe(
|
||||||
|
filter((submissionState: SubmissionObjectEntry) => isNotUndefined(submissionState)),
|
||||||
|
map((submissionState: SubmissionObjectEntry) => {
|
||||||
|
return isNotUndefined(submissionState.sections) && isNotUndefined(submissionState.sections[sectionId])
|
||||||
|
&& submissionState.sections[sectionId].sectionType === sectionType;
|
||||||
|
}),
|
||||||
|
distinctUntilChanged());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch a new [EnableSectionAction] to add a new section and move page target to it
|
* Dispatch a new [EnableSectionAction] to add a new section and move page target to it
|
||||||
*
|
*
|
||||||
|
@@ -288,14 +288,13 @@ export class SubmissionSectionUploadFileComponent implements OnChanges, OnInit {
|
|||||||
this.pathCombiner.subRootElement);
|
this.pathCombiner.subRootElement);
|
||||||
})
|
})
|
||||||
).subscribe((result: SubmissionObject[]) => {
|
).subscribe((result: SubmissionObject[]) => {
|
||||||
if (result[0].sections.upload) {
|
if (result[0].sections[this.sectionId]) {
|
||||||
Object.keys((result[0].sections.upload as WorkspaceitemSectionUploadObject).files)
|
const uploadSection = (result[0].sections[this.sectionId] as WorkspaceitemSectionUploadObject);
|
||||||
.filter((key) => (result[0].sections.upload as WorkspaceitemSectionUploadObject).files[key].uuid === this.fileId)
|
Object.keys(uploadSection.files)
|
||||||
|
.filter((key) => uploadSection.files[key].uuid === this.fileId)
|
||||||
.forEach((key) => this.uploadService.updateFileData(
|
.forEach((key) => this.uploadService.updateFileData(
|
||||||
this.submissionId,
|
this.submissionId, this.sectionId, this.fileId, uploadSection.files[key])
|
||||||
this.sectionId,
|
);
|
||||||
this.fileId,
|
|
||||||
(result[0].sections.upload as WorkspaceitemSectionUploadObject).files[key]));
|
|
||||||
}
|
}
|
||||||
this.switchMode();
|
this.switchMode();
|
||||||
}));
|
}));
|
||||||
|
@@ -526,6 +526,8 @@
|
|||||||
|
|
||||||
"auth.messages.expired": "Your session has expired. Please log in again.",
|
"auth.messages.expired": "Your session has expired. Please log in again.",
|
||||||
|
|
||||||
|
"auth.messages.token-refresh-failed": "Refreshing your session token failed. Please log in again.",
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"bitstream.download.page": "Now downloading {{bitstream}}..." ,
|
"bitstream.download.page": "Now downloading {{bitstream}}..." ,
|
||||||
@@ -3703,6 +3705,14 @@
|
|||||||
|
|
||||||
"workflow-item.send-back.button.confirm": "Send back",
|
"workflow-item.send-back.button.confirm": "Send back",
|
||||||
|
|
||||||
"workflow-item.view.breadcrumbs": "Workflow View"
|
"workflow-item.view.breadcrumbs": "Workflow View",
|
||||||
|
|
||||||
|
|
||||||
|
"idle-modal.header": "Session will expire soon",
|
||||||
|
|
||||||
|
"idle-modal.info": "For security reasons, user sessions expire after {{ timeToExpire }} minutes of inactivity. Your session will expire soon. Would you like to extend it or log out?",
|
||||||
|
|
||||||
|
"idle-modal.log-out": "Log out",
|
||||||
|
|
||||||
|
"idle-modal.extend-session": "Extend session"
|
||||||
}
|
}
|
||||||
|
@@ -6,5 +6,18 @@ export interface AuthTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface AuthConfig extends Config {
|
export interface AuthConfig extends Config {
|
||||||
target: AuthTarget;
|
target?: AuthTarget;
|
||||||
|
|
||||||
|
ui: {
|
||||||
|
// The amount of time before the idle warning is shown
|
||||||
|
timeUntilIdle: number;
|
||||||
|
// The amount of time the user has to react after the idle warning is shown before they are logged out.
|
||||||
|
idleGracePeriod: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
rest: {
|
||||||
|
// If the rest token expires in less than this amount of time, it will be refreshed automatically.
|
||||||
|
// This is independent from the idle warning.
|
||||||
|
timeLeftBeforeTokenRefresh: number;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,6 @@ import { GlobalConfig } from '../config/global-config.interface';
|
|||||||
import { NotificationAnimationsType } from '../app/shared/notifications/models/notification-animations-type';
|
import { NotificationAnimationsType } from '../app/shared/notifications/models/notification-animations-type';
|
||||||
import { BrowseByType } from '../app/+browse-by/+browse-by-switcher/browse-by-decorator';
|
import { BrowseByType } from '../app/+browse-by/+browse-by-switcher/browse-by-decorator';
|
||||||
import { RestRequestMethod } from '../app/core/data/rest-request-method';
|
import { RestRequestMethod } from '../app/core/data/rest-request-method';
|
||||||
import { BASE_THEME_NAME } from '../app/shared/theme-support/theme.constants';
|
|
||||||
|
|
||||||
export const environment: GlobalConfig = {
|
export const environment: GlobalConfig = {
|
||||||
production: true,
|
production: true,
|
||||||
@@ -43,6 +42,22 @@ export const environment: GlobalConfig = {
|
|||||||
timePerMethod: {[RestRequestMethod.PATCH]: 3} as any // time in seconds
|
timePerMethod: {[RestRequestMethod.PATCH]: 3} as any // time in seconds
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// Authentication settings
|
||||||
|
auth: {
|
||||||
|
// Authentication UI settings
|
||||||
|
ui: {
|
||||||
|
// the amount of time before the idle warning is shown
|
||||||
|
timeUntilIdle: 15 * 60 * 1000, // 15 minutes
|
||||||
|
// the amount of time the user has to react after the idle warning is shown before they are logged out.
|
||||||
|
idleGracePeriod: 5 * 60 * 1000, // 5 minutes
|
||||||
|
},
|
||||||
|
// Authentication REST settings
|
||||||
|
rest: {
|
||||||
|
// If the rest token expires in less than this amount of time, it will be refreshed automatically.
|
||||||
|
// This is independent from the idle warning.
|
||||||
|
timeLeftBeforeTokenRefresh: 2 * 60 * 1000, // 2 minutes
|
||||||
|
},
|
||||||
|
},
|
||||||
// Form settings
|
// Form settings
|
||||||
form: {
|
form: {
|
||||||
// NOTE: Map server-side validators to comparative Angular form validators
|
// NOTE: Map server-side validators to comparative Angular form validators
|
||||||
|
@@ -35,6 +35,22 @@ export const environment: Partial<GlobalConfig> = {
|
|||||||
timePerMethod: {[RestRequestMethod.PATCH]: 3} as any // time in seconds
|
timePerMethod: {[RestRequestMethod.PATCH]: 3} as any // time in seconds
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// Authentication settings
|
||||||
|
auth: {
|
||||||
|
// Authentication UI settings
|
||||||
|
ui: {
|
||||||
|
// the amount of time before the idle warning is shown
|
||||||
|
timeUntilIdle: 20000, // 20 sec
|
||||||
|
// the amount of time the user has to react after the idle warning is shown before they are logged out.
|
||||||
|
idleGracePeriod: 20000, // 20 sec
|
||||||
|
},
|
||||||
|
// Authentication REST settings
|
||||||
|
rest: {
|
||||||
|
// If the rest token expires in less than this amount of time, it will be refreshed automatically.
|
||||||
|
// This is independent from the idle warning.
|
||||||
|
timeLeftBeforeTokenRefresh: 20000, // 20 sec
|
||||||
|
},
|
||||||
|
},
|
||||||
// Form settings
|
// Form settings
|
||||||
form: {
|
form: {
|
||||||
// NOTE: Map server-side validators to comparative Angular form validators
|
// NOTE: Map server-side validators to comparative Angular form validators
|
||||||
|
Reference in New Issue
Block a user