@@ -108,6 +108,22 @@ export class RuleService extends ServiceBase<RuleListResponse, RuleList> impleme
108
108
return this . getRules ( ) ;
109
109
}
110
110
111
+ // async reloadRules(result: DeepPartial<RuleListResponse>): Promise<void> {
112
+ // const policySets = _.cloneDeep(_accessController.policySets);
113
+ // if (result?.items?.length > 0) {
114
+ // for (let item of result.items) {
115
+ // const rule: Rule = marshallResource(item?.payload, 'rule');
116
+ // for (let [, policySet] of policySets) {
117
+ // for (let [, policy] of (policySet).combinables) {
118
+ // if (!_.isNil(policy) && policy.combinables.has(rule.id)) {
119
+ // _accessController.updateRule(policySet.id, policy.id, rule);
120
+ // }
121
+ // }
122
+ // }
123
+ // }
124
+ // }
125
+ // }
126
+
111
127
async getRules ( ruleIDs ?: string [ ] ) : Promise < Map < string , Rule > > {
112
128
const filters = ruleIDs ? makeFilter ( ruleIDs ) : { } ;
113
129
const result = await super . read ( ReadRequest . fromPartial ( { filters } ) , { } ) ;
@@ -141,20 +157,8 @@ export class RuleService extends ServiceBase<RuleListResponse, RuleList> impleme
141
157
142
158
async superUpsert ( request : RuleList , ctx : any ) : Promise < DeepPartial < RuleListResponse > > {
143
159
const result = await super . upsert ( request , ctx ) ;
144
- const policySets = _ . cloneDeep ( _accessController . policySets ) ;
145
-
146
- if ( result ?. items ?. length > 0 ) {
147
- for ( let item of result . items ) {
148
- const rule : Rule = marshallResource ( item ?. payload , 'rule' ) ;
149
- for ( let [ , policySet ] of policySets ) {
150
- for ( let [ , policy ] of ( policySet ) . combinables ) {
151
- if ( ! _ . isNil ( policy ) && policy . combinables . has ( rule . id ) ) {
152
- _accessController . updateRule ( policySet . id , policy . id , rule ) ;
153
- }
154
- }
155
- }
156
- }
157
- }
160
+ // const policySets: Map<string, PolicySetWithCombinables> = await policySetService.load() || new Map();
161
+ // this.policySets = policySets;
158
162
return result ;
159
163
}
160
164
@@ -185,20 +189,7 @@ export class RuleService extends ServiceBase<RuleListResponse, RuleList> impleme
185
189
return { operation_status : acsResponse . operation_status } ;
186
190
}
187
191
const result = await super . create ( request , ctx ) ;
188
- const policySets = _ . cloneDeep ( _accessController . policySets ) ;
189
-
190
- if ( result ?. items ?. length > 0 ) {
191
- for ( let item of result . items ) {
192
- const rule : Rule = marshallResource ( item ?. payload , 'rule' ) ;
193
- for ( let [ , policySet ] of policySets ) {
194
- for ( let [ , policy ] of ( policySet ) . combinables ) {
195
- if ( ! _ . isNil ( policy ) && policy . combinables . has ( rule . id ) ) {
196
- _accessController . updateRule ( policySet . id , policy . id , rule ) ;
197
- }
198
- }
199
- }
200
- }
201
- }
192
+ await this . reloadRules ( result ) ;
202
193
return result ;
203
194
}
204
195
@@ -257,6 +248,7 @@ export class RuleService extends ServiceBase<RuleListResponse, RuleList> impleme
257
248
return { operation_status : acsResponse . operation_status } ;
258
249
}
259
250
const result = await super . update ( request , ctx ) ;
251
+ await this . reloadRules ( result ) ;
260
252
return result ;
261
253
}
262
254
@@ -285,7 +277,7 @@ export class RuleService extends ServiceBase<RuleListResponse, RuleList> impleme
285
277
if ( acsResponse . decision != Response_Decision . PERMIT ) {
286
278
return { operation_status : acsResponse . operation_status } ;
287
279
}
288
- const result = await super . upsert ( request , ctx ) ;
280
+ const result = await this . superUpsert ( request , ctx ) ;
289
281
return result ;
290
282
}
291
283
@@ -390,32 +382,35 @@ export class PolicyService extends ServiceBase<PolicyListResponse, PolicyList> i
390
382
return this . getPolicies ( ) ;
391
383
}
392
384
385
+ // async reloadPolicies(result: DeepPartial<PolicyListResponse>): Promise<void> {
386
+ // const policySets = _.cloneDeep(_accessController.policySets);
387
+ // if (result?.items?.length > 0) {
388
+ // for (let item of result.items) {
389
+ // for (let [, policySet] of policySets) {
390
+ // if (policySet.combinables.has(item.payload?.id)) {
391
+ // const policy: PolicyWithCombinables = marshallResource(item.payload, 'policy');
392
+
393
+ // if (_.has(item.payload, 'rules') && !_.isEmpty(item.payload.rules)) {
394
+ // policy.combinables = await ruleService.getRules(item.payload.rules);
395
+
396
+ // if (policy.combinables.size != item?.payload?.rules?.length) {
397
+ // for (let id of item.payload.rules) {
398
+ // if (!policy.combinables.has(id)) {
399
+ // policy.combinables.set(id, null);
400
+ // }
401
+ // }
402
+ // }
403
+ // }
404
+ // _accessController.updatePolicy(policySet.id, policy);
405
+ // }
406
+ // }
407
+ // }
408
+ // }
409
+ // }
410
+
393
411
async superUpsert ( request : PolicyList , ctx : any ) : Promise < DeepPartial < PolicyListResponse > > {
394
412
const result = await super . upsert ( request , ctx ) ;
395
- const policySets = _ . cloneDeep ( _accessController . policySets ) ;
396
-
397
- if ( result ?. items ?. length > 0 ) {
398
- for ( let item of result . items ) {
399
- for ( let [ , policySet ] of policySets ) {
400
- if ( policySet . combinables . has ( item . payload ?. id ) ) {
401
- const policy : PolicyWithCombinables = marshallResource ( item . payload , 'policy' ) ;
402
-
403
- if ( _ . has ( item . payload , 'rules' ) && ! _ . isEmpty ( item . payload . rules ) ) {
404
- policy . combinables = await ruleService . getRules ( item . payload . rules ) ;
405
-
406
- if ( policy . combinables . size != item ?. payload ?. rules ?. length ) {
407
- for ( let id of item . payload . rules ) {
408
- if ( ! policy . combinables . has ( id ) ) {
409
- policy . combinables . set ( id , null ) ;
410
- }
411
- }
412
- }
413
- }
414
- _accessController . updatePolicy ( policySet . id , policy ) ;
415
- }
416
- }
417
- }
418
- }
413
+ await _accessController . loadPolicies ( ) ;
419
414
return result ;
420
415
}
421
416
@@ -445,30 +440,7 @@ export class PolicyService extends ServiceBase<PolicyListResponse, PolicyList> i
445
440
return { operation_status : acsResponse . operation_status } ;
446
441
}
447
442
const result = await super . create ( request , ctx ) ;
448
- const policySets = _ . cloneDeep ( _accessController . policySets ) ;
449
-
450
- if ( result ?. items ?. length > 0 ) {
451
- for ( let item of result . items ) {
452
- for ( let [ , policySet ] of policySets ) {
453
- if ( policySet . combinables . has ( item . payload ?. id ) ) {
454
- const policy : PolicyWithCombinables = marshallResource ( item . payload , 'policy' ) ;
455
-
456
- if ( _ . has ( item . payload , 'rules' ) && ! _ . isEmpty ( item . payload . rules ) ) {
457
- policy . combinables = await ruleService . getRules ( item . payload . rules ) ;
458
-
459
- if ( policy . combinables . size != item ?. payload ?. rules ?. length ) {
460
- for ( let id of item . payload . rules ) {
461
- if ( ! policy . combinables . has ( id ) ) {
462
- policy . combinables . set ( id , null ) ;
463
- }
464
- }
465
- }
466
- }
467
- _accessController . updatePolicy ( policySet . id , policy ) ;
468
- }
469
- }
470
- }
471
- }
443
+ await this . reloadPolicies ( result ) ;
472
444
473
445
return result ;
474
446
}
@@ -541,6 +513,7 @@ export class PolicyService extends ServiceBase<PolicyListResponse, PolicyList> i
541
513
return { operation_status : acsResponse . operation_status } ;
542
514
}
543
515
const result = await super . update ( request , ctx ) ;
516
+ await this . reloadPolicies ( result ) ;
544
517
return result ;
545
518
}
546
519
@@ -569,7 +542,7 @@ export class PolicyService extends ServiceBase<PolicyListResponse, PolicyList> i
569
542
if ( acsResponse . decision != Response_Decision . PERMIT ) {
570
543
return { operation_status : acsResponse . operation_status } ;
571
544
}
572
- const result = await super . upsert ( request , ctx ) ;
545
+ const result = await this . superUpsert ( request , ctx ) ;
573
546
return result ;
574
547
}
575
548
@@ -985,7 +958,7 @@ export class PolicySetService extends ServiceBase<PolicySetListResponse, PolicyS
985
958
if ( acsResponse . decision != Response_Decision . PERMIT ) {
986
959
return { operation_status : acsResponse . operation_status } ;
987
960
}
988
- const result = await super . upsert ( request , ctx ) ;
961
+ const result = await this . superUpsert ( request , ctx ) ;
989
962
return result ;
990
963
}
991
964
}
0 commit comments