AddNamedGroupingPolicy adds a named grouping policy within the transaction.
(ptype string, params ...interface{})
| 308 | |
| 309 | // AddNamedGroupingPolicy adds a named grouping policy within the transaction. |
| 310 | func (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. |
| 344 | func (tx *Transaction) RemoveGroupingPolicy(params ...interface{}) (bool, error) { |
no test coverage detected