@@ -108,22 +108,6 @@ export class RuleService extends ServiceBase<RuleListResponse, RuleList> impleme
108108    return  this . getRules ( ) ; 
109109  } 
110110
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- 
127111  async  getRules ( ruleIDs ?: string [ ] ) : Promise < Map < string ,  Rule > >  { 
128112    const  filters  =  ruleIDs  ? makeFilter ( ruleIDs )  : { } ; 
129113    const  result  =  await  super . read ( ReadRequest . fromPartial ( {  filters } ) ,  { } ) ; 
@@ -157,8 +141,20 @@ export class RuleService extends ServiceBase<RuleListResponse, RuleList> impleme
157141
158142  async  superUpsert ( request : RuleList ,  ctx : any ) : Promise < DeepPartial < RuleListResponse > >  { 
159143    const  result  =  await  super . upsert ( request ,  ctx ) ; 
160-     // const policySets: Map<string, PolicySetWithCombinables> = await policySetService.load() || new Map(); 
161-     // this.policySets = policySets; 
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+     } 
162158    return  result ; 
163159  } 
164160
@@ -189,7 +185,20 @@ export class RuleService extends ServiceBase<RuleListResponse, RuleList> impleme
189185      return  {  operation_status : acsResponse . operation_status  } ; 
190186    } 
191187    const  result  =  await  super . create ( request ,  ctx ) ; 
192-     await  this . reloadRules ( result ) ; 
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+     } 
193202    return  result ; 
194203  } 
195204
@@ -248,7 +257,6 @@ export class RuleService extends ServiceBase<RuleListResponse, RuleList> impleme
248257      return  {  operation_status : acsResponse . operation_status  } ; 
249258    } 
250259    const  result  =  await  super . update ( request ,  ctx ) ; 
251-     await  this . reloadRules ( result ) ; 
252260    return  result ; 
253261  } 
254262
@@ -277,7 +285,7 @@ export class RuleService extends ServiceBase<RuleListResponse, RuleList> impleme
277285    if  ( acsResponse . decision  !=  Response_Decision . PERMIT )  { 
278286      return  {  operation_status : acsResponse . operation_status  } ; 
279287    } 
280-     const  result  =  await  this . superUpsert ( request ,  ctx ) ; 
288+     const  result  =  await  super . upsert ( request ,  ctx ) ; 
281289    return  result ; 
282290  } 
283291
@@ -382,35 +390,32 @@ export class PolicyService extends ServiceBase<PolicyListResponse, PolicyList> i
382390    return  this . getPolicies ( ) ; 
383391  } 
384392
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- 
411393  async  superUpsert ( request : PolicyList ,  ctx : any ) : Promise < DeepPartial < PolicyListResponse > >  { 
412394    const  result  =  await  super . upsert ( request ,  ctx ) ; 
413-     await  _accessController . loadPolicies ( ) ; 
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+     } 
414419    return  result ; 
415420  } 
416421
@@ -440,7 +445,30 @@ export class PolicyService extends ServiceBase<PolicyListResponse, PolicyList> i
440445      return  {  operation_status : acsResponse . operation_status  } ; 
441446    } 
442447    const  result  =  await  super . create ( request ,  ctx ) ; 
443-     await  this . reloadPolicies ( result ) ; 
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+     } 
444472
445473    return  result ; 
446474  } 
@@ -513,7 +541,6 @@ export class PolicyService extends ServiceBase<PolicyListResponse, PolicyList> i
513541      return  {  operation_status : acsResponse . operation_status  } ; 
514542    } 
515543    const  result  =  await  super . update ( request ,  ctx ) ; 
516-     await  this . reloadPolicies ( result ) ; 
517544    return  result ; 
518545  } 
519546
@@ -542,7 +569,7 @@ export class PolicyService extends ServiceBase<PolicyListResponse, PolicyList> i
542569    if  ( acsResponse . decision  !=  Response_Decision . PERMIT )  { 
543570      return  {  operation_status : acsResponse . operation_status  } ; 
544571    } 
545-     const  result  =  await  this . superUpsert ( request ,  ctx ) ; 
572+     const  result  =  await  super . upsert ( request ,  ctx ) ; 
546573    return  result ; 
547574  } 
548575
@@ -958,7 +985,7 @@ export class PolicySetService extends ServiceBase<PolicySetListResponse, PolicyS
958985    if  ( acsResponse . decision  !=  Response_Decision . PERMIT )  { 
959986      return  {  operation_status : acsResponse . operation_status  } ; 
960987    } 
961-     const  result  =  await  this . superUpsert ( request ,  ctx ) ; 
988+     const  result  =  await  super . upsert ( request ,  ctx ) ; 
962989    return  result ; 
963990  } 
964991} 
0 commit comments