MCPcopy
hub / github.com/apache/casbin / UpdatePolicySelf

Method UpdatePolicySelf

enforcer_distributed.go:140–167  ·  view source on GitHub ↗

UpdatePolicySelf provides a method for dispatcher to update an authorization rule from the current policy.

(shouldPersist func() bool, sec string, ptype string, oldRule, newRule []string)

Source from the content-addressed store, hash-verified

138
139// UpdatePolicySelf provides a method for dispatcher to update an authorization rule from the current policy.
140func (d *DistributedEnforcer) UpdatePolicySelf(shouldPersist func() bool, sec string, ptype string, oldRule, newRule []string) (affected bool, err error) {
141 d.m.Lock()
142 defer d.m.Unlock()
143 if shouldPersist != nil && shouldPersist() {
144 err = d.adapter.(persist.UpdatableAdapter).UpdatePolicy(sec, ptype, oldRule, newRule)
145 if err != nil {
146 return false, err
147 }
148 }
149
150 ruleUpdated, err := d.model.UpdatePolicy(sec, ptype, oldRule, newRule)
151 if !ruleUpdated || err != nil {
152 return ruleUpdated, err
153 }
154
155 if sec == "g" {
156 err := d.BuildIncrementalRoleLinks(model.PolicyRemove, ptype, [][]string{oldRule}) // remove the old rule
157 if err != nil {
158 return ruleUpdated, err
159 }
160 err = d.BuildIncrementalRoleLinks(model.PolicyAdd, ptype, [][]string{newRule}) // add the new rule
161 if err != nil {
162 return ruleUpdated, err
163 }
164 }
165
166 return ruleUpdated, nil
167}
168
169// UpdatePoliciesSelf provides a method for dispatcher to update a set of authorization rules from the current policy.
170func (d *DistributedEnforcer) UpdatePoliciesSelf(shouldPersist func() bool, sec string, ptype string, oldRules, newRules [][]string) (affected bool, err error) {

Callers

nothing calls this directly

Calls 2

UpdatePolicyMethod · 0.65

Tested by

no test coverage detected