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

Method applyOperationsToModel

transaction_commit.go:211–243  ·  view source on GitHub ↗

applyOperationsToModel applies all buffered operations to the in-memory model.

()

Source from the content-addressed store, hash-verified

209
210// applyOperationsToModel applies all buffered operations to the in-memory model.
211func (tx *Transaction) applyOperationsToModel() error {
212 // Create new model with all operations applied.
213 newModel, err := tx.buffer.ApplyOperationsToModel(tx.buffer.GetModelSnapshot())
214 if err != nil {
215 return err
216 }
217
218 // Replace the enforcer's model.
219 tx.enforcer.model = newModel
220 tx.enforcer.invalidateMatcherMap()
221
222 // Rebuild role links if necessary.
223 if tx.enforcer.autoBuildRoleLinks {
224 // Check if any operations involved grouping policies.
225 operations := tx.buffer.GetOperations()
226 needRoleRebuild := false
227
228 for _, op := range operations {
229 if op.Section == "g" {
230 needRoleRebuild = true
231 break
232 }
233 }
234
235 if needRoleRebuild {
236 if err := tx.enforcer.BuildRoleLinks(); err != nil {
237 return err
238 }
239 }
240 }
241
242 return nil
243}
244
245// IsCommitted returns true if the transaction has been committed.
246func (tx *Transaction) IsCommitted() bool {

Callers 1

CommitMethod · 0.95

Calls 5

GetModelSnapshotMethod · 0.80
invalidateMatcherMapMethod · 0.80
GetOperationsMethod · 0.80
BuildRoleLinksMethod · 0.65

Tested by

no test coverage detected