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

Method addPoliciesWithoutNotify

internal_api.go:86–129  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

84// If autoRemoveRepeat == true, existing rules are automatically filtered
85// Otherwise, false is returned directly.
86func (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.
132func (e *Enforcer) removePolicyWithoutNotify(sec string, ptype string, rule []string) (bool, error) {

Callers 3

addPoliciesMethod · 0.95
SelfAddPoliciesMethod · 0.95
SelfAddPoliciesExMethod · 0.95

Calls 7

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

Tested by

no test coverage detected