Correct parsing of AuthStatus and small changes

This commit is contained in:
Kristof De Langhe
2018-09-10 08:44:56 +02:00
parent 0455a16d03
commit ea075fbd8f
7 changed files with 10 additions and 9 deletions

View File

@@ -26,8 +26,9 @@ export class AuthResponseParsingService extends BaseResponseParsingService imple
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links) && (data.statusCode === '200' || data.statusCode === 'OK')) { if (isNotEmpty(data.payload) && isNotEmpty(data.payload._links) && (data.statusCode === '200' || data.statusCode === 'OK')) {
const response = this.process<AuthStatus, AuthType>(data.payload, request.href); const response: AuthStatus = this.process<AuthStatus, AuthType>(data.payload, request.href);
return new AuthStatusResponse(response[Object.keys(response)[0]][0], data.statusCode); response.eperson = data.payload._embedded.eperson;
return new AuthStatusResponse(response, data.statusCode);
} else { } else {
return new AuthStatusResponse(data.payload as AuthStatus, data.statusCode); return new AuthStatusResponse(data.payload as AuthStatus, data.statusCode);
} }

View File

@@ -126,7 +126,7 @@ export class AuthService {
return this.authRequestService.getRequest('status', options) return this.authRequestService.getRequest('status', options)
.map((status: AuthStatus) => { .map((status: AuthStatus) => {
if (status.authenticated) { if (status.authenticated) {
return status.eperson[0]; return status.eperson;
} else { } else {
throw(new Error('Not authenticated')); throw(new Error('Not authenticated'));
} }

View File

@@ -13,7 +13,7 @@ export class AuthStatus {
error?: AuthError; error?: AuthError;
eperson: Eperson[]; eperson: Eperson;
token?: AuthTokenInfo; token?: AuthTokenInfo;

View File

@@ -21,6 +21,6 @@ export class NormalizedAuthStatus extends NormalizedDSpaceObject {
authenticated: boolean; authenticated: boolean;
@autoserializeAs(Eperson) @autoserializeAs(Eperson)
eperson: Eperson[]; eperson: Eperson;
} }

View File

@@ -35,7 +35,7 @@ export class ServerAuthService extends AuthService {
return this.authRequestService.getRequest('status', options) return this.authRequestService.getRequest('status', options)
.map((status: AuthStatus) => { .map((status: AuthStatus) => {
if (status.authenticated) { if (status.authenticated) {
return status.eperson[0]; return status.eperson;
} else { } else {
throw(new Error('Not authenticated')); throw(new Error('Not authenticated'));
} }

View File

@@ -26,7 +26,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 = [this.mockUser]; authStatusStub.eperson = this.mockUser;
} else { } else {
authStatusStub.authenticated = false; authStatusStub.authenticated = false;
} }
@@ -45,7 +45,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 = [this.mockUser]; authStatusStub.eperson = this.mockUser;
} else { } else {
authStatusStub.authenticated = false; authStatusStub.authenticated = false;
} }

View File

@@ -19,7 +19,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 = [EpersonMock]; authStatus.eperson = EpersonMock;
return Observable.of(authStatus); return Observable.of(authStatus);
} else { } else {
console.log('error'); console.log('error');