@@ -24,12 +24,13 @@ export class InternalEnforcer extends CoreEnforcer {
2424 /**
2525 * addPolicyInternal adds a rule to the current policy.
2626 */
27- protected async addPolicyInternal ( sec : string , ptype : string , rule : string [ ] , useWatcher : boolean ) : Promise < boolean > {
27+ protected async addPolicyInternal ( sec : string , ptype : string , rule : string [ ] , useWatcher : boolean , useAdapter = true ) : Promise < boolean > {
2828 if ( this . model . hasPolicy ( sec , ptype , rule ) ) {
2929 return false ;
3030 }
3131
32- if ( this . adapter && this . autoSave ) {
32+ // if (this.adapter && this.autoSave) {
33+ if ( useAdapter && this . adapter && this . autoSave ) {
3334 try {
3435 await this . adapter . addPolicy ( sec , ptype , rule ) ;
3536 } catch ( e ) {
@@ -60,14 +61,21 @@ export class InternalEnforcer extends CoreEnforcer {
6061
6162 // addPolicies adds rules to the current policy.
6263 // removePolicies removes rules from the current policy.
63- protected async addPoliciesInternal ( sec : string , ptype : string , rules : string [ ] [ ] , useWatcher : boolean ) : Promise < boolean > {
64+ protected async addPoliciesInternal (
65+ sec : string ,
66+ ptype : string ,
67+ rules : string [ ] [ ] ,
68+ useWatcher : boolean ,
69+ useAdapter = true
70+ ) : Promise < boolean > {
6471 for ( const rule of rules ) {
6572 if ( this . model . hasPolicy ( sec , ptype , rule ) ) {
6673 return false ;
6774 }
6875 }
6976
70- if ( this . autoSave ) {
77+ // if (this.autoSave) {
78+ if ( useAdapter && this . autoSave ) {
7179 if ( 'addPolicies' in this . adapter ) {
7280 try {
7381 await this . adapter . addPolicies ( sec , ptype , rules ) ;
@@ -104,7 +112,13 @@ export class InternalEnforcer extends CoreEnforcer {
104112 * Unlike addPoliciesInternal, this method will filter out rules that already exist
105113 * and continue to add the remaining rules instead of returning false immediately.
106114 */
107- protected async addPoliciesInternalEx ( sec : string , ptype : string , rules : string [ ] [ ] , useWatcher : boolean ) : Promise < boolean > {
115+ protected async addPoliciesInternalEx (
116+ sec : string ,
117+ ptype : string ,
118+ rules : string [ ] [ ] ,
119+ useWatcher : boolean ,
120+ useAdapter = true
121+ ) : Promise < boolean > {
108122 // Filter out existing rules
109123 const newRules = rules . filter ( ( rule ) => ! this . model . hasPolicy ( sec , ptype , rule ) ) ;
110124
@@ -113,7 +127,8 @@ export class InternalEnforcer extends CoreEnforcer {
113127 return false ;
114128 }
115129
116- if ( this . autoSave ) {
130+ // if (this.autoSave) {
131+ if ( useAdapter && this . autoSave ) {
117132 if ( 'addPolicies' in this . adapter ) {
118133 try {
119134 await this . adapter . addPolicies ( sec , ptype , newRules ) ;
@@ -153,13 +168,14 @@ export class InternalEnforcer extends CoreEnforcer {
153168 ptype : string ,
154169 oldRule : string [ ] ,
155170 newRule : string [ ] ,
156- useWatcher : boolean
171+ useWatcher : boolean ,
172+ useAdapter = true
157173 ) : Promise < boolean > {
158174 if ( ! this . model . hasPolicy ( sec , ptype , oldRule ) ) {
159175 return false ;
160176 }
161-
162- if ( this . autoSave ) {
177+ // if (this.autoSave) {
178+ if ( useAdapter && this . autoSave ) {
163179 if ( 'updatePolicy' in this . adapter ) {
164180 try {
165181 await this . adapter . updatePolicy ( sec , ptype , oldRule , newRule ) ;
@@ -195,12 +211,19 @@ export class InternalEnforcer extends CoreEnforcer {
195211 /**
196212 * removePolicyInternal removes a rule from the current policy.
197213 */
198- protected async removePolicyInternal ( sec : string , ptype : string , rule : string [ ] , useWatcher : boolean ) : Promise < boolean > {
214+ protected async removePolicyInternal (
215+ sec : string ,
216+ ptype : string ,
217+ rule : string [ ] ,
218+ useWatcher : boolean ,
219+ useAdapter = true
220+ ) : Promise < boolean > {
199221 if ( ! this . model . hasPolicy ( sec , ptype , rule ) ) {
200222 return false ;
201223 }
202224
203- if ( this . adapter && this . autoSave ) {
225+ // if (this.adapter && this.autoSave) {
226+ if ( useAdapter && this . adapter && this . autoSave ) {
204227 try {
205228 await this . adapter . removePolicy ( sec , ptype , rule ) ;
206229 } catch ( e ) {
@@ -229,14 +252,21 @@ export class InternalEnforcer extends CoreEnforcer {
229252 }
230253
231254 // removePolicies removes rules from the current policy.
232- protected async removePoliciesInternal ( sec : string , ptype : string , rules : string [ ] [ ] , useWatcher : boolean ) : Promise < boolean > {
255+ protected async removePoliciesInternal (
256+ sec : string ,
257+ ptype : string ,
258+ rules : string [ ] [ ] ,
259+ useWatcher : boolean ,
260+ useAdapter = true
261+ ) : Promise < boolean > {
233262 for ( const rule of rules ) {
234263 if ( ! this . model . hasPolicy ( sec , ptype , rule ) ) {
235264 return false ;
236265 }
237266 }
238267
239- if ( this . autoSave ) {
268+ // if (this.autoSave) {
269+ if ( useAdapter && this . autoSave ) {
240270 if ( 'removePolicies' in this . adapter ) {
241271 try {
242272 await this . adapter . removePolicies ( sec , ptype , rules ) ;
@@ -276,9 +306,11 @@ export class InternalEnforcer extends CoreEnforcer {
276306 ptype : string ,
277307 fieldIndex : number ,
278308 fieldValues : string [ ] ,
279- useWatcher : boolean
309+ useWatcher : boolean ,
310+ useAdapter = true
280311 ) : Promise < boolean > {
281- if ( this . adapter && this . autoSave ) {
312+ // if (this.adapter && this.autoSave) {
313+ if ( useAdapter && this . adapter && this . autoSave ) {
282314 try {
283315 await this . adapter . removeFilteredPolicy ( sec , ptype , fieldIndex , ...fieldValues ) ;
284316 } catch ( e ) {
0 commit comments