mirror of
https://github.com/rancher/norman.git
synced 2025-09-02 15:54:32 +00:00
Filter resources on default fields
This change gives norman the ability to filter api requests based on the default value of fields. Before, it would filter on the actual data in the resource, and then apply default values to the resource before returning. Issue: https://github.com/rancher/rancher/issues/13418
This commit is contained in:
committed by
Darren Shepherd
parent
3499440178
commit
7fed8b17a8
@@ -7,12 +7,12 @@ import (
|
||||
"github.com/rancher/norman/types/convert"
|
||||
)
|
||||
|
||||
func QueryFilter(opts *types.QueryOptions, data []map[string]interface{}) []map[string]interface{} {
|
||||
return ApplyQueryOptions(opts, data)
|
||||
func QueryFilter(opts *types.QueryOptions, schema *types.Schema, data []map[string]interface{}) []map[string]interface{} {
|
||||
return ApplyQueryOptions(opts, schema, data)
|
||||
}
|
||||
|
||||
func ApplyQueryOptions(options *types.QueryOptions, data []map[string]interface{}) []map[string]interface{} {
|
||||
data = ApplyQueryConditions(options.Conditions, data)
|
||||
func ApplyQueryOptions(options *types.QueryOptions, schema *types.Schema, data []map[string]interface{}) []map[string]interface{} {
|
||||
data = ApplyQueryConditions(options.Conditions, schema, data)
|
||||
data = ApplySort(options.Sort, data)
|
||||
return ApplyPagination(options.Pagination, data)
|
||||
}
|
||||
@@ -35,13 +35,13 @@ func ApplySort(sortOpts types.Sort, data []map[string]interface{}) []map[string]
|
||||
return data
|
||||
}
|
||||
|
||||
func ApplyQueryConditions(conditions []*types.QueryCondition, data []map[string]interface{}) []map[string]interface{} {
|
||||
func ApplyQueryConditions(conditions []*types.QueryCondition, schema *types.Schema, data []map[string]interface{}) []map[string]interface{} {
|
||||
var result []map[string]interface{}
|
||||
|
||||
outer:
|
||||
for _, item := range data {
|
||||
for _, condition := range conditions {
|
||||
if !condition.Valid(item) {
|
||||
if !condition.Valid(schema, item) {
|
||||
continue outer
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user