mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[AAE-10556] Admin with HxP - In case the roles API call fails the app crashes (#7895)
* [AAE-10556] Admin with HxP - In case the roles API call fails the app crashes * Added tests for API error
This commit is contained in:
parent
508ea87621
commit
6559cd2564
@ -20,7 +20,7 @@ import { TestBed } from '@angular/core/testing';
|
||||
import { UserAccessService } from './user-access.service';
|
||||
import { JwtHelperService } from './jwt-helper.service';
|
||||
import { OAuth2Service } from './oauth2.service';
|
||||
import { of } from 'rxjs';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import { userAccessMock } from '../mock/user-access.mock';
|
||||
import { AppConfigService } from '../app-config';
|
||||
|
||||
@ -161,5 +161,12 @@ describe('UserAccessService', () => {
|
||||
|
||||
expect(getAccessFromApiSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should set empty access list on fething roles error', async () => {
|
||||
getAccessFromApiSpy.and.returnValue(throwError({ status: 503 }));
|
||||
await userAccessService.fetchUserAccess();
|
||||
|
||||
expect(userAccessService.hasGlobalAccess(['MOCKED_ROLES'])).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -21,6 +21,8 @@ import { ApplicationAccessModel } from '../models/application-access.model';
|
||||
import { UserAccessModel } from '../models/user-access.model';
|
||||
import { AppConfigService } from '../app-config/app-config.service';
|
||||
import { OAuth2Service } from './oauth2.service';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
const IDENTITY_MICRO_SERVICE_INGRESS = 'identity-adapter-service';
|
||||
|
||||
@ -54,6 +56,14 @@ export class UserAccessService {
|
||||
private async fetchAccessFromApi() {
|
||||
const url = `${this.identityHost}/${IDENTITY_MICRO_SERVICE_INGRESS}/v1/roles`;
|
||||
await this.oAuth2Service.get({ url })
|
||||
.pipe(
|
||||
catchError(() => of({
|
||||
globalAccess: {
|
||||
roles: []
|
||||
},
|
||||
applicationAccess: []
|
||||
}))
|
||||
)
|
||||
.toPromise()
|
||||
.then((response: UserAccessModel) => {
|
||||
this.globalAccess = response.globalAccess.roles;
|
||||
|
Loading…
x
Reference in New Issue
Block a user