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