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

Method addPoliciesWithoutNotifyCtx

enforcer_context.go:449–487  ·  view source on GitHub ↗

addPoliciesWithoutNotifyCtx adds rules to the current policy with context.

(ctx context.Context, sec string, ptype string, rules [][]string, autoRemoveRepeat bool)

Source from the content-addressed store, hash-verified

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) {
450 if e.dispatcher != nil && e.autoNotifyDispatcher {
451 return true, e.dispatcher.AddPolicies(sec, ptype, rules)
452 }
453
454 if !autoRemoveRepeat {
455 hasPolicies, err := e.model.HasPolicies(sec, ptype, rules)
456 if hasPolicies || err != nil {
457 return false, err
458 }
459 }
460
461 if e.shouldPersist() {
462 if err := e.adapterCtx.(persist.ContextBatchAdapter).AddPoliciesCtx(ctx, sec, ptype, rules); err != nil {
463 if err.Error() != notImplemented {
464 return false, err
465 }
466 }
467 }
468
469 err := e.model.AddPolicies(sec, ptype, rules)
470 if err != nil {
471 return false, err
472 }
473
474 if sec == "g" {
475 err := e.BuildIncrementalRoleLinks(model.PolicyAdd, ptype, rules)
476 if err != nil {
477 return true, err
478 }
479
480 err = e.BuildIncrementalConditionalRoleLinks(model.PolicyAdd, ptype, rules)
481 if err != nil {
482 return true, err
483 }
484 }
485
486 return true, nil
487}
488
489// removePolicyWithoutNotifyCtx removes a rule from the current policy with context.
490func (e *ContextEnforcer) removePolicyWithoutNotifyCtx(ctx context.Context, sec string, ptype string, rule []string) (bool, error) {

Callers 3

SelfAddPoliciesCtxMethod · 0.95
SelfAddPoliciesExCtxMethod · 0.95
addPoliciesCtxMethod · 0.95

Calls 7

HasPoliciesMethod · 0.80
shouldPersistMethod · 0.80
AddPoliciesMethod · 0.65
AddPoliciesCtxMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected