MCPcopy Create free account
hub / github.com/apache/casbin / RemoveNamedGroupingPolicy

Method RemoveNamedGroupingPolicy

transaction.go:349–380  ·  view source on GitHub ↗

RemoveNamedGroupingPolicy removes a named grouping policy within the transaction.

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

Source from the content-addressed store, hash-verified

347
348// RemoveNamedGroupingPolicy removes a named grouping policy within the transaction.
349func (tx *Transaction) RemoveNamedGroupingPolicy(ptype string, params ...interface{}) (bool, error) {
350 tx.mutex.Lock()
351 defer tx.mutex.Unlock()
352
353 if err := tx.checkTransactionStatus(); err != nil {
354 return false, err
355 }
356
357 rule := tx.buildRuleFromParams(params...)
358
359 // Check if grouping policy exists in the buffered model.
360 bufferedModel, err := tx.buffer.ApplyOperationsToModel(tx.buffer.GetModelSnapshot())
361 if err != nil {
362 return false, err
363 }
364
365 hasPolicy, err := bufferedModel.HasPolicy("g", ptype, rule)
366 if !hasPolicy || err != nil {
367 return false, err
368 }
369
370 // Add operation to buffer.
371 op := persist.PolicyOperation{
372 Type: persist.OperationRemove,
373 Section: "g",
374 PolicyType: ptype,
375 Rules: [][]string{rule},
376 }
377 tx.buffer.AddOperation(op)
378
379 return true, nil
380}
381
382// GetBufferedModel returns the model as it would look after applying all buffered operations.
383// This is useful for preview or validation purposes within the transaction.

Callers 1

RemoveGroupingPolicyMethod · 0.95

Calls 6

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

Tested by

no test coverage detected