From f92eb27c246ab7256b8218aefd56fae963e1e4d9 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Wed, 26 Feb 2020 10:01:43 +0100 Subject: [PATCH] remove NormalizedAuthStatus --- src/app/core/auth/auth.service.spec.ts | 11 +++++------ src/app/core/auth/auth.service.ts | 7 ++----- src/app/core/auth/authenticated.guard.ts | 10 +++------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/app/core/auth/auth.service.spec.ts b/src/app/core/auth/auth.service.spec.ts index 1a34d02e9c..ff9562da60 100644 --- a/src/app/core/auth/auth.service.spec.ts +++ b/src/app/core/auth/auth.service.spec.ts @@ -23,7 +23,6 @@ import { EPersonMock } from '../../shared/testing/eperson-mock'; import { AppState } from '../../app.reducer'; import { ClientCookieService } from '../services/client-cookie.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; -import { getMockRemoteDataBuildService } from '../../shared/mocks/mock-remote-data-build.service'; import { routeServiceStub } from '../../shared/testing/route-service-stub'; import { RouteService } from '../services/route.service'; import { authMethodsMock } from '../../shared/testing/auth-service-stub'; @@ -64,7 +63,7 @@ describe('AuthService test', () => { linkService = { resolveLinks: {} }; - spyOn(linkService, 'resolveLinks').and.returnValue({authenticated: true, eperson: observableOf({payload: {}})}); + spyOn(linkService, 'resolveLinks').and.returnValue({ authenticated: true, eperson: observableOf({ payload: {} }) }); } @@ -272,7 +271,7 @@ describe('AuthService test', () => { expect(storage.remove).toHaveBeenCalled(); }); - it ('should set redirect url to previous page', () => { + it('should set redirect url to previous page', () => { spyOn(routeServiceMock, 'getHistory').and.callThrough(); spyOn(routerStub, 'navigateByUrl'); authService.redirectAfterLoginSuccess(true); @@ -280,7 +279,7 @@ describe('AuthService test', () => { expect(routerStub.navigateByUrl).toHaveBeenCalledWith('/collection/123'); }); - it ('should set redirect url to current page', () => { + it('should set redirect url to current page', () => { spyOn(routeServiceMock, 'getHistory').and.callThrough(); spyOn(routerStub, 'navigateByUrl'); authService.redirectAfterLoginSuccess(false); @@ -288,7 +287,7 @@ describe('AuthService test', () => { expect(routerStub.navigateByUrl).toHaveBeenCalledWith('/home'); }); - it ('should redirect to / and not to /login', () => { + it('should redirect to / and not to /login', () => { spyOn(routeServiceMock, 'getHistory').and.returnValue(observableOf(['/login', '/login'])); spyOn(routerStub, 'navigateByUrl'); authService.redirectAfterLoginSuccess(true); @@ -296,7 +295,7 @@ describe('AuthService test', () => { expect(routerStub.navigateByUrl).toHaveBeenCalledWith('/'); }); - it ('should redirect to / when no redirect url is found', () => { + it('should redirect to / when no redirect url is found', () => { spyOn(routeServiceMock, 'getHistory').and.returnValue(observableOf([''])); spyOn(routerStub, 'navigateByUrl'); authService.redirectAfterLoginSuccess(true); diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts index eed641cbf3..d46cd29433 100644 --- a/src/app/core/auth/auth.service.ts +++ b/src/app/core/auth/auth.service.ts @@ -8,9 +8,9 @@ import { distinctUntilChanged, filter, map, startWith, switchMap, take, withLate import { RouterReducerState } from '@ngrx/router-store'; import { select, Store } from '@ngrx/store'; import { CookieAttributes } from 'js-cookie'; + import { followLink } from '../../shared/utils/follow-link-config.model'; import { LinkService } from '../cache/builders/link.service'; - import { EPerson } from '../eperson/models/eperson.model'; import { AuthRequestService } from './auth-request.service'; import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service'; @@ -27,14 +27,11 @@ import { } from './auth.actions'; import { NativeWindowRef, NativeWindowService } from '../services/window.service'; import { Base64EncodeUrl } from '../../shared/utils/encode-decode.util'; -import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RouteService } from '../services/route.service'; import { AuthMethod } from './models/auth.method'; -import { NormalizedAuthStatus } from './models/normalized-auth-status.model'; export const LOGIN_ROUTE = '/login'; export const LOGOUT_ROUTE = '/logout'; - export const REDIRECT_COOKIE = 'dsRedirectUrl'; /** @@ -132,7 +129,7 @@ export class AuthService { options.headers = headers; options.withCredentials = true; return this.authRequestService.getRequest('status', options).pipe( - map((status: NormalizedAuthStatus) => Object.assign(new AuthStatus(), status)) + map((status: AuthStatus) => Object.assign(new AuthStatus(), status)) ); } diff --git a/src/app/core/auth/authenticated.guard.ts b/src/app/core/auth/authenticated.guard.ts index 2fae15f194..7a2f39854c 100644 --- a/src/app/core/auth/authenticated.guard.ts +++ b/src/app/core/auth/authenticated.guard.ts @@ -1,17 +1,14 @@ - -import {take} from 'rxjs/operators'; import { Injectable } from '@angular/core'; import { ActivatedRouteSnapshot, CanActivate, CanLoad, Route, Router, RouterStateSnapshot } from '@angular/router'; -import {Observable, of} from 'rxjs'; +import { Observable } from 'rxjs'; +import { take } from 'rxjs/operators'; import { select, Store } from '@ngrx/store'; -// reducers import { CoreState } from '../core.reducers'; -import { isAuthenticated, isAuthenticationLoading } from './selectors'; +import { isAuthenticated } from './selectors'; import { AuthService } from './auth.service'; import { RedirectWhenAuthenticationIsRequiredAction } from './auth.actions'; -import { isEmpty } from '../../shared/empty.util'; /** * Prevent unauthorized activating and loading of routes @@ -53,7 +50,6 @@ export class AuthenticatedGuard implements CanActivate, CanLoad { } private handleAuth(url: string): Observable { - console.log('authenticated.guard.handleAuth() was called with url: ', url); // get observable const observable = this.store.pipe(select(isAuthenticated));