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

Method AddNamedGroupingPolicy

transaction.go:310–341  ·  view source on GitHub ↗

AddNamedGroupingPolicy adds a named grouping policy within the transaction.

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

Source from the content-addressed store, hash-verified

308
309// AddNamedGroupingPolicy adds a named grouping policy within the transaction.
310func (tx *Transaction) AddNamedGroupingPolicy(ptype string, params ...interface{}) (bool, error) {
311 tx.mutex.Lock()
312 defer tx.mutex.Unlock()
313
314 if err := tx.checkTransactionStatus(); err != nil {
315 return false, err
316 }
317
318 rule := tx.buildRuleFromParams(params...)
319
320 // Check if grouping policy already exists in the buffered model.
321 bufferedModel, err := tx.buffer.ApplyOperationsToModel(tx.buffer.GetModelSnapshot())
322 if err != nil {
323 return false, err
324 }
325
326 hasPolicy, err := bufferedModel.HasPolicy("g", ptype, rule)
327 if hasPolicy || err != nil {
328 return false, err
329 }
330
331 // Add operation to buffer.
332 op := persist.PolicyOperation{
333 Type: persist.OperationAdd,
334 Section: "g",
335 PolicyType: ptype,
336 Rules: [][]string{rule},
337 }
338 tx.buffer.AddOperation(op)
339
340 return true, nil
341}
342
343// RemoveGroupingPolicy removes a grouping policy within the transaction.
344func (tx *Transaction) RemoveGroupingPolicy(params ...interface{}) (bool, error) {

Callers 1

AddGroupingPolicyMethod · 0.95

Calls 6

buildRuleFromParamsMethod · 0.95
GetModelSnapshotMethod · 0.80
AddOperationMethod · 0.80
HasPolicyMethod · 0.65

Tested by

no test coverage detected