@@ -24,7 +24,7 @@ export class InternalEnforcer extends CoreEnforcer {
2424 /**
2525 * addPolicyInternal adds a rule to the current policy.
2626 */
27- public async addPolicyInternal ( sec : string , ptype : string , rule : string [ ] ) : Promise < boolean > {
27+ protected async addPolicyInternal ( sec : string , ptype : string , rule : string [ ] , useWatcher : boolean ) : Promise < boolean > {
2828 if ( this . model . hasPolicy ( sec , ptype , rule ) ) {
2929 return false ;
3030 }
@@ -39,10 +39,15 @@ export class InternalEnforcer extends CoreEnforcer {
3939 }
4040 }
4141
42- if ( this . autoNotifyWatcher ) {
43- // error intentionally ignored
44- if ( this . watcherEx ) await this . watcherEx . updateForAddPolicy ( sec , ptype , ...rule ) ;
45- else if ( this . watcher ) await this . watcher . update ( ) ;
42+ if ( useWatcher ) {
43+ if ( this . autoNotifyWatcher ) {
44+ // error intentionally ignored
45+ if ( this . watcherEx ) {
46+ this . watcherEx . updateForAddPolicy ( sec , ptype , ...rule ) ;
47+ } else if ( this . watcher ) {
48+ this . watcher . update ( ) ;
49+ }
50+ }
4651 }
4752
4853 const ok = this . model . addPolicy ( sec , ptype , rule ) ;
@@ -55,7 +60,7 @@ export class InternalEnforcer extends CoreEnforcer {
5560
5661 // addPolicies adds rules to the current policy.
5762 // removePolicies removes rules from the current policy.
58- public async addPoliciesInternal ( sec : string , ptype : string , rules : string [ ] [ ] ) : Promise < boolean > {
63+ protected async addPoliciesInternal ( sec : string , ptype : string , rules : string [ ] [ ] , useWatcher : boolean ) : Promise < boolean > {
5964 for ( const rule of rules ) {
6065 if ( this . model . hasPolicy ( sec , ptype , rule ) ) {
6166 return false ;
@@ -76,10 +81,15 @@ export class InternalEnforcer extends CoreEnforcer {
7681 }
7782 }
7883
79- if ( this . autoNotifyWatcher ) {
80- // error intentionally ignored
81- if ( this . watcherEx ) await this . watcherEx . updateForAddPolicies ( sec , ptype , ...rules ) ;
82- else if ( this . watcher ) this . watcher . update ( ) ;
84+ if ( useWatcher ) {
85+ if ( this . autoNotifyWatcher ) {
86+ // error intentionally ignored
87+ if ( this . watcherEx ) {
88+ this . watcherEx . updateForAddPolicies ( sec , ptype , ...rules ) ;
89+ } else if ( this . watcher ) {
90+ this . watcher . update ( ) ;
91+ }
92+ }
8393 }
8494
8595 const [ ok , effects ] = await this . model . addPolicies ( sec , ptype , rules ) ;
@@ -92,7 +102,13 @@ export class InternalEnforcer extends CoreEnforcer {
92102 /**
93103 * updatePolicyInternal updates a rule from the current policy.
94104 */
95- public async updatePolicyInternal ( sec : string , ptype : string , oldRule : string [ ] , newRule : string [ ] ) : Promise < boolean > {
105+ protected async updatePolicyInternal (
106+ sec : string ,
107+ ptype : string ,
108+ oldRule : string [ ] ,
109+ newRule : string [ ] ,
110+ useWatcher : boolean
111+ ) : Promise < boolean > {
96112 if ( ! this . model . hasPolicy ( sec , ptype , oldRule ) ) {
97113 return false ;
98114 }
@@ -111,10 +127,12 @@ export class InternalEnforcer extends CoreEnforcer {
111127 }
112128 }
113129
114- if ( this . watcher && this . autoNotifyWatcher ) {
115- // In fact I think it should wait for the respond, but they implement add_policy() like this
116- // error intentionally ignored
117- this . watcher . update ( ) ;
130+ if ( useWatcher ) {
131+ if ( this . watcher && this . autoNotifyWatcher ) {
132+ // In fact I think it should wait for the respond, but they implement add_policy() like this
133+ // error intentionally ignored
134+ this . watcher . update ( ) ;
135+ }
118136 }
119137
120138 const ok = this . model . updatePolicy ( sec , ptype , oldRule , newRule ) ;
@@ -129,7 +147,7 @@ export class InternalEnforcer extends CoreEnforcer {
129147 /**
130148 * removePolicyInternal removes a rule from the current policy.
131149 */
132- public async removePolicyInternal ( sec : string , ptype : string , rule : string [ ] ) : Promise < boolean > {
150+ protected async removePolicyInternal ( sec : string , ptype : string , rule : string [ ] , useWatcher : boolean ) : Promise < boolean > {
133151 if ( ! this . model . hasPolicy ( sec , ptype , rule ) ) {
134152 return false ;
135153 }
@@ -144,10 +162,15 @@ export class InternalEnforcer extends CoreEnforcer {
144162 }
145163 }
146164
147- if ( this . watcher && this . autoNotifyWatcher ) {
148- // error intentionally ignored
149- if ( this . watcherEx ) await this . watcherEx . updateForRemovePolicy ( sec , ptype , ...rule ) ;
150- else if ( this . watcher ) await this . watcher . update ( ) ;
165+ if ( useWatcher ) {
166+ if ( this . watcher && this . autoNotifyWatcher ) {
167+ // error intentionally ignored
168+ if ( this . watcherEx ) {
169+ this . watcherEx . updateForRemovePolicy ( sec , ptype , ...rule ) ;
170+ } else if ( this . watcher ) {
171+ this . watcher . update ( ) ;
172+ }
173+ }
151174 }
152175
153176 const ok = await this . model . removePolicy ( sec , ptype , rule ) ;
@@ -158,7 +181,7 @@ export class InternalEnforcer extends CoreEnforcer {
158181 }
159182
160183 // removePolicies removes rules from the current policy.
161- public async removePoliciesInternal ( sec : string , ptype : string , rules : string [ ] [ ] ) : Promise < boolean > {
184+ protected async removePoliciesInternal ( sec : string , ptype : string , rules : string [ ] [ ] , useWatcher : boolean ) : Promise < boolean > {
162185 for ( const rule of rules ) {
163186 if ( ! this . model . hasPolicy ( sec , ptype , rule ) ) {
164187 return false ;
@@ -179,10 +202,15 @@ export class InternalEnforcer extends CoreEnforcer {
179202 }
180203 }
181204
182- if ( this . watcher && this . autoNotifyWatcher ) {
183- // error intentionally ignored
184- if ( this . watcherEx ) await this . watcherEx . updateForRemovePolicies ( sec , ptype , ...rules ) ;
185- else if ( this . watcher ) await this . watcher . update ( ) ;
205+ if ( useWatcher ) {
206+ if ( this . watcher && this . autoNotifyWatcher ) {
207+ // error intentionally ignored
208+ if ( this . watcherEx ) {
209+ this . watcherEx . updateForRemovePolicies ( sec , ptype , ...rules ) ;
210+ } else if ( this . watcher ) {
211+ this . watcher . update ( ) ;
212+ }
213+ }
186214 }
187215
188216 const [ ok , effects ] = this . model . removePolicies ( sec , ptype , rules ) ;
@@ -195,7 +223,13 @@ export class InternalEnforcer extends CoreEnforcer {
195223 /**
196224 * removeFilteredPolicyInternal removes rules based on field filters from the current policy.
197225 */
198- public async removeFilteredPolicyInternal ( sec : string , ptype : string , fieldIndex : number , fieldValues : string [ ] ) : Promise < boolean > {
226+ protected async removeFilteredPolicyInternal (
227+ sec : string ,
228+ ptype : string ,
229+ fieldIndex : number ,
230+ fieldValues : string [ ] ,
231+ useWatcher : boolean
232+ ) : Promise < boolean > {
199233 if ( this . adapter && this . autoSave ) {
200234 try {
201235 await this . adapter . removeFilteredPolicy ( sec , ptype , fieldIndex , ...fieldValues ) ;
@@ -206,10 +240,15 @@ export class InternalEnforcer extends CoreEnforcer {
206240 }
207241 }
208242
209- if ( this . watcher && this . autoNotifyWatcher ) {
210- // error intentionally ignored
211- if ( this . watcherEx ) await this . watcherEx . updateForRemoveFilteredPolicy ( sec , ptype , fieldIndex , ...fieldValues ) ;
212- else if ( this . watcher ) await this . watcher . update ( ) ;
243+ if ( useWatcher ) {
244+ if ( this . watcher && this . autoNotifyWatcher ) {
245+ // error intentionally ignored
246+ if ( this . watcherEx ) {
247+ this . watcherEx . updateForRemoveFilteredPolicy ( sec , ptype , fieldIndex , ...fieldValues ) ;
248+ } else if ( this . watcher ) {
249+ this . watcher . update ( ) ;
250+ }
251+ }
213252 }
214253
215254 const [ ok , effects ] = this . model . removeFilteredPolicy ( sec , ptype , fieldIndex , ...fieldValues ) ;
0 commit comments