small fixes for authentication

This commit is contained in:
lotte
2018-09-12 16:11:04 +02:00
parent caf9194f36
commit 1f336f29fd
25 changed files with 115 additions and 87 deletions

View File

@@ -1,14 +1,15 @@
import { AuthType } from './auth-type'; import { AuthType } from './auth-type';
import { GenericConstructor } from '../shared/generic-constructor'; import { GenericConstructor } from '../shared/generic-constructor';
import { NormalizedAuthStatus } from './models/normalized-auth-status.model'; import { NormalizedAuthStatus } from './models/normalized-auth-status.model';
import { NormalizedEperson } from '../eperson/models/NormalizedEperson.model'; import { NormalizedEPerson } from '../eperson/models/normalized-eperson.model';
import { NormalizedObject } from '../cache/models/normalized-object.model'; import { NormalizedObject } from '../cache/models/normalized-object.model';
import { EPerson } from '../eperson/models/eperson.model';
export class AuthObjectFactory { export class AuthObjectFactory {
public static getConstructor(type): GenericConstructor<NormalizedObject> { public static getConstructor(type): GenericConstructor<NormalizedObject> {
switch (type) { switch (type) {
case AuthType.Eperson: { case AuthType.EPerson: {
return NormalizedEperson return NormalizedEPerson
} }
case AuthType.Status: { case AuthType.Status: {

View File

@@ -1,4 +1,4 @@
export enum AuthType { export enum AuthType {
Eperson = 'eperson', EPerson = 'eperson',
Status = 'status' Status = 'status'
} }

View File

@@ -5,7 +5,7 @@ import { Action } from '@ngrx/store';
import { type } from '../../shared/ngrx/type'; import { type } from '../../shared/ngrx/type';
// import models // import models
import { Eperson } from '../eperson/models/eperson.model'; import { EPerson } from '../eperson/models/eperson.model';
import { AuthTokenInfo } from './models/auth-token-info.model'; import { AuthTokenInfo } from './models/auth-token-info.model';
export const AuthActionTypes = { export const AuthActionTypes = {
@@ -76,10 +76,10 @@ export class AuthenticatedSuccessAction implements Action {
payload: { payload: {
authenticated: boolean; authenticated: boolean;
authToken: AuthTokenInfo; authToken: AuthTokenInfo;
user: Eperson user: EPerson
}; };
constructor(authenticated: boolean, authToken: AuthTokenInfo, user: Eperson) { constructor(authenticated: boolean, authToken: AuthTokenInfo, user: EPerson) {
this.payload = { authenticated, authToken, user }; this.payload = { authenticated, authToken, user };
} }
} }
@@ -250,9 +250,9 @@ export class RefreshTokenErrorAction implements Action {
*/ */
export class RegistrationAction implements Action { export class RegistrationAction implements Action {
public type: string = AuthActionTypes.REGISTRATION; public type: string = AuthActionTypes.REGISTRATION;
payload: Eperson; payload: EPerson;
constructor(user: Eperson) { constructor(user: EPerson) {
this.payload = user; this.payload = user;
} }
} }
@@ -278,9 +278,9 @@ export class RegistrationErrorAction implements Action {
*/ */
export class RegistrationSuccessAction implements Action { export class RegistrationSuccessAction implements Action {
public type: string = AuthActionTypes.REGISTRATION_SUCCESS; public type: string = AuthActionTypes.REGISTRATION_SUCCESS;
payload: Eperson; payload: EPerson;
constructor(user: Eperson) { constructor(user: EPerson) {
this.payload = user; this.payload = user;
} }
} }

View File

@@ -25,7 +25,7 @@ import { AuthServiceStub } from '../../shared/testing/auth-service-stub';
import { AuthService } from './auth.service'; import { AuthService } from './auth.service';
import { TruncatablesState } from '../../shared/truncatable/truncatable.reducer'; import { TruncatablesState } from '../../shared/truncatable/truncatable.reducer';
import { EpersonMock } from '../../shared/testing/eperson-mock'; import { EPersonMock } from '../../shared/testing/eperson-mock';
describe('AuthEffects', () => { describe('AuthEffects', () => {
let authEffects: AuthEffects; let authEffects: AuthEffects;
@@ -104,7 +104,7 @@ describe('AuthEffects', () => {
it('should return a AUTHENTICATED_SUCCESS action in response to a AUTHENTICATED action', () => { it('should return a AUTHENTICATED_SUCCESS action in response to a AUTHENTICATED action', () => {
actions = hot('--a-', {a: {type: AuthActionTypes.AUTHENTICATED, payload: token}}); actions = hot('--a-', {a: {type: AuthActionTypes.AUTHENTICATED, payload: token}});
const expected = cold('--b-', {b: new AuthenticatedSuccessAction(true, token, EpersonMock)}); const expected = cold('--b-', {b: new AuthenticatedSuccessAction(true, token, EPersonMock)});
expect(authEffects.authenticated$).toBeObservable(expected); expect(authEffects.authenticated$).toBeObservable(expected);
}); });

View File

@@ -28,7 +28,7 @@ import {
RegistrationErrorAction, RegistrationErrorAction,
RegistrationSuccessAction RegistrationSuccessAction
} from './auth.actions'; } from './auth.actions';
import { Eperson } from '../eperson/models/eperson.model'; import { EPerson } from '../eperson/models/eperson.model';
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 { AppState } from '../../app.reducer'; import { AppState } from '../../app.reducer';
@@ -63,7 +63,7 @@ export class AuthEffects {
.ofType(AuthActionTypes.AUTHENTICATED) .ofType(AuthActionTypes.AUTHENTICATED)
.switchMap((action: AuthenticatedAction) => { .switchMap((action: AuthenticatedAction) => {
return this.authService.authenticatedUser(action.payload) return this.authService.authenticatedUser(action.payload)
.map((user: Eperson) => new AuthenticatedSuccessAction((user !== null), action.payload, user)) .map((user: EPerson) => new AuthenticatedSuccessAction((user !== null), action.payload, user))
.catch((error) => Observable.of(new AuthenticatedErrorAction(error))); .catch((error) => Observable.of(new AuthenticatedErrorAction(error)));
}); });
@@ -88,7 +88,7 @@ export class AuthEffects {
.debounceTime(500) // to remove when functionality is implemented .debounceTime(500) // to remove when functionality is implemented
.switchMap((action: RegistrationAction) => { .switchMap((action: RegistrationAction) => {
return this.authService.create(action.payload) return this.authService.create(action.payload)
.map((user: Eperson) => new RegistrationSuccessAction(user)) .map((user: EPerson) => new RegistrationSuccessAction(user))
.catch((error) => Observable.of(new RegistrationErrorAction(error))); .catch((error) => Observable.of(new RegistrationErrorAction(error)));
}); });

View File

@@ -21,7 +21,7 @@ import {
SetRedirectUrlAction SetRedirectUrlAction
} 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';
describe('authReducer', () => { describe('authReducer', () => {
@@ -107,7 +107,7 @@ describe('authReducer', () => {
loading: true, loading: true,
info: undefined info: undefined
}; };
const action = new AuthenticatedSuccessAction(true, mockTokenInfo, EpersonMock); const action = new AuthenticatedSuccessAction(true, mockTokenInfo, EPersonMock);
const newState = authReducer(initialState, action); const newState = authReducer(initialState, action);
state = { state = {
authenticated: true, authenticated: true,
@@ -116,7 +116,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EpersonMock user: EPersonMock
}; };
expect(newState).toEqual(state); expect(newState).toEqual(state);
}); });
@@ -182,7 +182,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EpersonMock user: EPersonMock
}; };
const action = new LogOutAction(); const action = new LogOutAction();
@@ -199,7 +199,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EpersonMock user: EPersonMock
}; };
const action = new LogOutSuccessAction(); const action = new LogOutSuccessAction();
@@ -225,7 +225,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EpersonMock user: EPersonMock
}; };
const action = new LogOutErrorAction(mockError); const action = new LogOutErrorAction(mockError);
@@ -237,7 +237,7 @@ describe('authReducer', () => {
error: 'Test error message', error: 'Test error message',
loading: false, loading: false,
info: undefined, info: undefined,
user: EpersonMock user: EPersonMock
}; };
expect(newState).toEqual(state); expect(newState).toEqual(state);
}); });
@@ -250,7 +250,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EpersonMock user: EPersonMock
}; };
const newTokenInfo = new AuthTokenInfo('Refreshed token'); const newTokenInfo = new AuthTokenInfo('Refreshed token');
const action = new RefreshTokenAction(newTokenInfo); const action = new RefreshTokenAction(newTokenInfo);
@@ -262,7 +262,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EpersonMock, user: EPersonMock,
refreshing: true refreshing: true
}; };
expect(newState).toEqual(state); expect(newState).toEqual(state);
@@ -276,7 +276,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EpersonMock, user: EPersonMock,
refreshing: true refreshing: true
}; };
const newTokenInfo = new AuthTokenInfo('Refreshed token'); const newTokenInfo = new AuthTokenInfo('Refreshed token');
@@ -289,7 +289,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EpersonMock, user: EPersonMock,
refreshing: false refreshing: false
}; };
expect(newState).toEqual(state); expect(newState).toEqual(state);
@@ -303,7 +303,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EpersonMock, user: EPersonMock,
refreshing: true refreshing: true
}; };
const action = new RefreshTokenErrorAction(); const action = new RefreshTokenErrorAction();
@@ -329,7 +329,7 @@ describe('authReducer', () => {
error: undefined, error: undefined,
loading: false, loading: false,
info: undefined, info: undefined,
user: EpersonMock user: EPersonMock
}; };
state = { state = {

View File

@@ -12,7 +12,7 @@ import {
SetRedirectUrlAction SetRedirectUrlAction
} from './auth.actions'; } from './auth.actions';
// import models // import models
import { Eperson } from '../eperson/models/eperson.model'; import { EPerson } from '../eperson/models/eperson.model';
import { AuthTokenInfo } from './models/auth-token-info.model'; import { AuthTokenInfo } from './models/auth-token-info.model';
/** /**
@@ -46,7 +46,7 @@ export interface AuthState {
refreshing?: boolean; refreshing?: boolean;
// the authenticated user // the authenticated user
user?: Eperson; user?: EPerson;
} }
/** /**

View File

@@ -18,8 +18,8 @@ import { AuthRequestServiceStub } from '../../shared/testing/auth-request-servic
import { AuthRequestService } from './auth-request.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';
import { Eperson } from '../eperson/models/eperson.model'; import { EPerson } from '../eperson/models/eperson.model';
import { EpersonMock } from '../../shared/testing/eperson-mock'; import { EPersonMock } from '../../shared/testing/eperson-mock';
import { AppState } from '../../app.reducer'; import { AppState } from '../../app.reducer';
import { ClientCookieService } from '../../shared/services/client-cookie.service'; import { ClientCookieService } from '../../shared/services/client-cookie.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
@@ -44,7 +44,7 @@ describe('AuthService test', () => {
loaded: true, loaded: true,
loading: false, loading: false,
authToken: token, authToken: token,
user: EpersonMock user: EPersonMock
}; };
const rdbService = getMockRemoteDataBuildService(); const rdbService = getMockRemoteDataBuildService();
describe('', () => { describe('', () => {
@@ -82,7 +82,7 @@ describe('AuthService test', () => {
}); });
it('should return the authenticated user object when user token is valid', () => { it('should return the authenticated user object when user token is valid', () => {
authService.authenticatedUser(new AuthTokenInfo('test_token')).subscribe((user: Eperson) => { authService.authenticatedUser(new AuthTokenInfo('test_token')).subscribe((user: EPerson) => {
expect(user).toBeDefined(); expect(user).toBeDefined();
}); });
}); });
@@ -188,7 +188,7 @@ describe('AuthService test', () => {
loaded: true, loaded: true,
loading: false, loading: false,
authToken: expiredToken, authToken: expiredToken,
user: EpersonMock user: EPersonMock
}; };
store store
.subscribe((state) => { .subscribe((state) => {

View File

@@ -9,7 +9,7 @@ import { CookieAttributes } from 'js-cookie';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { map, switchMap, withLatestFrom } from 'rxjs/operators'; import { map, switchMap, withLatestFrom } from 'rxjs/operators';
import { Eperson } from '../eperson/models/eperson.model'; import { EPerson } from '../eperson/models/eperson.model';
import { AuthRequestService } from './auth-request.service'; import { AuthRequestService } from './auth-request.service';
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service'; import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
@@ -28,7 +28,7 @@ import { ResetAuthenticationMessagesAction, SetRedirectUrlAction } from './auth.
import { NativeWindowRef, NativeWindowService } from '../../shared/services/window.service'; import { NativeWindowRef, NativeWindowService } from '../../shared/services/window.service';
import { Base64EncodeUrl } from '../../shared/utils/encode-decode.util'; import { Base64EncodeUrl } from '../../shared/utils/encode-decode.util';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { NormalizedEperson } from '../eperson/models/NormalizedEperson.model'; import { NormalizedEPerson } from '../eperson/models/normalized-eperson.model';
export const LOGIN_ROUTE = '/login'; export const LOGIN_ROUTE = '/login';
export const LOGOUT_ROUTE = '/logout'; export const LOGOUT_ROUTE = '/logout';
@@ -107,7 +107,7 @@ export class AuthService {
if (status.authenticated) { if (status.authenticated) {
return status; return status;
} else { } else {
throw(new Error('Invalid email or password')); Observable.throw(new Error('Invalid email or password'));
} }
}) })
@@ -125,7 +125,7 @@ export class AuthService {
* Returns the authenticated user * Returns the authenticated user
* @returns {User} * @returns {User}
*/ */
public authenticatedUser(token: AuthTokenInfo): Observable<Eperson> { public authenticatedUser(token: AuthTokenInfo): Observable<EPerson> {
// Determine if the user has an existing auth session on the server // Determine if the user has an existing auth session on the server
const options: HttpOptions = Object.create({}); const options: HttpOptions = Object.create({});
let headers = new HttpHeaders(); let headers = new HttpHeaders();
@@ -136,10 +136,8 @@ export class AuthService {
switchMap((status: AuthStatus) => { switchMap((status: AuthStatus) => {
if (status.authenticated) { if (status.authenticated) {
// TODO this should be cleaned up, AuthStatus could be parsed by the RemoteDataService as a whole... // TODO this should be cleaned up, AuthStatus could be parsed by the RemoteDataService as a whole...
const person$ = this.rdbService.buildSingle<NormalizedEperson, Eperson>(status.eperson.toString()); const person$ = this.rdbService.buildSingle<NormalizedEPerson, EPerson>(status.eperson.toString());
// person$.subscribe(() => console.log('test'));
return person$.pipe(map((eperson) => eperson.payload)); return person$.pipe(map((eperson) => eperson.payload));
} else { } else {
throw(new Error('Not authenticated')); throw(new Error('Not authenticated'));
@@ -202,7 +200,7 @@ export class AuthService {
* Create a new user * Create a new user
* @returns {User} * @returns {User}
*/ */
public create(user: Eperson): Observable<Eperson> { public create(user: EPerson): Observable<EPerson> {
// Normally you would do an HTTP request to POST the user // Normally you would do an HTTP request to POST the user
// details and then return the new user object // details and then return the new user object
// but, let's just return the new user for this example. // but, let's just return the new user for this example.

View File

@@ -1,6 +1,6 @@
import { AuthError } from './auth-error.model'; import { AuthError } from './auth-error.model';
import { AuthTokenInfo } from './auth-token-info.model'; import { AuthTokenInfo } from './auth-token-info.model';
import { Eperson } from '../../eperson/models/eperson.model'; import { EPerson } from '../../eperson/models/eperson.model';
import { RemoteData } from '../../data/remote-data'; import { RemoteData } from '../../data/remote-data';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
@@ -14,7 +14,7 @@ export class AuthStatus {
error?: AuthError; error?: AuthError;
eperson: Observable<RemoteData<Eperson>>; eperson: Observable<RemoteData<EPerson>>;
token?: AuthTokenInfo; token?: AuthTokenInfo;

View File

@@ -26,7 +26,7 @@ export class NormalizedAuthStatus extends NormalizedObject {
@autoserialize @autoserialize
authenticated: boolean; authenticated: boolean;
@relationship(ResourceType.Eperson, false) @relationship(ResourceType.EPerson, false)
@autoserialize @autoserialize
eperson: string; eperson: string;
} }

View File

@@ -1,4 +1,4 @@
import {first, map} from 'rxjs/operators'; import { first, map, switchMap } from 'rxjs/operators';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
@@ -9,7 +9,8 @@ import { isNotEmpty } from '../../shared/empty.util';
import { AuthService } from './auth.service'; import { AuthService } from './auth.service';
import { AuthTokenInfo } from './models/auth-token-info.model'; import { AuthTokenInfo } from './models/auth-token-info.model';
import { CheckAuthenticationTokenAction } from './auth.actions'; import { CheckAuthenticationTokenAction } from './auth.actions';
import { Eperson } from '../eperson/models/eperson.model'; import { EPerson } from '../eperson/models/eperson.model';
import { NormalizedEPerson } from '../eperson/models/normalized-eperson.model';
/** /**
* The auth service. * The auth service.
@@ -21,7 +22,7 @@ export class ServerAuthService extends AuthService {
* Returns the authenticated user * Returns the authenticated user
* @returns {User} * @returns {User}
*/ */
public authenticatedUser(token: AuthTokenInfo): Observable<Eperson> { public authenticatedUser(token: AuthTokenInfo): Observable<EPerson> {
// Determine if the user has an existing auth session on the server // Determine if the user has an existing auth session on the server
const options: HttpOptions = Object.create({}); const options: HttpOptions = Object.create({});
let headers = new HttpHeaders(); let headers = new HttpHeaders();
@@ -34,13 +35,18 @@ export class ServerAuthService extends AuthService {
options.headers = headers; options.headers = headers;
return this.authRequestService.getRequest('status', options).pipe( return this.authRequestService.getRequest('status', options).pipe(
map((status: AuthStatus) => { switchMap((status: AuthStatus) => {
if (status.authenticated) { if (status.authenticated) {
return status.eperson[0];
// TODO this should be cleaned up, AuthStatus could be parsed by the RemoteDataService as a whole...
const person$ = this.rdbService.buildSingle<NormalizedEPerson, EPerson>(status.eperson.toString());
// person$.subscribe(() => console.log('test'));
return person$.pipe(map((eperson) => eperson.payload));
} else { } else {
throw(new Error('Not authenticated')); Observable.throw(new Error('Not authenticated'));
} }
})); }))
} }
/** /**

View File

@@ -8,8 +8,8 @@ import { ResourceType } from '../../shared/resource-type';
import { NormalizedObject } from './normalized-object.model'; import { NormalizedObject } from './normalized-object.model';
import { NormalizedBitstreamFormat } from './normalized-bitstream-format.model'; import { NormalizedBitstreamFormat } from './normalized-bitstream-format.model';
import { NormalizedResourcePolicy } from './normalized-resource-policy.model'; import { NormalizedResourcePolicy } from './normalized-resource-policy.model';
import { NormalizedEperson } from '../../eperson/models/NormalizedEperson.model'; import { NormalizedEPerson } from '../../eperson/models/normalized-eperson.model';
import { NormalizedGroup } from '../../eperson/models/NormalizedGroup.model'; import { NormalizedGroup } from '../../eperson/models/normalized-group.model';
export class NormalizedObjectFactory { export class NormalizedObjectFactory {
public static getConstructor(type: ResourceType): GenericConstructor<NormalizedObject> { public static getConstructor(type: ResourceType): GenericConstructor<NormalizedObject> {
@@ -35,8 +35,8 @@ export class NormalizedObjectFactory {
case ResourceType.ResourcePolicy: { case ResourceType.ResourcePolicy: {
return NormalizedResourcePolicy return NormalizedResourcePolicy
} }
case ResourceType.Eperson: { case ResourceType.EPerson: {
return NormalizedEperson return NormalizedEPerson
} }
case ResourceType.Group: { case ResourceType.Group: {
return NormalizedGroup return NormalizedGroup

View File

@@ -7,6 +7,8 @@ import { GlobalConfig } from '../../../config/global-config.interface';
import { GenericConstructor } from '../shared/generic-constructor'; import { GenericConstructor } from '../shared/generic-constructor';
import { PaginatedList } from './paginated-list'; import { PaginatedList } from './paginated-list';
import { NormalizedObject } from '../cache/models/normalized-object.model'; import { NormalizedObject } from '../cache/models/normalized-object.model';
import { ResourceType } from '../shared/resource-type';
import { RESTURLCombiner } from '../url-combiner/rest-url-combiner';
function isObjectLevel(halObj: any) { function isObjectLevel(halObj: any) {
return isNotEmpty(halObj._links) && hasValue(halObj._links.self); return isNotEmpty(halObj._links) && hasValue(halObj._links.self);
@@ -34,6 +36,7 @@ export abstract class BaseResponseParsingService {
} else if (Array.isArray(data)) { } else if (Array.isArray(data)) {
return this.processArray(data, requestHref); return this.processArray(data, requestHref);
} else if (isObjectLevel(data)) { } else if (isObjectLevel(data)) {
data = this.fixBadEPersonRestResponse(data);
const object = this.deserialize(data); const object = this.deserialize(data);
if (isNotEmpty(data._embedded)) { if (isNotEmpty(data._embedded)) {
Object Object
@@ -53,6 +56,7 @@ export abstract class BaseResponseParsingService {
} }
}); });
} }
this.cache(object, requestHref); this.cache(object, requestHref);
return object; return object;
} }
@@ -145,4 +149,22 @@ export abstract class BaseResponseParsingService {
} }
return obj[keys[0]]; return obj[keys[0]];
} }
/* TODO remove when REST response for epersons is fixed */
private fixBadEPersonRestResponse(obj: any): any {
if (obj.type === ResourceType.EPerson) {
const groups = obj.groups;
const normGroups = [];
if (isNotEmpty(groups)) {
groups.forEach((group) => {
const parts = ['eperson', 'groups', group.uuid];
const href = new RESTURLCombiner(this.EnvConfig, ...parts).toString();
normGroups.push(href);
}
)
}
return Object.assign({}, obj, { groups: normGroups });
}
return obj;
}
} }

View File

@@ -1,7 +1,7 @@
import { DSpaceObject } from '../../shared/dspace-object.model'; import { DSpaceObject } from '../../shared/dspace-object.model';
import { Group } from './group.model'; import { Group } from './group.model';
export class Eperson extends DSpaceObject { export class EPerson extends DSpaceObject {
public handle: string; public handle: string;

View File

@@ -2,13 +2,13 @@ import { autoserialize, inheritSerialization } from 'cerialize';
import { CacheableObject } from '../../cache/object-cache.reducer'; import { CacheableObject } from '../../cache/object-cache.reducer';
import { ListableObject } from '../../../shared/object-collection/shared/listable-object.model'; import { ListableObject } from '../../../shared/object-collection/shared/listable-object.model';
import { NormalizedDSpaceObject } from '../../cache/models/normalized-dspace-object.model'; import { NormalizedDSpaceObject } from '../../cache/models/normalized-dspace-object.model';
import { Eperson } from './eperson.model'; import { EPerson } from './eperson.model';
import { mapsTo, relationship } from '../../cache/builders/build-decorators'; import { mapsTo, relationship } from '../../cache/builders/build-decorators';
import { ResourceType } from '../../shared/resource-type'; import { ResourceType } from '../../shared/resource-type';
@mapsTo(Eperson) @mapsTo(EPerson)
@inheritSerialization(NormalizedDSpaceObject) @inheritSerialization(NormalizedDSpaceObject)
export class NormalizedEperson extends NormalizedDSpaceObject implements CacheableObject, ListableObject { export class NormalizedEPerson extends NormalizedDSpaceObject implements CacheableObject, ListableObject {
@autoserialize @autoserialize
public handle: string; public handle: string;

View File

@@ -6,7 +6,7 @@ export enum ResourceType {
Item = 'item', Item = 'item',
Collection = 'collection', Collection = 'collection',
Community = 'community', Community = 'community',
Eperson = 'eperson', EPerson = 'eperson',
Group = 'group', Group = 'group',
ResourcePolicy = 'resourcePolicy' ResourcePolicy = 'resourcePolicy'
} }

View File

@@ -5,7 +5,7 @@ import { By } from '@angular/platform-browser';
import { Store, StoreModule } from '@ngrx/store'; import { Store, StoreModule } from '@ngrx/store';
import { authReducer, AuthState } from '../../core/auth/auth.reducer'; import { authReducer, AuthState } from '../../core/auth/auth.reducer';
import { EpersonMock } from '../testing/eperson-mock'; import { EPersonMock } from '../testing/eperson-mock';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { AppState } from '../../app.reducer'; import { AppState } from '../../app.reducer';
import { AuthNavMenuComponent } from './auth-nav-menu.component'; import { AuthNavMenuComponent } from './auth-nav-menu.component';
@@ -13,6 +13,7 @@ import { HostWindowServiceStub } from '../testing/host-window-service-stub';
import { HostWindowService } from '../host-window.service'; import { HostWindowService } from '../host-window.service';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model'; import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
import { EPerson } from '../../core/eperson/models/eperson.model';
describe('AuthNavMenuComponent', () => { describe('AuthNavMenuComponent', () => {
@@ -31,7 +32,7 @@ describe('AuthNavMenuComponent', () => {
loaded: true, loaded: true,
loading: false, loading: false,
authToken: new AuthTokenInfo('test_token'), authToken: new AuthTokenInfo('test_token'),
user: EpersonMock user: EPersonMock
}; };
let routerState = { let routerState = {
url: '/home' url: '/home'

View File

@@ -8,7 +8,7 @@ import { HostWindowService } from '../host-window.service';
import { AppState, routerStateSelector } from '../../app.reducer'; import { AppState, routerStateSelector } from '../../app.reducer';
import { isNotUndefined } from '../empty.util'; import { isNotUndefined } from '../empty.util';
import { getAuthenticatedUser, isAuthenticated, isAuthenticationLoading } from '../../core/auth/selectors'; import { getAuthenticatedUser, isAuthenticated, isAuthenticationLoading } from '../../core/auth/selectors';
import { Eperson } from '../../core/eperson/models/eperson.model'; import { EPerson } from '../../core/eperson/models/eperson.model';
import { LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service'; import { LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
@@ -35,7 +35,7 @@ export class AuthNavMenuComponent implements OnInit {
public showAuth = Observable.of(false); public showAuth = Observable.of(false);
public user: Observable<Eperson>; public user: Observable<EPerson>;
constructor(private store: Store<AppState>, constructor(private store: Store<AppState>,
private windowService: HostWindowService) { private windowService: HostWindowService) {

View File

@@ -7,8 +7,8 @@ import { Store, StoreModule } from '@ngrx/store';
import { LogInComponent } from './log-in.component'; import { LogInComponent } from './log-in.component';
import { authReducer } from '../../core/auth/auth.reducer'; import { authReducer } from '../../core/auth/auth.reducer';
import { EpersonMock } from '../testing/eperson-mock'; import { EPersonMock } from '../testing/eperson-mock';
import { Eperson } from '../../core/eperson/models/eperson.model'; import { EPerson } from '../../core/eperson/models/eperson.model';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { AuthService } from '../../core/auth/auth.service'; import { AuthService } from '../../core/auth/auth.service';
import { AuthServiceStub } from '../testing/auth-service-stub'; import { AuthServiceStub } from '../testing/auth-service-stub';
@@ -19,7 +19,7 @@ describe('LogInComponent', () => {
let component: LogInComponent; let component: LogInComponent;
let fixture: ComponentFixture<LogInComponent>; let fixture: ComponentFixture<LogInComponent>;
let page: Page; let page: Page;
let user: Eperson; let user: EPerson;
const authState = { const authState = {
authenticated: false, authenticated: false,
@@ -28,7 +28,7 @@ describe('LogInComponent', () => {
}; };
beforeEach(() => { beforeEach(() => {
user = EpersonMock; user = EPersonMock;
}); });
beforeEach(async(() => { beforeEach(async(() => {

View File

@@ -5,8 +5,8 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { Store, StoreModule } from '@ngrx/store'; import { Store, StoreModule } from '@ngrx/store';
import { authReducer } from '../../core/auth/auth.reducer'; import { authReducer } from '../../core/auth/auth.reducer';
import { EpersonMock } from '../testing/eperson-mock'; import { EPersonMock } from '../testing/eperson-mock';
import { Eperson } from '../../core/eperson/models/eperson.model'; import { EPerson } from '../../core/eperson/models/eperson.model';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { AppState } from '../../app.reducer'; import { AppState } from '../../app.reducer';
@@ -18,7 +18,7 @@ describe('LogOutComponent', () => {
let component: LogOutComponent; let component: LogOutComponent;
let fixture: ComponentFixture<LogOutComponent>; let fixture: ComponentFixture<LogOutComponent>;
let page: Page; let page: Page;
let user: Eperson; let user: EPerson;
const authState = { const authState = {
authenticated: false, authenticated: false,
@@ -28,7 +28,7 @@ describe('LogOutComponent', () => {
const routerStub = new RouterStub(); const routerStub = new RouterStub();
beforeEach(() => { beforeEach(() => {
user = EpersonMock; user = EPersonMock;
}); });
beforeEach(async(() => { beforeEach(async(() => {

View File

@@ -2,13 +2,13 @@ import { Observable } from 'rxjs/Observable';
import { HttpOptions } from '../../core/dspace-rest-v2/dspace-rest-v2.service'; import { HttpOptions } from '../../core/dspace-rest-v2/dspace-rest-v2.service';
import { AuthStatus } from '../../core/auth/models/auth-status.model'; import { AuthStatus } from '../../core/auth/models/auth-status.model';
import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model'; import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
import { Eperson } from '../../core/eperson/models/eperson.model'; import { EPerson } from '../../core/eperson/models/eperson.model';
import { isNotEmpty } from '../empty.util'; import { isNotEmpty } from '../empty.util';
import { EpersonMock } from './eperson-mock'; import { EPersonMock } from './eperson-mock';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
export class AuthRequestServiceStub { export class AuthRequestServiceStub {
protected mockUser: Eperson = EpersonMock; protected mockUser: EPerson = EPersonMock;
protected mockTokenInfo = new AuthTokenInfo('test_token'); protected mockTokenInfo = new AuthTokenInfo('test_token');
public postToEndpoint(method: string, body: any, options?: HttpOptions): Observable<any> { public postToEndpoint(method: string, body: any, options?: HttpOptions): Observable<any> {
@@ -27,7 +27,7 @@ export class AuthRequestServiceStub {
if (this.validateToken(token)) { if (this.validateToken(token)) {
authStatusStub.authenticated = true; authStatusStub.authenticated = true;
authStatusStub.token = this.mockTokenInfo; authStatusStub.token = this.mockTokenInfo;
authStatusStub.eperson = Observable.of(new RemoteData<Eperson>(false, false, true, undefined, this.mockUser)); authStatusStub.eperson = Observable.of(new RemoteData<EPerson>(false, false, true, undefined, this.mockUser));
} else { } else {
authStatusStub.authenticated = false; authStatusStub.authenticated = false;
} }
@@ -46,7 +46,7 @@ export class AuthRequestServiceStub {
if (this.validateToken(token)) { if (this.validateToken(token)) {
authStatusStub.authenticated = true; authStatusStub.authenticated = true;
authStatusStub.token = this.mockTokenInfo; authStatusStub.token = this.mockTokenInfo;
authStatusStub.eperson = Observable.of(new RemoteData<Eperson>(false, false, true, undefined, this.mockUser)); authStatusStub.eperson = Observable.of(new RemoteData<EPerson>(false, false, true, undefined, this.mockUser));
} else { } else {
authStatusStub.authenticated = false; authStatusStub.authenticated = false;
} }

View File

@@ -1,8 +1,8 @@
import { AuthStatus } from '../../core/auth/models/auth-status.model'; import { AuthStatus } from '../../core/auth/models/auth-status.model';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model'; import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
import { EpersonMock } from './eperson-mock'; import { EPersonMock } from './eperson-mock';
import { Eperson } from '../../core/eperson/models/eperson.model'; import { EPerson } from '../../core/eperson/models/eperson.model';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
export class AuthServiceStub { export class AuthServiceStub {
@@ -20,7 +20,7 @@ export class AuthServiceStub {
authStatus.okay = true; authStatus.okay = true;
authStatus.authenticated = true; authStatus.authenticated = true;
authStatus.token = this.token; authStatus.token = this.token;
authStatus.eperson = Observable.of(new RemoteData<Eperson>(false, false, true, undefined, EpersonMock)); authStatus.eperson = Observable.of(new RemoteData<EPerson>(false, false, true, undefined, EPersonMock));
return Observable.of(authStatus); return Observable.of(authStatus);
} else { } else {
console.log('error'); console.log('error');
@@ -28,9 +28,9 @@ export class AuthServiceStub {
} }
} }
public authenticatedUser(token: AuthTokenInfo): Observable<Eperson> { public authenticatedUser(token: AuthTokenInfo): Observable<EPerson> {
if (token.accessToken === 'token_test') { if (token.accessToken === 'token_test') {
return Observable.of(EpersonMock); return Observable.of(EPersonMock);
} else { } else {
throw(new Error('Message Error test')); throw(new Error('Message Error test'));
} }

View File

@@ -1,6 +1,6 @@
import { Eperson } from '../../core/eperson/models/eperson.model'; import { EPerson } from '../../core/eperson/models/eperson.model';
export const EpersonMock: Eperson = Object.assign(new Eperson(),{ export const EPersonMock: EPerson = Object.assign(new EPerson(),{
handle: null, handle: null,
groups: [], groups: [],
netid: 'test@test.com', netid: 'test@test.com',