@@ -28,7 +28,7 @@ import { AuthUtilsService } from '@common/utils/auth.utils';
28
28
import { CommonHttpService } from '@common/api/common-http.service' ;
29
29
import { AuthService } from '@services/auth.service' ;
30
30
import { SettingsService } from '@services/settings.service' ;
31
- import { switchMap } from 'rxjs/operators' ;
31
+ import { switchMap , take } from 'rxjs/operators' ;
32
32
import { FrameService } from '../frame.service' ;
33
33
34
34
@Component ( {
@@ -70,6 +70,7 @@ export class HeaderComponent implements OnInit, OnDestroy {
70
70
private _getRebrandCustomValuesSubscription ;
71
71
private _clusterNameSubScription ;
72
72
public isAuthReadConfig : boolean = false ;
73
+ member$ = this . multiClusterService . member$ ;
73
74
74
75
@ViewChild ( 'fsbutton' , { static : true } ) fsbutton ;
75
76
@@ -284,102 +285,98 @@ export class HeaderComponent implements OnInit, OnDestroy {
284
285
} ) ;
285
286
}
286
287
getClusters ( ) {
287
- this . multiClusterService
288
- . getClusters ( )
289
- . pipe ( )
290
- . subscribe ( {
291
- next : ( data : ClusterData ) => {
292
- this . clusters = data . clusters || [ ] ;
293
- //get primary cluster's rest_version
294
- const primaryCluster = this . clusters . find (
295
- cluster =>
296
- cluster . clusterType === GlobalConstant . CLUSTER_TYPES . MASTER
297
- ) ;
298
- this . primaryClusterRestVersion = primaryCluster
299
- ? primaryCluster . rest_version
300
- : '' ;
301
- this . multiClusterService . primaryClusterRestVersion =
302
- this . primaryClusterRestVersion ;
303
- //init the cluster role
304
- this . isMemberRole = data . fed_role === MapConstant . FED_ROLES . MEMBER ;
305
- this . isMasterRole = data . fed_role === MapConstant . FED_ROLES . MASTER ;
306
- this . isStandaloneRole = data . fed_role === '' ;
307
- GlobalVariable . isMaster = this . isMasterRole ;
308
- GlobalVariable . isMember = this . isMemberRole ;
309
- GlobalVariable . isStandAlone = this . isStandaloneRole ;
310
-
311
- const resource = {
312
- multiClusterOp : {
313
- global : 2 ,
314
- } ,
315
- manageAuth : {
316
- global : 3 ,
317
- } ,
318
- multiClusterView : {
319
- global : 1 ,
320
- } ,
321
- } ;
322
-
323
- this . isAllowedToRedirectMultiCluster =
288
+ this . member$ . pipe ( take ( 1 ) ) . subscribe ( {
289
+ next : ( data : ClusterData ) => {
290
+ this . clusters = data . clusters || [ ] ;
291
+ //get primary cluster's rest_version
292
+ const primaryCluster = this . clusters . find (
293
+ cluster => cluster . clusterType === GlobalConstant . CLUSTER_TYPES . MASTER
294
+ ) ;
295
+ this . primaryClusterRestVersion = primaryCluster
296
+ ? primaryCluster . rest_version
297
+ : '' ;
298
+ this . multiClusterService . primaryClusterRestVersion =
299
+ this . primaryClusterRestVersion ;
300
+ //init the cluster role
301
+ this . isMemberRole = data . fed_role === MapConstant . FED_ROLES . MEMBER ;
302
+ this . isMasterRole = data . fed_role === MapConstant . FED_ROLES . MASTER ;
303
+ this . isStandaloneRole = data . fed_role === '' ;
304
+ GlobalVariable . isMaster = this . isMasterRole ;
305
+ GlobalVariable . isMember = this . isMemberRole ;
306
+ GlobalVariable . isStandAlone = this . isStandaloneRole ;
307
+
308
+ const resource = {
309
+ multiClusterOp : {
310
+ global : 2 ,
311
+ } ,
312
+ manageAuth : {
313
+ global : 3 ,
314
+ } ,
315
+ multiClusterView : {
316
+ global : 1 ,
317
+ } ,
318
+ } ;
319
+
320
+ this . isAllowedToRedirectMultiCluster =
321
+ this . authUtilsService . getGlobalPermissionDisplayFlag (
322
+ 'multi_cluster'
323
+ ) ||
324
+ ( isAuthorized ( GlobalVariable . user . roles , resource . multiClusterOp ) &&
325
+ data . fed_role !== MapConstant . FED_ROLES . MASTER ) ;
326
+
327
+ //get the status of the chosen cluster
328
+ const sessionCluster = this . localStorage . get (
329
+ GlobalConstant . LOCAL_STORAGE_CLUSTER
330
+ ) ;
331
+ const clusterInSession = sessionCluster
332
+ ? JSON . parse ( sessionCluster )
333
+ : null ;
334
+ if ( clusterInSession ) {
335
+ this . isOnRemoteCluster = clusterInSession . isRemote ;
336
+ GlobalVariable . isRemote = clusterInSession . isRemote ;
337
+ } else {
338
+ GlobalVariable . isRemote = false ;
339
+ }
340
+
341
+ if ( GlobalVariable . isMaster ) {
342
+ this . isAllowedToOperateMultiCluster =
343
+ isAuthorized ( GlobalVariable . user . roles , resource . manageAuth ) ||
324
344
this . authUtilsService . getGlobalPermissionDisplayFlag (
325
345
'multi_cluster'
326
- ) ||
327
- ( isAuthorized ( GlobalVariable . user . roles , resource . multiClusterOp ) &&
328
- data . fed_role !== MapConstant . FED_ROLES . MASTER ) ;
329
-
330
- //get the status of the chosen cluster
331
- const sessionCluster = this . localStorage . get (
332
- GlobalConstant . LOCAL_STORAGE_CLUSTER
333
- ) ;
334
- const clusterInSession = sessionCluster
335
- ? JSON . parse ( sessionCluster )
336
- : null ;
337
- if ( clusterInSession ) {
338
- this . isOnRemoteCluster = clusterInSession . isRemote ;
339
- GlobalVariable . isRemote = clusterInSession . isRemote ;
346
+ ) ;
347
+ if ( clusterInSession !== null ) {
348
+ this . selectedCluster = clusterInSession ;
340
349
} else {
341
- GlobalVariable . isRemote = false ;
350
+ this . selectedCluster = this . clusters . find ( cluster => {
351
+ return cluster . clusterType === MapConstant . FED_ROLES . MASTER ;
352
+ } ) ;
342
353
}
354
+ }
343
355
344
- if ( GlobalVariable . isMaster ) {
345
- this . isAllowedToOperateMultiCluster =
346
- isAuthorized ( GlobalVariable . user . roles , resource . manageAuth ) ||
347
- this . authUtilsService . getGlobalPermissionDisplayFlag (
348
- 'multi_cluster'
349
- ) ;
350
- if ( clusterInSession !== null ) {
351
- this . selectedCluster = clusterInSession ;
356
+ if ( GlobalVariable . isMember ) {
357
+ this . isAllowedToOperateMultiCluster =
358
+ isAuthorized (
359
+ GlobalVariable . user . roles ,
360
+ resource . multiClusterView
361
+ ) ||
362
+ this . authUtilsService . getGlobalPermissionDisplayFlag (
363
+ 'multi_cluster'
364
+ ) ;
365
+ this . clusters . forEach ( cluster => {
366
+ if ( cluster . clusterType === MapConstant . FED_ROLES . MASTER ) {
367
+ this . primaryMasterName = cluster . name ;
352
368
} else {
353
- this . selectedCluster = this . clusters . find ( cluster => {
354
- return cluster . clusterType === MapConstant . FED_ROLES . MASTER ;
355
- } ) ;
369
+ this . managedClusterName = cluster . name ;
356
370
}
357
- }
358
-
359
- if ( GlobalVariable . isMember ) {
360
- this . isAllowedToOperateMultiCluster =
361
- isAuthorized (
362
- GlobalVariable . user . roles ,
363
- resource . multiClusterView
364
- ) ||
365
- this . authUtilsService . getGlobalPermissionDisplayFlag (
366
- 'multi_cluster'
367
- ) ;
368
- this . clusters . forEach ( cluster => {
369
- if ( cluster . clusterType === MapConstant . FED_ROLES . MASTER ) {
370
- this . primaryMasterName = cluster . name ;
371
- } else {
372
- this . managedClusterName = cluster . name ;
373
- }
374
- } ) ;
375
- }
371
+ } ) ;
372
+ }
376
373
377
- this . multiClusterService . dispatchGetClustersFinishEvent ( ) ;
378
- } ,
379
- error : error => {
380
- this . clustersError = true ;
381
- } ,
382
- } ) ;
374
+ this . multiClusterService . dispatchGetClustersFinishEvent ( ) ;
375
+ } ,
376
+ error : error => {
377
+ this . clustersError = true ;
378
+ } ,
379
+ } ) ;
383
380
}
384
381
385
382
redirectCluster ( cluster : Cluster ) {
0 commit comments