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

Method updatePolicyWithoutNotifyCtx

enforcer_context.go:584–613  ·  view source on GitHub ↗

updatePolicyWithoutNotifyCtx updates a policy rule in the current policy with context.

(ctx context.Context, sec string, ptype string, oldRule, newRule []string)

Source from the content-addressed store, hash-verified

582
583// updatePolicyWithoutNotifyCtx updates a policy rule in the current policy with context.
584func (e *ContextEnforcer) updatePolicyWithoutNotifyCtx(ctx context.Context, sec string, ptype string, oldRule, newRule []string) (bool, error) {
585 if e.dispatcher != nil && e.autoNotifyDispatcher {
586 return true, e.dispatcher.UpdatePolicy(sec, ptype, oldRule, newRule)
587 }
588
589 if e.shouldPersist() {
590 if err := e.adapterCtx.(persist.ContextUpdatableAdapter).UpdatePolicyCtx(ctx, sec, ptype, oldRule, newRule); err != nil {
591 if err.Error() != notImplemented {
592 return false, err
593 }
594 }
595 }
596 ruleUpdated, err := e.model.UpdatePolicy(sec, ptype, oldRule, newRule)
597 if !ruleUpdated || err != nil {
598 return ruleUpdated, err
599 }
600
601 if sec == "g" {
602 err := e.BuildIncrementalRoleLinks(model.PolicyRemove, ptype, [][]string{oldRule}) // remove the old rule
603 if err != nil {
604 return ruleUpdated, err
605 }
606 err = e.BuildIncrementalRoleLinks(model.PolicyAdd, ptype, [][]string{newRule}) // add the new rule
607 if err != nil {
608 return ruleUpdated, err
609 }
610 }
611
612 return ruleUpdated, nil
613}
614
615func (e *ContextEnforcer) updatePoliciesWithoutNotifyCtx(ctx context.Context, sec string, ptype string, oldRules [][]string, newRules [][]string) (bool, error) {
616 if len(newRules) != len(oldRules) {

Callers 2

SelfUpdatePolicyCtxMethod · 0.95
updatePolicyCtxMethod · 0.95

Calls 5

shouldPersistMethod · 0.80
UpdatePolicyMethod · 0.65
UpdatePolicyCtxMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected