Skip to content

Commit

Permalink
fix: batch enforce response (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
hound672 authored Jun 19, 2023
1 parent b031c03 commit 81ce8dc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions casdoorsdk/enforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Enforce(permissionId, modelId, resourceId string, casbinRequest CasbinReque
return allow, nil
}

func BatchEnforce(permissionId, modelId, resourceId string, casbinRequests []CasbinRequest) ([]bool, error) {
func BatchEnforce(permissionId, modelId, resourceId string, casbinRequests []CasbinRequest) ([][]bool, error) {
postBytes, err := json.Marshal(casbinRequests)
if err != nil {
return nil, err
Expand All @@ -67,18 +67,26 @@ func BatchEnforce(permissionId, modelId, resourceId string, casbinRequests []Cas
return nil, err
}

var allows []bool
var allows [][]bool
data, ok := res.Data.([]interface{})
if !ok {
return nil, errors.New("invalid data")
}

for _, d := range data {
el, ok := d.([]interface{})
elems, ok := d.([]interface{})
if !ok {
return nil, errors.New("invalid data")
}
allows = append(allows, el[0].(bool))
var permRes []bool
for _, el := range elems {
r, ok := el.(bool)
if !ok {
return nil, errors.New("invalid data")
}
permRes = append(permRes, r)
}
allows = append(allows, permRes)
}

return allows, nil
Expand Down

0 comments on commit 81ce8dc

Please sign in to comment.