FilterAttributesQuery - Filter attributes according to given filter
(tenantID string, filter *base.AttributeFilter)
| 38 | |
| 39 | // FilterAttributesQuery - Filter attributes according to given filter |
| 40 | func FilterAttributesQuery(tenantID string, filter *base.AttributeFilter) memdb.FilterFunc { |
| 41 | return func(attributeRaw interface{}) bool { |
| 42 | attribute, ok := attributeRaw.(storage.Attribute) |
| 43 | if !ok { |
| 44 | return true |
| 45 | } |
| 46 | switch { |
| 47 | case attribute.TenantID != tenantID: |
| 48 | return true |
| 49 | case filter.GetEntity().GetType() != "" && attribute.EntityType != filter.GetEntity().GetType(): |
| 50 | return true |
| 51 | case len(filter.GetEntity().GetIds()) > 0 && !slices.Contains(filter.GetEntity().GetIds(), attribute.EntityID): |
| 52 | return true |
| 53 | case len(filter.GetAttributes()) > 0 && !slices.Contains(filter.GetAttributes(), attribute.Attribute): |
| 54 | return true |
| 55 | } |
| 56 | return false |
| 57 | } |
| 58 | } |
no test coverage detected