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

Method UpdatePolicy

model/policy.go:280–296  ·  view source on GitHub ↗

UpdatePolicy updates a policy rule from the model.

(sec string, ptype string, oldRule []string, newRule []string)

Source from the content-addressed store, hash-verified

278
279// UpdatePolicy updates a policy rule from the model.
280func (model Model) UpdatePolicy(sec string, ptype string, oldRule []string, newRule []string) (bool, error) {
281 _, err := model.GetAssertion(sec, ptype)
282 if err != nil {
283 return false, err
284 }
285 oldPolicy := strings.Join(oldRule, DefaultSep)
286 index, ok := model[sec][ptype].PolicyMap[oldPolicy]
287 if !ok {
288 return false, nil
289 }
290
291 model[sec][ptype].Policy[index] = newRule
292 delete(model[sec][ptype].PolicyMap, oldPolicy)
293 model[sec][ptype].PolicyMap[strings.Join(newRule, DefaultSep)] = index
294
295 return true, nil
296}
297
298// UpdatePolicies updates a policy rule from the model.
299func (model Model) UpdatePolicies(sec string, ptype string, oldRules, newRules [][]string) (bool, error) {

Callers

nothing calls this directly

Calls 1

GetAssertionMethod · 0.95

Tested by

no test coverage detected