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

Method removeFilteredPolicyWithoutNotifyCtx

enforcer_context.go:551–581  ·  view source on GitHub ↗

removeFilteredPolicyWithoutNotifyCtx removes policy rules that match the filter from the current policy with context.

(ctx context.Context, sec string, ptype string, fieldIndex int, fieldValues []string)

Source from the content-addressed store, hash-verified

549
550// removeFilteredPolicyWithoutNotifyCtx removes policy rules that match the filter from the current policy with context.
551func (e *ContextEnforcer) removeFilteredPolicyWithoutNotifyCtx(ctx context.Context, sec string, ptype string, fieldIndex int, fieldValues []string) (bool, error) {
552 if len(fieldValues) == 0 {
553 return false, Err.ErrInvalidFieldValuesParameter
554 }
555
556 if e.dispatcher != nil && e.autoNotifyDispatcher {
557 return true, e.dispatcher.RemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues...)
558 }
559
560 if e.shouldPersist() {
561 if err := e.adapterCtx.RemoveFilteredPolicyCtx(ctx, sec, ptype, fieldIndex, fieldValues...); err != nil {
562 if err.Error() != notImplemented {
563 return false, err
564 }
565 }
566 }
567
568 ruleRemoved, effects, err := e.model.RemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues...)
569 if !ruleRemoved || err != nil {
570 return ruleRemoved, err
571 }
572
573 if sec == "g" {
574 err := e.BuildIncrementalRoleLinks(model.PolicyRemove, ptype, effects)
575 if err != nil {
576 return ruleRemoved, err
577 }
578 }
579
580 return ruleRemoved, nil
581}
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) {

Callers 2

Calls 5

shouldPersistMethod · 0.80
RemoveFilteredPolicyMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected