Skip to content

Commit

Permalink
feat: controls whether to automatically notify Watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
nodece committed Apr 18, 2020
1 parent 864ebb6 commit 2ce07c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/coreEnforcer.ts
Expand Up @@ -38,6 +38,7 @@ export class CoreEnforcer {
private enabled: boolean;
protected autoSave: boolean;
protected autoBuildRoleLinks: boolean;
protected autoNotifyWatcher: boolean;

public initialize(): void {
this.rm = new DefaultRoleManager(10);
Expand All @@ -48,6 +49,7 @@ export class CoreEnforcer {
this.enabled = true;
this.autoSave = true;
this.autoBuildRoleLinks = true;
this.autoNotifyWatcher = true;
}

/**
Expand Down Expand Up @@ -227,6 +229,14 @@ export class CoreEnforcer {
this.autoSave = autoSave;
}

/**
* enableAutoNotifyWatcher controls whether to save a policy rule automatically notify the Watcher when it is added or removed.
* @param enable whether to enable the AutoNotifyWatcher feature.
*/
public enableAutoNotifyWatcher(enable: boolean): void {
this.autoNotifyWatcher = enable;
}

/**
* enableAutoBuildRoleLinks controls whether to save a policy rule
* automatically to the adapter when it is added or removed.
Expand Down
24 changes: 12 additions & 12 deletions src/internalEnforcer.ts
Expand Up @@ -35,11 +35,11 @@ export class InternalEnforcer extends CoreEnforcer {
throw e;
}
}
}

if (this.watcher) {
// error intentionally ignored
await this.watcher.update();
}
if (this.watcher && this.autoNotifyWatcher) {
// error intentionally ignored
await this.watcher.update();
}

return ruleAdded;
Expand All @@ -62,11 +62,11 @@ export class InternalEnforcer extends CoreEnforcer {
throw e;
}
}
}

if (this.watcher) {
// error intentionally ignored
await this.watcher.update();
}
if (this.watcher && this.autoNotifyWatcher) {
// error intentionally ignored
await this.watcher.update();
}

return ruleRemoved;
Expand All @@ -89,11 +89,11 @@ export class InternalEnforcer extends CoreEnforcer {
throw e;
}
}
}

if (this.watcher) {
// error intentionally ignored
await this.watcher.update();
}
if (this.watcher && this.autoNotifyWatcher) {
// error intentionally ignored
await this.watcher.update();
}

return ruleRemoved;
Expand Down

0 comments on commit 2ce07c2

Please sign in to comment.