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

Method addPolicyWithoutNotify

internal_api.go:45–81  ·  view source on GitHub ↗

addPolicy adds a rule to the current policy.

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

Source from the content-addressed store, hash-verified

43
44// addPolicy adds a rule to the current policy.
45func (e *Enforcer) addPolicyWithoutNotify(sec string, ptype string, rule []string) (bool, error) {
46 if e.dispatcher != nil && e.autoNotifyDispatcher {
47 return true, e.dispatcher.AddPolicies(sec, ptype, [][]string{rule})
48 }
49
50 hasPolicy, err := e.model.HasPolicy(sec, ptype, rule)
51 if hasPolicy || err != nil {
52 return false, err
53 }
54
55 if e.shouldPersist() {
56 if err = e.adapter.AddPolicy(sec, ptype, rule); err != nil {
57 if err.Error() != notImplemented {
58 return false, err
59 }
60 }
61 }
62
63 err = e.model.AddPolicy(sec, ptype, rule)
64 if err != nil {
65 return false, err
66 }
67
68 if sec == "g" {
69 err := e.BuildIncrementalRoleLinks(model.PolicyAdd, ptype, [][]string{rule})
70 if err != nil {
71 return true, err
72 }
73
74 // Validate constraints after adding grouping policy
75 if err := e.validateConstraintsForGroupingPolicy(); err != nil {
76 return false, err
77 }
78 }
79
80 return true, nil
81}
82
83// addPoliciesWithoutNotify adds rules to the current policy without notify
84// If autoRemoveRepeat == true, existing rules are automatically filtered

Callers 2

addPolicyMethod · 0.95
SelfAddPolicyMethod · 0.95

Calls 7

shouldPersistMethod · 0.95
AddPoliciesMethod · 0.65
HasPolicyMethod · 0.65
AddPolicyMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected