@@ -8,15 +8,38 @@ import {
8
8
HostListener ,
9
9
} from '@angular/core' ;
10
10
import { NavigationEnd , Router } from '@angular/router' ;
11
+ import { combineLatest } from 'rxjs' ;
11
12
import { filter , map , startWith } from 'rxjs/operators' ;
12
13
import { SubSink } from 'subsink' ;
13
14
14
15
import { VCLBreakpoints } from '@vcl/ng-vcl' ;
15
16
16
17
import { APP , ROUTER } from '@console-core/config' ;
18
+ import { AccountFacade , OrganizationContextFacade } from '@console-core/state' ;
19
+ import { IOrganization } from '@console-core/types' ;
17
20
18
21
import { RcDrawerService } from '../../../services' ;
19
22
23
+ const isHierarchical = (
24
+ root : string ,
25
+ decendant : string | undefined | null ,
26
+ organizations : IOrganization [ ]
27
+ ) : boolean => {
28
+ if ( ! root || ! decendant ) return false ;
29
+
30
+ const parentMap = new Map < string , string | null > (
31
+ organizations . map ( ( org ) => [ org . id , String ( org . parentId ) ] )
32
+ ) ;
33
+
34
+ while ( decendant && parentMap . has ( decendant ) ) {
35
+ if ( decendant === root ) return true ;
36
+ decendant = parentMap . get ( decendant ) ?? null ;
37
+ if ( decendant === null ) break ;
38
+ }
39
+
40
+ return false ;
41
+ } ;
42
+
20
43
@Component ( {
21
44
selector : 'rc-private-template' ,
22
45
templateUrl : './private-template.component.html' ,
@@ -59,11 +82,45 @@ export class RcPrivateTemplateComponent implements OnInit, OnDestroy {
59
82
ROUTER . pages . main . children . fulfillments . link ,
60
83
] ;
61
84
85
+ isSuperAdmin$ = this . accountFacade . user$ . pipe (
86
+ map ( ( user ) => {
87
+ return user ?. roleAssociations . some (
88
+ ( ra ) => ra . role === 'superadministrator-r-id'
89
+ ) ;
90
+ } )
91
+ ) ;
92
+
93
+ isAdmin$ = combineLatest ( [
94
+ this . accountFacade . user$ ,
95
+ this . organizationContextFacade . selectedId$ ,
96
+ this . organizationContextFacade . all$ ,
97
+ ] ) . pipe (
98
+ map ( ( [ user , organizationId , organizations ] ) => {
99
+ return user ?. roleAssociations . some (
100
+ ( ra ) =>
101
+ ra . role === 'administrator-r-id' &&
102
+ ra . attributes ?. some ( ( attr ) =>
103
+ attr . attributes ?. some (
104
+ ( inst ) =>
105
+ inst . value === organizationId ||
106
+ isHierarchical (
107
+ String ( inst . value ) ,
108
+ String ( organizationId ) ,
109
+ organizations
110
+ )
111
+ )
112
+ )
113
+ ) ;
114
+ } )
115
+ ) ;
116
+
62
117
constructor (
118
+ private readonly accountFacade : AccountFacade ,
63
119
private readonly breakpointObserver : BreakpointObserver ,
64
- private readonly router : Router ,
120
+ private readonly changeDetectorRef : ChangeDetectorRef ,
65
121
private readonly drawerService : RcDrawerService ,
66
- private readonly changeDetectorRef : ChangeDetectorRef
122
+ private readonly organizationContextFacade : OrganizationContextFacade ,
123
+ private readonly router : Router
67
124
) { }
68
125
69
126
ngOnInit ( ) : void {
0 commit comments