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

Method updatePolicyWithoutNotify

internal_api.go:165–199  ·  view source on GitHub ↗
(sec string, ptype string, oldRule []string, newRule []string)

Source from the content-addressed store, hash-verified

163}
164
165func (e *Enforcer) updatePolicyWithoutNotify(sec string, ptype string, oldRule []string, newRule []string) (bool, error) {
166 if e.dispatcher != nil && e.autoNotifyDispatcher {
167 return true, e.dispatcher.UpdatePolicy(sec, ptype, oldRule, newRule)
168 }
169
170 if e.shouldPersist() {
171 if err := e.adapter.(persist.UpdatableAdapter).UpdatePolicy(sec, ptype, oldRule, newRule); err != nil {
172 if err.Error() != notImplemented {
173 return false, err
174 }
175 }
176 }
177 ruleUpdated, err := e.model.UpdatePolicy(sec, ptype, oldRule, newRule)
178 if !ruleUpdated || err != nil {
179 return ruleUpdated, err
180 }
181
182 if sec == "g" {
183 err := e.BuildIncrementalRoleLinks(model.PolicyRemove, ptype, [][]string{oldRule}) // remove the old rule
184 if err != nil {
185 return ruleUpdated, err
186 }
187 err = e.BuildIncrementalRoleLinks(model.PolicyAdd, ptype, [][]string{newRule}) // add the new rule
188 if err != nil {
189 return ruleUpdated, err
190 }
191
192 // Validate constraints after updating grouping policy
193 if err := e.validateConstraintsForGroupingPolicy(); err != nil {
194 return false, err
195 }
196 }
197
198 return ruleUpdated, nil
199}
200
201func (e *Enforcer) updatePoliciesWithoutNotify(sec string, ptype string, oldRules [][]string, newRules [][]string) (bool, error) {
202 if len(newRules) != len(oldRules) {

Callers 2

updatePolicyMethod · 0.95
SelfUpdatePolicyMethod · 0.95

Calls 5

shouldPersistMethod · 0.95
UpdatePolicyMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected