addPoliciesWithoutNotify adds rules to the current policy without notify If autoRemoveRepeat == true, existing rules are automatically filtered Otherwise, false is returned directly.
(sec string, ptype string, rules [][]string, autoRemoveRepeat bool)
| 84 | // If autoRemoveRepeat == true, existing rules are automatically filtered |
| 85 | // Otherwise, false is returned directly. |
| 86 | func (e *Enforcer) addPoliciesWithoutNotify(sec string, ptype string, rules [][]string, autoRemoveRepeat bool) (bool, error) { |
| 87 | if e.dispatcher != nil && e.autoNotifyDispatcher { |
| 88 | return true, e.dispatcher.AddPolicies(sec, ptype, rules) |
| 89 | } |
| 90 | |
| 91 | if !autoRemoveRepeat { |
| 92 | hasPolicies, err := e.model.HasPolicies(sec, ptype, rules) |
| 93 | if hasPolicies || err != nil { |
| 94 | return false, err |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | if e.shouldPersist() { |
| 99 | if err := e.adapter.(persist.BatchAdapter).AddPolicies(sec, ptype, rules); err != nil { |
| 100 | if err.Error() != notImplemented { |
| 101 | return false, err |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | err := e.model.AddPolicies(sec, ptype, rules) |
| 107 | if err != nil { |
| 108 | return false, err |
| 109 | } |
| 110 | |
| 111 | if sec == "g" { |
| 112 | err := e.BuildIncrementalRoleLinks(model.PolicyAdd, ptype, rules) |
| 113 | if err != nil { |
| 114 | return true, err |
| 115 | } |
| 116 | |
| 117 | err = e.BuildIncrementalConditionalRoleLinks(model.PolicyAdd, ptype, rules) |
| 118 | if err != nil { |
| 119 | return true, err |
| 120 | } |
| 121 | |
| 122 | // Validate constraints after adding grouping policies |
| 123 | if err := e.validateConstraintsForGroupingPolicy(); err != nil { |
| 124 | return false, err |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | return true, nil |
| 129 | } |
| 130 | |
| 131 | // removePolicy removes a rule from the current policy. |
| 132 | func (e *Enforcer) removePolicyWithoutNotify(sec string, ptype string, rule []string) (bool, error) { |
no test coverage detected