import { of as observableOf } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
-import { ServicesModule } from './services.module';
+import { MgrModuleService } from '~/app/shared/api/mgr-module.service';
+import { Icons } from '~/app/shared/enum/icons.enum';
/**
* This service checks if a route can be activated by executing a
- * REST API call to '/api/<apiPath>/status'. If the returned response
+ * REST API call to '/ui-api/<uiApiPath>/status'. If the returned response
* states that the module is not available, then the user is redirected
* to the specified <redirectTo> URL path.
*
* canActivate: [AuthGuardService, ModuleStatusGuardService],
* data: {
* moduleStatusGuardConfig: {
- * apiPath: 'rgw',
+ * uiApiPath: 'rgw',
* redirectTo: 'rgw/501'
* }
* }
* ...
*/
@Injectable({
- providedIn: ServicesModule
+ providedIn: 'root'
})
export class ModuleStatusGuardService implements CanActivate, CanActivateChild {
- // TODO: Hotfix - remove WHITELIST'ing when a generic ErrorComponent is implemented
- static readonly WHITELIST: string[] = ['501'];
+ // TODO: Hotfix - remove ALLOWLIST'ing when a generic ErrorComponent is implemented
+ static readonly ALLOWLIST: string[] = ['501'];
- constructor(private http: HttpClient, private router: Router) {}
+ constructor(
+ private http: HttpClient,
+ private router: Router,
+ private mgrModuleService: MgrModuleService
+ ) {}
canActivate(route: ActivatedRouteSnapshot) {
return this.doCheck(route);
}
private doCheck(route: ActivatedRouteSnapshot) {
- if (route.url.length > 0 && ModuleStatusGuardService.WHITELIST.includes(route.url[0].path)) {
+ if (route.url.length > 0 && ModuleStatusGuardService.ALLOWLIST.includes(route.url[0].path)) {
return observableOf(true);
}
const config = route.data['moduleStatusGuardConfig'];
- return this.http.get(`/api/${config.apiPath}/status`).pipe(
+ let backendCheck = false;
+ if (config.backend) {
+ this.mgrModuleService.getConfig('orchestrator').subscribe(
+ (resp) => {
+ backendCheck = config.backend === resp['orchestrator'];
+ },
+ () => {
+ this.router.navigate([config.redirectTo]);
+ return observableOf(false);
+ }
+ );
+ }
+ return this.http.get(`ui-api/${config.uiApiPath}/status`).pipe(
map((resp: any) => {
- if (!resp.available) {
- this.router.navigate([config.redirectTo, resp.message || '']);
+ if (!resp.available && !backendCheck) {
+ this.router.navigate([config.redirectTo || ''], {
+ state: {
+ header: config.header,
+ message: resp.message,
+ section: config.section,
+ section_info: config.section_info,
+ button_name: config.button_name,
+ button_route: config.button_route,
+ button_title: config.button_title,
+ uiConfig: config.uiConfig,
+ uiApiPath: config.uiApiPath,
+ icon: Icons.wrench,
+ component: config.component
+ }
+ });
}
return resp.available;
}),