MCPcopy Index your code
hub / github.com/apache/casbin / AddNamedPolicy

Method AddNamedPolicy

management_api.go:257–268  ·  view source on GitHub ↗

AddNamedPolicy adds an authorization rule to the current named policy. If the rule already exists, the function returns false and the rule will not be added. Otherwise the function returns true by adding the new rule.

(ptype string, params ...interface{})

Source from the content-addressed store, hash-verified

255// If the rule already exists, the function returns false and the rule will not be added.
256// Otherwise the function returns true by adding the new rule.
257func (e *Enforcer) AddNamedPolicy(ptype string, params ...interface{}) (bool, error) {
258 if strSlice, ok := params[0].([]string); len(params) == 1 && ok {
259 strSlice = append(make([]string, 0, len(strSlice)), strSlice...)
260 return e.addPolicy("p", ptype, strSlice)
261 }
262 policy := make([]string, 0)
263 for _, param := range params {
264 policy = append(policy, param.(string))
265 }
266
267 return e.addPolicy("p", ptype, policy)
268}
269
270// AddNamedPolicies adds authorization rules to the current named policy.
271// If the rule already exists, the function returns false for the corresponding rule and the rule will not be added.

Callers 3

AddPolicyMethod · 0.95
TestModifyPolicyAPIFunction · 0.95
TestMockAdapterErrorsFunction · 0.95

Calls 1

addPolicyMethod · 0.95

Tested by 2

TestModifyPolicyAPIFunction · 0.76
TestMockAdapterErrorsFunction · 0.76