MCPcopy Index your code
hub / github.com/apache/casbin / updatePoliciesWithoutNotify

Method updatePoliciesWithoutNotify

internal_api.go:201–240  ·  view source on GitHub ↗
(sec string, ptype string, oldRules [][]string, newRules [][]string)

Source from the content-addressed store, hash-verified

199}
200
201func (e *Enforcer) updatePoliciesWithoutNotify(sec string, ptype string, oldRules [][]string, newRules [][]string) (bool, error) {
202 if len(newRules) != len(oldRules) {
203 return false, fmt.Errorf("the length of oldRules should be equal to the length of newRules, but got the length of oldRules is %d, the length of newRules is %d", len(oldRules), len(newRules))
204 }
205
206 if e.dispatcher != nil && e.autoNotifyDispatcher {
207 return true, e.dispatcher.UpdatePolicies(sec, ptype, oldRules, newRules)
208 }
209
210 if e.shouldPersist() {
211 if err := e.adapter.(persist.UpdatableAdapter).UpdatePolicies(sec, ptype, oldRules, newRules); err != nil {
212 if err.Error() != notImplemented {
213 return false, err
214 }
215 }
216 }
217
218 ruleUpdated, err := e.model.UpdatePolicies(sec, ptype, oldRules, newRules)
219 if !ruleUpdated || err != nil {
220 return ruleUpdated, err
221 }
222
223 if sec == "g" {
224 err := e.BuildIncrementalRoleLinks(model.PolicyRemove, ptype, oldRules) // remove the old rules
225 if err != nil {
226 return ruleUpdated, err
227 }
228 err = e.BuildIncrementalRoleLinks(model.PolicyAdd, ptype, newRules) // add the new rules
229 if err != nil {
230 return ruleUpdated, err
231 }
232
233 // Validate constraints after updating grouping policies
234 if err := e.validateConstraintsForGroupingPolicy(); err != nil {
235 return false, err
236 }
237 }
238
239 return ruleUpdated, nil
240}
241
242// removePolicies removes rules from the current policy.
243func (e *Enforcer) removePoliciesWithoutNotify(sec string, ptype string, rules [][]string) (bool, error) {

Callers 2

updatePoliciesMethod · 0.95
SelfUpdatePoliciesMethod · 0.95

Calls 5

shouldPersistMethod · 0.95
UpdatePoliciesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected