|
| 1 | +// Copyright 2026 The casbin Authors. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package casbin |
| 16 | + |
| 17 | +// GetAIPolicy gets all the AI policy rules in the policy. |
| 18 | +func (e *Enforcer) GetAIPolicy() ([][]string, error) { |
| 19 | + return e.GetNamedAIPolicy("a") |
| 20 | +} |
| 21 | + |
| 22 | +// GetFilteredAIPolicy gets all the AI policy rules in the policy, field filters can be specified. |
| 23 | +func (e *Enforcer) GetFilteredAIPolicy(fieldIndex int, fieldValues ...string) ([][]string, error) { |
| 24 | + return e.GetFilteredNamedAIPolicy("a", fieldIndex, fieldValues...) |
| 25 | +} |
| 26 | + |
| 27 | +// GetNamedAIPolicy gets all the AI policy rules in the named policy. |
| 28 | +func (e *Enforcer) GetNamedAIPolicy(ptype string) ([][]string, error) { |
| 29 | + return e.model.GetPolicy("a", ptype) |
| 30 | +} |
| 31 | + |
| 32 | +// GetFilteredNamedAIPolicy gets all the AI policy rules in the named policy, field filters can be specified. |
| 33 | +func (e *Enforcer) GetFilteredNamedAIPolicy(ptype string, fieldIndex int, fieldValues ...string) ([][]string, error) { |
| 34 | + return e.model.GetFilteredPolicy("a", ptype, fieldIndex, fieldValues...) |
| 35 | +} |
| 36 | + |
| 37 | +// HasAIPolicy determines whether an AI policy rule exists. |
| 38 | +func (e *Enforcer) HasAIPolicy(params ...string) (bool, error) { |
| 39 | + return e.HasNamedAIPolicy("a", params...) |
| 40 | +} |
| 41 | + |
| 42 | +// HasNamedAIPolicy determines whether a named AI policy rule exists. |
| 43 | +func (e *Enforcer) HasNamedAIPolicy(ptype string, params ...string) (bool, error) { |
| 44 | + return e.model.HasPolicy("a", ptype, params) |
| 45 | +} |
| 46 | + |
| 47 | +// AddAIPolicy adds an AI policy rule to the current policy. |
| 48 | +// If the rule already exists, the function returns false and the rule will not be added. |
| 49 | +// Otherwise the function returns true by adding the new rule. |
| 50 | +func (e *Enforcer) AddAIPolicy(params ...string) (bool, error) { |
| 51 | + return e.AddNamedAIPolicy("a", params...) |
| 52 | +} |
| 53 | + |
| 54 | +// AddAIPolicies adds AI policy rules to the current policy. |
| 55 | +// If the rule already exists, the function returns false for the corresponding rule and the rule will not be added. |
| 56 | +// Otherwise the function returns true for the corresponding rule by adding the new rule. |
| 57 | +func (e *Enforcer) AddAIPolicies(rules [][]string) (bool, error) { |
| 58 | + return e.AddNamedAIPolicies("a", rules) |
| 59 | +} |
| 60 | + |
| 61 | +// AddNamedAIPolicy adds an AI policy rule to the current named policy. |
| 62 | +// If the rule already exists, the function returns false and the rule will not be added. |
| 63 | +// Otherwise the function returns true by adding the new rule. |
| 64 | +func (e *Enforcer) AddNamedAIPolicy(ptype string, params ...string) (bool, error) { |
| 65 | + return e.addPolicyInternal("a", ptype, params) |
| 66 | +} |
| 67 | + |
| 68 | +// AddNamedAIPolicies adds AI policy rules to the current named policy. |
| 69 | +// If the rule already exists, the function returns false for the corresponding policy rule and the rule will not be added. |
| 70 | +// Otherwise the function returns true for the corresponding policy rule by adding the new rule. |
| 71 | +func (e *Enforcer) AddNamedAIPolicies(ptype string, rules [][]string) (bool, error) { |
| 72 | + return e.addPoliciesInternal("a", ptype, rules) |
| 73 | +} |
| 74 | + |
| 75 | +// RemoveAIPolicy removes an AI policy rule from the current policy. |
| 76 | +func (e *Enforcer) RemoveAIPolicy(params ...string) (bool, error) { |
| 77 | + return e.RemoveNamedAIPolicy("a", params...) |
| 78 | +} |
| 79 | + |
| 80 | +// RemoveAIPolicies removes AI policy rules from the current policy. |
| 81 | +func (e *Enforcer) RemoveAIPolicies(rules [][]string) (bool, error) { |
| 82 | + return e.RemoveNamedAIPolicies("a", rules) |
| 83 | +} |
| 84 | + |
| 85 | +// RemoveFilteredAIPolicy removes an AI policy rule from the current policy, field filters can be specified. |
| 86 | +func (e *Enforcer) RemoveFilteredAIPolicy(fieldIndex int, fieldValues ...string) (bool, error) { |
| 87 | + return e.RemoveFilteredNamedAIPolicy("a", fieldIndex, fieldValues...) |
| 88 | +} |
| 89 | + |
| 90 | +// RemoveNamedAIPolicy removes an AI policy rule from the current named policy. |
| 91 | +func (e *Enforcer) RemoveNamedAIPolicy(ptype string, params ...string) (bool, error) { |
| 92 | + return e.removePolicyInternal("a", ptype, params) |
| 93 | +} |
| 94 | + |
| 95 | +// RemoveNamedAIPolicies removes AI policy rules from the current named policy. |
| 96 | +func (e *Enforcer) RemoveNamedAIPolicies(ptype string, rules [][]string) (bool, error) { |
| 97 | + return e.removePoliciesInternal("a", ptype, rules) |
| 98 | +} |
| 99 | + |
| 100 | +// RemoveFilteredNamedAIPolicy removes an AI policy rule from the current named policy, field filters can be specified. |
| 101 | +func (e *Enforcer) RemoveFilteredNamedAIPolicy(ptype string, fieldIndex int, fieldValues ...string) (bool, error) { |
| 102 | + return e.removeFilteredPolicyInternal("a", ptype, fieldIndex, fieldValues...) |
| 103 | +} |
| 104 | + |
| 105 | +// UpdateAIPolicy updates an AI policy rule from the current policy. |
| 106 | +func (e *Enforcer) UpdateAIPolicy(oldPolicy []string, newPolicy []string) (bool, error) { |
| 107 | + return e.UpdateNamedAIPolicy("a", oldPolicy, newPolicy) |
| 108 | +} |
| 109 | + |
| 110 | +// UpdateAIPolicies updates AI policy rules from the current policy. |
| 111 | +func (e *Enforcer) UpdateAIPolicies(oldPolicies [][]string, newPolicies [][]string) (bool, error) { |
| 112 | + return e.UpdateNamedAIPolicies("a", oldPolicies, newPolicies) |
| 113 | +} |
| 114 | + |
| 115 | +// UpdateNamedAIPolicy updates an AI policy rule from the current named policy. |
| 116 | +func (e *Enforcer) UpdateNamedAIPolicy(ptype string, oldPolicy []string, newPolicy []string) (bool, error) { |
| 117 | + return e.updatePolicyInternal("a", ptype, oldPolicy, newPolicy) |
| 118 | +} |
| 119 | + |
| 120 | +// UpdateNamedAIPolicies updates AI policy rules from the current named policy. |
| 121 | +func (e *Enforcer) UpdateNamedAIPolicies(ptype string, oldPolicies [][]string, newPolicies [][]string) (bool, error) { |
| 122 | + return e.updatePoliciesInternal("a", ptype, oldPolicies, newPolicies) |
| 123 | +} |
0 commit comments