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)
| 413 | |
| 414 | // addPolicyWithoutNotifyCtx adds a rule to the current policy with context. |
| 415 | func (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. |
| 449 | func (e *ContextEnforcer) addPoliciesWithoutNotifyCtx(ctx context.Context, sec string, ptype string, rules [][]string, autoRemoveRepeat bool) (bool, error) { |
no test coverage detected