Skip to content

Commit

Permalink
fix must_not
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoRoessner committed Feb 16, 2024
1 parent 01edc6a commit d241a14
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 4 deletions.
80 changes: 80 additions & 0 deletions lib/apiv3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,86 @@ func TestApiV3(t *testing.T) {

t.Run("get rights of unknown with admin", testRequestWithToken(config, admintoken, "GET", "/v3/administrate/rights/aspects/unknown", nil, 404, nil))

t.Run("filter creator by jwt ref", testRequestWithToken(config, admintoken, "POST", "/v3/query/aspects", model.QueryMessage{
Resource: "aspects",
Find: &model.QueryFind{
QueryListCommons: model.QueryListCommons{
Rights: "r",
SortDesc: true,
},
Search: "",
Filter: &model.Selection{
Condition: model.ConditionConfig{
Feature: "creator",
Operation: "!=",
Ref: "jwt.user",
},
},
},
}, 200, nil))

t.Run("filter creator by jwt ref client", func(t *testing.T) {
result, code, err := client.Query[[]any](c, admintoken, model.QueryMessage{
Resource: "aspects",
Find: &model.QueryFind{
QueryListCommons: model.QueryListCommons{
Rights: "r",
SortDesc: true,
},
Search: "",
Filter: &model.Selection{
Condition: model.ConditionConfig{
Feature: "creator",
Operation: "!=",
Ref: "jwt.user",
},
},
},
})
if err != nil {
t.Error(err)
return
}
if code != 200 {
t.Error(code)
return
}
if len(result) == 0 {
t.Error(result)
return
}

result, code, err = client.Query[[]any](c, testtoken, model.QueryMessage{
Resource: "aspects",
Find: &model.QueryFind{
QueryListCommons: model.QueryListCommons{
Rights: "r",
SortDesc: true,
},
Search: "",
Filter: &model.Selection{
Condition: model.ConditionConfig{
Feature: "creator",
Operation: "!=",
Ref: "jwt.user",
},
},
},
})
if err != nil {
t.Error(err)
return
}
if code != 200 {
t.Error(code)
return
}
if len(result) != 0 {
t.Error(result)
return
}
})

}

func jsonNormaliseMap(in []map[string]interface{}) (out []map[string]interface{}) {
Expand Down
10 changes: 6 additions & 4 deletions lib/query/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ func (this *Query) GetConditionFilter(token auth.Token, condition model.Conditio
}, nil
} else {
return map[string]interface{}{
"must_not": []map[string]interface{}{
{
"term": map[string]interface{}{
condition.Feature: val,
"bool": map[string]interface{}{
"must_not": []map[string]interface{}{
{
"term": map[string]interface{}{
condition.Feature: val,
},
},
},
},
Expand Down

0 comments on commit d241a14

Please sign in to comment.