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

Method AddPoliciesWithAffected

model/policy.go:234–253  ·  view source on GitHub ↗

AddPoliciesWithAffected adds policy rules to the model, and returns affected rules.

(sec string, ptype string, rules [][]string)

Source from the content-addressed store, hash-verified

232
233// AddPoliciesWithAffected adds policy rules to the model, and returns affected rules.
234func (model Model) AddPoliciesWithAffected(sec string, ptype string, rules [][]string) ([][]string, error) {
235 _, err := model.GetAssertion(sec, ptype)
236 if err != nil {
237 return nil, err
238 }
239 var affected [][]string
240 for _, rule := range rules {
241 hashKey := strings.Join(rule, DefaultSep)
242 _, ok := model[sec][ptype].PolicyMap[hashKey]
243 if ok {
244 continue
245 }
246 affected = append(affected, rule)
247 err = model.AddPolicy(sec, ptype, rule)
248 if err != nil {
249 return affected, err
250 }
251 }
252 return affected, err
253}
254
255// RemovePolicy removes a policy rule from the model.
256// Deprecated: Using AddPoliciesWithAffected instead.

Callers 2

AddPoliciesMethod · 0.95
AddPoliciesSelfMethod · 0.80

Calls 2

GetAssertionMethod · 0.95
AddPolicyMethod · 0.95

Tested by

no test coverage detected