-
-
Notifications
You must be signed in to change notification settings - Fork 225
Description
Goal: Modify the Enforcer to allow updating the policy in memory without triggering the Adapter (database write) or the Watcher (notification), even when autoSave is enabled.
Detailed Implementation Plan:
Modify InternalEnforcer methods:
Update all internal modification methods (e.g., addPolicyInternal, removePolicyInternal, updatePolicyInternal, addPoliciesInternal, etc.).
Add a new optional parameter useAdapter: boolean to these methods.
Set the default value of useAdapter to true to ensure backward compatibility.
In the method body, wrap the adapter call logic (e.g., this.adapter.addPolicy(...)) with a check: if (useAdapter && this.adapter && this.autoSave).
Update ManagementEnforcer (self* methods):
Locate all self* methods (e.g., selfAddPolicy, selfRemovePolicy, selfUpdatePolicy, etc.).
Update their implementation to call the corresponding *Internal method passing false for the new useAdapter parameter (along with false for the existing useWatcher parameter).
This ensures that calling self* methods will strictly update the memory model only, bypassing both the database adapter and the watcher notification.
Documentation:
Add JSDoc comments to these self* methods explaining that they are intended for in-memory updates in distributed setups (e.g., inside a Watcher callback).
Expected Outcome: Users can call enforcer.selfAddPolicy(...) in a Watcher callback. This will update the local cache but prevent the dead-loop caused by writing back to the DB and triggering the Watcher again.