Commit cc188e50 authored by DivyPatel9881's avatar DivyPatel9881

fix: Added addPolicies and removePolicies function.

parent 13bf718c
......@@ -233,6 +233,22 @@ func (a *Adapter) AddPolicy(sec string, ptype string, rule []string) error {
return err
}
// AddPolicies adds policy rules to the storage.
func (a *Adapter) AddPolicies(sec string, ptype string, rules [][]string) error {
var lines []*CasbinRule
for _,rule := range rules{
line := savePolicyLine(ptype, rule)
lines = append(lines, line)
}
err := a.db.RunInTransaction(func(tx *pg.Tx) error {
_, err := tx.Model(&lines).OnConflict("DO NOTHING").Insert()
return err
})
return err
}
// RemovePolicy removes a policy rule from the storage.
func (a *Adapter) RemovePolicy(sec string, ptype string, rule []string) error {
line := savePolicyLine(ptype, rule)
......@@ -240,6 +256,22 @@ func (a *Adapter) RemovePolicy(sec string, ptype string, rule []string) error {
return err
}
// RemovePolicies removes policy rules from the storage.
func (a *Adapter) RemovePolicies(sec string, ptype string, rules [][]string) error {
var lines []*CasbinRule
for _,rule := range rules{
line := savePolicyLine(ptype, rule)
lines = append(lines, line)
}
err := a.db.RunInTransaction(func(tx *pg.Tx) error {
_, err := tx.Model(&lines).Delete()
return err
})
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 {
query := a.db.Model((*CasbinRule)(nil)).Where("p_type = ?", ptype)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment