mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge pull request #3982 from atmire/no-platform-specific-code-in-abstract-services-8_x
No platform specific code in abstract services 8_x
This commit is contained in:
@@ -288,7 +288,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, notificationsService, translateService);
|
authService = new AuthService(window, 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', () => {
|
||||||
@@ -373,7 +373,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, notificationsService, translateService);
|
authService = new AuthService(window, 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);
|
||||||
@@ -593,7 +593,7 @@ describe('AuthService test', () => {
|
|||||||
(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, notificationsService, translateService);
|
authService = new AuthService(window, 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', () => {
|
||||||
@@ -633,7 +633,7 @@ describe('AuthService test', () => {
|
|||||||
(state as any).core = Object.create({});
|
(state as any).core = Object.create({});
|
||||||
(state as any).core.auth = idleState;
|
(state as any).core.auth = idleState;
|
||||||
});
|
});
|
||||||
authService = new AuthService({}, window, undefined, authReqService, mockEpersonDataService, router, routeService, cookieService, store, hardRedirectService, notificationsService, translateService);
|
authService = new AuthService(window, authReqService, mockEpersonDataService, router, routeService, cookieService, store, hardRedirectService, notificationsService, translateService);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('isUserIdle should return true when user is not idle', () => {
|
it('isUserIdle should return true when user is not idle', () => {
|
||||||
|
@@ -2,7 +2,6 @@ import { HttpHeaders } from '@angular/common/http';
|
|||||||
import {
|
import {
|
||||||
Inject,
|
Inject,
|
||||||
Injectable,
|
Injectable,
|
||||||
Optional,
|
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import {
|
import {
|
||||||
@@ -24,10 +23,6 @@ import {
|
|||||||
} from 'rxjs/operators';
|
} from 'rxjs/operators';
|
||||||
|
|
||||||
import { environment } from '../../../environments/environment';
|
import { environment } from '../../../environments/environment';
|
||||||
import {
|
|
||||||
REQUEST,
|
|
||||||
RESPONSE,
|
|
||||||
} from '../../../express.tokens';
|
|
||||||
import { AppState } from '../../app.reducer';
|
import { AppState } from '../../app.reducer';
|
||||||
import {
|
import {
|
||||||
hasNoValue,
|
hasNoValue,
|
||||||
@@ -111,9 +106,8 @@ export class AuthService {
|
|||||||
*/
|
*/
|
||||||
private tokenRefreshTimer;
|
private tokenRefreshTimer;
|
||||||
|
|
||||||
constructor(@Inject(REQUEST) protected req: any,
|
constructor(
|
||||||
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
||||||
@Optional() @Inject(RESPONSE) private response: any,
|
|
||||||
protected authRequestService: AuthRequestService,
|
protected authRequestService: AuthRequestService,
|
||||||
protected epersonService: EPersonDataService,
|
protected epersonService: EPersonDataService,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
@@ -121,8 +115,8 @@ export class AuthService {
|
|||||||
protected storage: CookieService,
|
protected storage: CookieService,
|
||||||
protected store: Store<AppState>,
|
protected store: Store<AppState>,
|
||||||
protected hardRedirectService: HardRedirectService,
|
protected hardRedirectService: HardRedirectService,
|
||||||
private notificationService: NotificationsService,
|
protected notificationService: NotificationsService,
|
||||||
private translateService: TranslateService,
|
protected translateService: TranslateService,
|
||||||
) {
|
) {
|
||||||
this.store.pipe(
|
this.store.pipe(
|
||||||
// when this service is constructed the store is not fully initialized yet
|
// when this service is constructed the store is not fully initialized yet
|
||||||
@@ -504,10 +498,6 @@ export class AuthService {
|
|||||||
if (this._window.nativeWindow.location) {
|
if (this._window.nativeWindow.location) {
|
||||||
// Hard redirect to login page, so that all state is definitely lost
|
// Hard redirect to login page, so that all state is definitely lost
|
||||||
this._window.nativeWindow.location.href = redirectUrl;
|
this._window.nativeWindow.location.href = redirectUrl;
|
||||||
} else if (this.response) {
|
|
||||||
if (!this.response._headerSent) {
|
|
||||||
this.response.redirect(302, redirectUrl);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.router.navigateByUrl(redirectUrl);
|
this.router.navigateByUrl(redirectUrl);
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,40 @@
|
|||||||
import { HttpHeaders } from '@angular/common/http';
|
import { HttpHeaders } from '@angular/common/http';
|
||||||
import { Injectable } from '@angular/core';
|
import {
|
||||||
|
Inject,
|
||||||
|
Injectable,
|
||||||
|
Optional,
|
||||||
|
} from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
|
import {
|
||||||
|
REQUEST,
|
||||||
|
RESPONSE,
|
||||||
|
} from '../../../express.tokens';
|
||||||
|
import { AppState } from '../../app.reducer';
|
||||||
import {
|
import {
|
||||||
hasValue,
|
hasValue,
|
||||||
isNotEmpty,
|
isNotEmpty,
|
||||||
} from '../../shared/empty.util';
|
} from '../../shared/empty.util';
|
||||||
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
import { RemoteData } from '../data/remote-data';
|
import { RemoteData } from '../data/remote-data';
|
||||||
import { HttpOptions } from '../dspace-rest/dspace-rest.service';
|
import { HttpOptions } from '../dspace-rest/dspace-rest.service';
|
||||||
import { AuthService } from './auth.service';
|
import { EPersonDataService } from '../eperson/eperson-data.service';
|
||||||
|
import { CookieService } from '../services/cookie.service';
|
||||||
|
import { HardRedirectService } from '../services/hard-redirect.service';
|
||||||
|
import { RouteService } from '../services/route.service';
|
||||||
|
import {
|
||||||
|
NativeWindowRef,
|
||||||
|
NativeWindowService,
|
||||||
|
} from '../services/window.service';
|
||||||
|
import {
|
||||||
|
AuthService,
|
||||||
|
LOGIN_ROUTE,
|
||||||
|
} from './auth.service';
|
||||||
|
import { AuthRequestService } from './auth-request.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';
|
||||||
|
|
||||||
@@ -19,6 +44,34 @@ import { AuthTokenInfo } from './models/auth-token-info.model';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class ServerAuthService extends AuthService {
|
export class ServerAuthService extends AuthService {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@Inject(REQUEST) protected req: any,
|
||||||
|
@Optional() @Inject(RESPONSE) private response: any,
|
||||||
|
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
||||||
|
protected authRequestService: AuthRequestService,
|
||||||
|
protected epersonService: EPersonDataService,
|
||||||
|
protected router: Router,
|
||||||
|
protected routeService: RouteService,
|
||||||
|
protected storage: CookieService,
|
||||||
|
protected store: Store<AppState>,
|
||||||
|
protected hardRedirectService: HardRedirectService,
|
||||||
|
protected notificationService: NotificationsService,
|
||||||
|
protected translateService: TranslateService,
|
||||||
|
) {
|
||||||
|
super(
|
||||||
|
_window,
|
||||||
|
authRequestService,
|
||||||
|
epersonService,
|
||||||
|
router,
|
||||||
|
routeService,
|
||||||
|
storage,
|
||||||
|
store,
|
||||||
|
hardRedirectService,
|
||||||
|
notificationService,
|
||||||
|
translateService,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the authenticated user
|
* Returns the authenticated user
|
||||||
* @returns {User}
|
* @returns {User}
|
||||||
@@ -62,4 +115,18 @@ export class ServerAuthService extends AuthService {
|
|||||||
map((rd: RemoteData<AuthStatus>) => Object.assign(new AuthStatus(), rd.payload)),
|
map((rd: RemoteData<AuthStatus>) => Object.assign(new AuthStatus(), rd.payload)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override redirectToLoginWhenTokenExpired() {
|
||||||
|
const redirectUrl = LOGIN_ROUTE + '?expired=true';
|
||||||
|
if (this._window.nativeWindow.location) {
|
||||||
|
// Hard redirect to login page, so that all state is definitely lost
|
||||||
|
this._window.nativeWindow.location.href = redirectUrl;
|
||||||
|
} else if (this.response) {
|
||||||
|
if (!this.response._headerSent) {
|
||||||
|
this.response.redirect(302, redirectUrl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.router.navigateByUrl(redirectUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,15 +1,10 @@
|
|||||||
import {
|
import { Injectable } from '@angular/core';
|
||||||
Inject,
|
|
||||||
Injectable,
|
|
||||||
} from '@angular/core';
|
|
||||||
import { CookieAttributes } from 'js-cookie';
|
import { CookieAttributes } from 'js-cookie';
|
||||||
import {
|
import {
|
||||||
Observable,
|
Observable,
|
||||||
Subject,
|
Subject,
|
||||||
} from 'rxjs';
|
} from 'rxjs';
|
||||||
|
|
||||||
import { REQUEST } from '../../../express.tokens';
|
|
||||||
|
|
||||||
export interface ICookieService {
|
export interface ICookieService {
|
||||||
readonly cookies$: Observable<{ readonly [key: string]: any }>;
|
readonly cookies$: Observable<{ readonly [key: string]: any }>;
|
||||||
|
|
||||||
@@ -27,9 +22,6 @@ export abstract class CookieService implements ICookieService {
|
|||||||
protected readonly cookieSource = new Subject<{ readonly [key: string]: any }>();
|
protected readonly cookieSource = new Subject<{ readonly [key: string]: any }>();
|
||||||
public readonly cookies$ = this.cookieSource.asObservable();
|
public readonly cookies$ = this.cookieSource.asObservable();
|
||||||
|
|
||||||
constructor(@Inject(REQUEST) protected req: any) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract set(name: string, value: any, options?: CookieAttributes): void;
|
public abstract set(name: string, value: any, options?: CookieAttributes): void;
|
||||||
|
|
||||||
public abstract remove(name: string, options?: CookieAttributes): void;
|
public abstract remove(name: string, options?: CookieAttributes): void;
|
||||||
|
@@ -1,6 +1,10 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import {
|
||||||
|
Inject,
|
||||||
|
Injectable,
|
||||||
|
} from '@angular/core';
|
||||||
import { CookieAttributes } from 'js-cookie';
|
import { CookieAttributes } from 'js-cookie';
|
||||||
|
|
||||||
|
import { REQUEST } from '../../../express.tokens';
|
||||||
import {
|
import {
|
||||||
CookieService,
|
CookieService,
|
||||||
ICookieService,
|
ICookieService,
|
||||||
@@ -9,6 +13,10 @@ import {
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class ServerCookieService extends CookieService implements ICookieService {
|
export class ServerCookieService extends CookieService implements ICookieService {
|
||||||
|
|
||||||
|
constructor(@Inject(REQUEST) protected req: any) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
public set(name: string, value: any, options?: CookieAttributes): void {
|
public set(name: string, value: any, options?: CookieAttributes): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user