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

Method RemovePolicy

model/policy.go:257–277  ·  view source on GitHub ↗

RemovePolicy removes a policy rule from the model. Deprecated: Using AddPoliciesWithAffected instead.

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

Source from the content-addressed store, hash-verified

255// RemovePolicy removes a policy rule from the model.
256// Deprecated: Using AddPoliciesWithAffected instead.
257func (model Model) RemovePolicy(sec string, ptype string, rule []string) (bool, error) {
258 ast, err := model.GetAssertion(sec, ptype)
259 if err != nil {
260 return false, err
261 }
262 key := strings.Join(rule, DefaultSep)
263 index, ok := ast.PolicyMap[key]
264 if !ok {
265 return false, nil
266 }
267
268 lastIdx := len(ast.Policy) - 1
269 if index != lastIdx {
270 ast.Policy[index] = ast.Policy[lastIdx]
271 lastPolicyKey := strings.Join(ast.Policy[index], DefaultSep)
272 ast.PolicyMap[lastPolicyKey] = index
273 }
274 ast.Policy = ast.Policy[:lastIdx]
275 delete(ast.PolicyMap, key)
276 return true, nil
277}
278
279// UpdatePolicy updates a policy rule from the model.
280func (model Model) UpdatePolicy(sec string, ptype string, oldRule []string, newRule []string) (bool, error) {

Callers

nothing calls this directly

Calls 1

GetAssertionMethod · 0.95

Tested by

no test coverage detected