Skip to content

Commit

Permalink
add RemovePolicies and AddPolicies
Browse files Browse the repository at this point in the history
Signed-off-by: linxing <linxing301@gmail.com>
  • Loading branch information
linxing committed Aug 14, 2020
1 parent 0ca20dc commit 0769202
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions adapter.go
Expand Up @@ -335,13 +335,43 @@ func (a *Adapter) AddPolicy(sec string, ptype string, rule []string) error {
return err
}

// AddPolicies adds multiple policy rule to the storage.
func (a *Adapter) AddPolicies(sec string, ptype string, rules [][]string) error {
_, err := a.engine.Transaction(func(tx *xorm.Session) (interface{}, error) {
for _, rule := range rules {
line := a.savePolicyLine(ptype, rule)
_, err := tx.Insert(line)
if err != nil {
return nil, err
}
}
return nil, nil
})
return err
}

// RemovePolicy removes a policy rule from the storage.
func (a *Adapter) RemovePolicy(sec string, ptype string, rule []string) error {
line := a.savePolicyLine(ptype, rule)
_, err := a.engine.Delete(line)
return err
}

// ReovRemovePolicies removes multiple policy rule from the storage.
func (a *Adapter) RemovePolicies(sec string, ptype string, rules [][]string) error {
_, err := a.engine.Transaction(func(tx *xorm.Session) (interface{}, error) {
for _, rule := range rules {
line := a.savePolicyLine(ptype, rule)
_, err := tx.Delete(line)
if err != nil {
return nil, nil
}
}
return nil, nil
})
return err
}

// RemoveFilteredPolicy removes policy rules that match the filter from the storage.
func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int, fieldValues ...string) error {
line := &CasbinRule{PType: ptype, tableName: a.tableName}
Expand Down

0 comments on commit 0769202

Please sign in to comment.