HasNamedPolicy determines whether a named authorization rule exists.
(ptype string, params ...interface{})
| 218 | |
| 219 | // HasNamedPolicy determines whether a named authorization rule exists. |
| 220 | func (e *Enforcer) HasNamedPolicy(ptype string, params ...interface{}) (bool, error) { |
| 221 | if strSlice, ok := params[0].([]string); len(params) == 1 && ok { |
| 222 | return e.model.HasPolicy("p", ptype, strSlice) |
| 223 | } |
| 224 | |
| 225 | policy := make([]string, 0) |
| 226 | for _, param := range params { |
| 227 | policy = append(policy, param.(string)) |
| 228 | } |
| 229 | |
| 230 | return e.model.HasPolicy("p", ptype, policy) |
| 231 | } |
| 232 | |
| 233 | // AddPolicy adds an authorization rule to the current policy. |
| 234 | // If the rule already exists, the function returns false and the rule will not be added. |