updatePolicyWithoutNotifyCtx updates a policy rule in the current policy with context.
(ctx context.Context, sec string, ptype string, oldRule, newRule []string)
| 582 | |
| 583 | // updatePolicyWithoutNotifyCtx updates a policy rule in the current policy with context. |
| 584 | func (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 | |
| 615 | func (e *ContextEnforcer) updatePoliciesWithoutNotifyCtx(ctx context.Context, sec string, ptype string, oldRules [][]string, newRules [][]string) (bool, error) { |
| 616 | if len(newRules) != len(oldRules) { |
no test coverage detected