Skip to content

Commit

Permalink
fix: RemoveFilteredPolicy don't check empty parameter
Browse files Browse the repository at this point in the history
Signed-off-by: tangyang9464 <tangyang9464@163.com>
  • Loading branch information
tangyang9464 committed Sep 9, 2021
1 parent ce5e281 commit 275ad34
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,16 @@ func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int,
line := a.getTableInstance()

line.Ptype = ptype

if fieldIndex == -1 {
return a.rawDelete(a.db, *line)
}

err := checkQueryField(fieldValues)
if err != nil {
return err
}

if fieldIndex <= 0 && 0 < fieldIndex+len(fieldValues) {
line.V0 = fieldValues[0-fieldIndex]
}
Expand All @@ -600,10 +610,20 @@ func (a *Adapter) RemoveFilteredPolicy(sec string, ptype string, fieldIndex int,
if fieldIndex <= 5 && 5 < fieldIndex+len(fieldValues) {
line.V5 = fieldValues[5-fieldIndex]
}
err := a.rawDelete(a.db, *line)
err = a.rawDelete(a.db, *line)
return err
}

// checkQueryfield make sure the fields won't all be empty (string --> "")
func checkQueryField(fieldValues []string) error {
for _, fieldValue := range fieldValues {
if fieldValue != "" {
return nil
}
}
return errors.New("the query field cannot all be empty string (\"\"), please check")
}

func (a *Adapter) rawDelete(db *gorm.DB, line CasbinRule) error {
queryArgs := []interface{}{line.Ptype}

Expand Down

0 comments on commit 275ad34

Please sign in to comment.