Skip to content

Commit 2ce07c2

Browse files
committed
feat: controls whether to automatically notify Watcher
1 parent 864ebb6 commit 2ce07c2

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/coreEnforcer.ts

+10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class CoreEnforcer {
3838
private enabled: boolean;
3939
protected autoSave: boolean;
4040
protected autoBuildRoleLinks: boolean;
41+
protected autoNotifyWatcher: boolean;
4142

4243
public initialize(): void {
4344
this.rm = new DefaultRoleManager(10);
@@ -48,6 +49,7 @@ export class CoreEnforcer {
4849
this.enabled = true;
4950
this.autoSave = true;
5051
this.autoBuildRoleLinks = true;
52+
this.autoNotifyWatcher = true;
5153
}
5254

5355
/**
@@ -227,6 +229,14 @@ export class CoreEnforcer {
227229
this.autoSave = autoSave;
228230
}
229231

232+
/**
233+
* enableAutoNotifyWatcher controls whether to save a policy rule automatically notify the Watcher when it is added or removed.
234+
* @param enable whether to enable the AutoNotifyWatcher feature.
235+
*/
236+
public enableAutoNotifyWatcher(enable: boolean): void {
237+
this.autoNotifyWatcher = enable;
238+
}
239+
230240
/**
231241
* enableAutoBuildRoleLinks controls whether to save a policy rule
232242
* automatically to the adapter when it is added or removed.

src/internalEnforcer.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export class InternalEnforcer extends CoreEnforcer {
3535
throw e;
3636
}
3737
}
38+
}
3839

39-
if (this.watcher) {
40-
// error intentionally ignored
41-
await this.watcher.update();
42-
}
40+
if (this.watcher && this.autoNotifyWatcher) {
41+
// error intentionally ignored
42+
await this.watcher.update();
4343
}
4444

4545
return ruleAdded;
@@ -62,11 +62,11 @@ export class InternalEnforcer extends CoreEnforcer {
6262
throw e;
6363
}
6464
}
65+
}
6566

66-
if (this.watcher) {
67-
// error intentionally ignored
68-
await this.watcher.update();
69-
}
67+
if (this.watcher && this.autoNotifyWatcher) {
68+
// error intentionally ignored
69+
await this.watcher.update();
7070
}
7171

7272
return ruleRemoved;
@@ -89,11 +89,11 @@ export class InternalEnforcer extends CoreEnforcer {
8989
throw e;
9090
}
9191
}
92+
}
9293

93-
if (this.watcher) {
94-
// error intentionally ignored
95-
await this.watcher.update();
96-
}
94+
if (this.watcher && this.autoNotifyWatcher) {
95+
// error intentionally ignored
96+
await this.watcher.update();
9797
}
9898

9999
return ruleRemoved;

0 commit comments

Comments
 (0)