mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
Correct parsing of AuthStatus and small changes
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
@@ -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'));
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ export class AuthStatus {
|
|||||||
|
|
||||||
error?: AuthError;
|
error?: AuthError;
|
||||||
|
|
||||||
eperson: Eperson[];
|
eperson: Eperson;
|
||||||
|
|
||||||
token?: AuthTokenInfo;
|
token?: AuthTokenInfo;
|
||||||
|
|
||||||
|
@@ -21,6 +21,6 @@ export class NormalizedAuthStatus extends NormalizedDSpaceObject {
|
|||||||
authenticated: boolean;
|
authenticated: boolean;
|
||||||
|
|
||||||
@autoserializeAs(Eperson)
|
@autoserializeAs(Eperson)
|
||||||
eperson: Eperson[];
|
eperson: Eperson;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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'));
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
|
@@ -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');
|
||||||
|
Reference in New Issue
Block a user