This is an automated email from the ASF dual-hosted git repository.

hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin.git


The following commit(s) were added to refs/heads/master by this push:
     new 34b3ff7  fix: clear role links in ClearPolicy
34b3ff7 is described below

commit 34b3ff743dabd996ca6089775b8acd8f9a677959
Author: Yang Luo <[email protected]>
AuthorDate: Tue Oct 20 21:43:30 2026 +0800

    fix: clear role links in ClearPolicy
---
 enforcer.go             | 12 ++++++++++++
 enforcer_distributed.go |  4 ++++
 2 files changed, 16 insertions(+)

diff --git a/enforcer.go b/enforcer.go
index b2417c8..f2752e9 100644
--- a/enforcer.go
+++ b/enforcer.go
@@ -372,6 +372,18 @@ func (e *Enforcer) ClearPolicy() {
                return
        }
        e.model.ClearPolicy()
+       if e.autoBuildRoleLinks {
+               e.clearRoleLinks()
+       }
+}
+
+func (e *Enforcer) clearRoleLinks() {
+       for _, rm := range e.rmMap {
+               _ = rm.Clear()
+       }
+       for _, crm := range e.condRmMap {
+               _ = crm.Clear()
+       }
 }
 
 // LoadPolicy reloads the policy from file/database.
diff --git a/enforcer_distributed.go b/enforcer_distributed.go
index 361520f..f494d4c 100644
--- a/enforcer_distributed.go
+++ b/enforcer_distributed.go
@@ -157,6 +157,10 @@ func (d *DistributedEnforcer) 
ClearPolicySelf(shouldPersist func() bool) error {
        }
 
        d.model.ClearPolicy()
+       if d.autoBuildRoleLinks {
+               d.clearRoleLinks()
+       }
+       d.invalidateMatcherMap()
 
        return nil
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to