mirror of
https://github.com/ceph/ceph
synced 2025-03-11 02:39:05 +00:00
Merge pull request #43640 from rhcs-dashboard/module-status-guard-error-handling
mgr/dashboard: Proper error handling in module status guard Reviewed-by: Alfonso Martínez <almartin@redhat.com> Reviewed-by: Avan Thakkar <athakkar@redhat.com> Reviewed-by: Nizamudeen A <nia@redhat.com> Reviewed-by: Pere Diaz Bou <pdiazbou@redhat.com>
This commit is contained in:
commit
8a4649e651
@ -4,7 +4,7 @@ import { fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
import { ActivatedRouteSnapshot, Router, Routes } from '@angular/router';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { of as observableOf, throwError } from 'rxjs';
|
||||
|
||||
import { configureTestBed } from '~/testing/unit-test-helper';
|
||||
import { MgrModuleService } from '../api/mgr-module.service';
|
||||
@ -31,12 +31,16 @@ describe('ModuleStatusGuardService', () => {
|
||||
getResult: {},
|
||||
activateResult: boolean,
|
||||
urlResult: string,
|
||||
backend = 'cephadm'
|
||||
backend = 'cephadm',
|
||||
configOptPermission = true
|
||||
) => {
|
||||
let result: boolean;
|
||||
spyOn(httpClient, 'get').and.returnValue(observableOf(getResult));
|
||||
const test = { orchestrator: backend };
|
||||
spyOn(mgrModuleService, 'getConfig').and.returnValue(observableOf(test));
|
||||
const orchBackend = { orchestrator: backend };
|
||||
const getConfigSpy = spyOn(mgrModuleService, 'getConfig');
|
||||
configOptPermission
|
||||
? getConfigSpy.and.returnValue(observableOf(orchBackend))
|
||||
: getConfigSpy.and.returnValue(throwError({}));
|
||||
ngZone.run(() => {
|
||||
service.canActivateChild(route).subscribe((resp) => {
|
||||
result = resp;
|
||||
@ -91,4 +95,8 @@ describe('ModuleStatusGuardService', () => {
|
||||
it('should redirect normally if the backend provided matches the current backend', fakeAsync(() => {
|
||||
testCanActivate({ available: true, message: 'foo' }, true, '/', 'rook');
|
||||
}));
|
||||
|
||||
it('should redirect to the "redirectTo" link for user without sufficient permission', fakeAsync(() => {
|
||||
testCanActivate({ available: true, message: 'foo' }, true, '/foo', 'rook', false);
|
||||
}));
|
||||
});
|
||||
|
@ -61,9 +61,15 @@ export class ModuleStatusGuardService implements CanActivate, CanActivateChild {
|
||||
const config = route.data['moduleStatusGuardConfig'];
|
||||
let backendCheck = false;
|
||||
if (config.backend) {
|
||||
this.mgrModuleService.getConfig('orchestrator').subscribe((resp) => {
|
||||
backendCheck = config.backend === resp['orchestrator'];
|
||||
});
|
||||
this.mgrModuleService.getConfig('orchestrator').subscribe(
|
||||
(resp) => {
|
||||
backendCheck = config.backend === resp['orchestrator'];
|
||||
},
|
||||
() => {
|
||||
this.router.navigate([config.redirectTo]);
|
||||
return observableOf(false);
|
||||
}
|
||||
);
|
||||
}
|
||||
return this.http.get(`api/${config.apiPath}/status`).pipe(
|
||||
map((resp: any) => {
|
||||
|
Loading…
Reference in New Issue
Block a user