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

Method addPolicyWithoutNotifyCtx

enforcer_context.go:415–446  ·  view source on GitHub ↗

Internal API methods with context support addPolicyWithoutNotifyCtx adds a rule to the current policy with context.

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

Source from the content-addressed store, hash-verified

413
414// addPolicyWithoutNotifyCtx adds a rule to the current policy with context.
415func (e *ContextEnforcer) addPolicyWithoutNotifyCtx(ctx context.Context, sec string, ptype string, rule []string) (bool, error) {
416 if e.dispatcher != nil && e.autoNotifyDispatcher {
417 return true, e.dispatcher.AddPolicies(sec, ptype, [][]string{rule})
418 }
419
420 hasPolicy, err := e.model.HasPolicy(sec, ptype, rule)
421 if hasPolicy || err != nil {
422 return false, err
423 }
424
425 if e.shouldPersist() {
426 if err = e.adapterCtx.AddPolicyCtx(ctx, sec, ptype, rule); err != nil {
427 if err.Error() != notImplemented {
428 return false, err
429 }
430 }
431 }
432
433 err = e.model.AddPolicy(sec, ptype, rule)
434 if err != nil {
435 return false, err
436 }
437
438 if sec == "g" {
439 err := e.BuildIncrementalRoleLinks(model.PolicyAdd, ptype, [][]string{rule})
440 if err != nil {
441 return true, err
442 }
443 }
444
445 return true, nil
446}
447
448// addPoliciesWithoutNotifyCtx adds rules to the current policy with context.
449func (e *ContextEnforcer) addPoliciesWithoutNotifyCtx(ctx context.Context, sec string, ptype string, rules [][]string, autoRemoveRepeat bool) (bool, error) {

Callers 2

SelfAddPolicyCtxMethod · 0.95
addPolicyCtxMethod · 0.95

Calls 7

shouldPersistMethod · 0.80
AddPoliciesMethod · 0.65
HasPolicyMethod · 0.65
AddPolicyCtxMethod · 0.65
AddPolicyMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected