From 6eb982e368cd5e854bab077efc0b61ec1de4dd0e Mon Sep 17 00:00:00 2001 From: Silvan Date: Thu, 21 Mar 2024 15:56:58 +0100 Subject: [PATCH] fix(api): correct mapping of metadata queries (#7609) --- internal/api/grpc/auth/metadata_converter.go | 2 +- internal/api/grpc/management/org_converter.go | 2 +- .../api/grpc/management/user_converter.go | 2 +- internal/api/grpc/metadata/metadata.go | 30 ++++++++++++++----- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/internal/api/grpc/auth/metadata_converter.go b/internal/api/grpc/auth/metadata_converter.go index fa6ed41cb6..943ae06a96 100644 --- a/internal/api/grpc/auth/metadata_converter.go +++ b/internal/api/grpc/auth/metadata_converter.go @@ -21,7 +21,7 @@ func BulkSetMetadataToDomain(req *auth.BulkSetMyMetadataRequest) []*domain.Metad func ListUserMetadataToQuery(req *auth.ListMyMetadataRequest) (*query.UserMetadataSearchQueries, error) { offset, limit, asc := object.ListQueryToModel(req.Query) - queries, err := metadata.MetadataQueriesToQuery(req.Queries) + queries, err := metadata.UserMetadataQueriesToQuery(req.Queries) if err != nil { return nil, err } diff --git a/internal/api/grpc/management/org_converter.go b/internal/api/grpc/management/org_converter.go index 299a1abaa9..879b5e0763 100644 --- a/internal/api/grpc/management/org_converter.go +++ b/internal/api/grpc/management/org_converter.go @@ -110,7 +110,7 @@ func BulkSetOrgMetadataToDomain(req *mgmt_pb.BulkSetOrgMetadataRequest) []*domai func ListOrgMetadataToDomain(req *mgmt_pb.ListOrgMetadataRequest) (*query.OrgMetadataSearchQueries, error) { offset, limit, asc := object.ListQueryToModel(req.Query) - queries, err := metadata.MetadataQueriesToQuery(req.Queries) + queries, err := metadata.OrgMetadataQueriesToQuery(req.Queries) if err != nil { return nil, err } diff --git a/internal/api/grpc/management/user_converter.go b/internal/api/grpc/management/user_converter.go index dc627c885a..a2de7a601b 100644 --- a/internal/api/grpc/management/user_converter.go +++ b/internal/api/grpc/management/user_converter.go @@ -76,7 +76,7 @@ func BulkSetUserMetadataToDomain(req *mgmt_pb.BulkSetUserMetadataRequest) []*dom func ListUserMetadataToDomain(req *mgmt_pb.ListUserMetadataRequest) (*query.UserMetadataSearchQueries, error) { offset, limit, asc := object.ListQueryToModel(req.Query) - queries, err := metadata.MetadataQueriesToQuery(req.Queries) + queries, err := metadata.UserMetadataQueriesToQuery(req.Queries) if err != nil { return nil, err } diff --git a/internal/api/grpc/metadata/metadata.go b/internal/api/grpc/metadata/metadata.go index e6be7685f7..cdeba80564 100644 --- a/internal/api/grpc/metadata/metadata.go +++ b/internal/api/grpc/metadata/metadata.go @@ -49,10 +49,10 @@ func OrgMetadataToPb(data *query.OrgMetadata) *meta_pb.Metadata { } } -func MetadataQueriesToQuery(queries []*meta_pb.MetadataQuery) (_ []query.SearchQuery, err error) { +func OrgMetadataQueriesToQuery(queries []*meta_pb.MetadataQuery) (_ []query.SearchQuery, err error) { q := make([]query.SearchQuery, len(queries)) for i, query := range queries { - q[i], err = MetadataQueryToQuery(query) + q[i], err = OrgMetadataQueryToQuery(query) if err != nil { return nil, err } @@ -60,15 +60,31 @@ func MetadataQueriesToQuery(queries []*meta_pb.MetadataQuery) (_ []query.SearchQ return q, nil } -func MetadataQueryToQuery(query *meta_pb.MetadataQuery) (query.SearchQuery, error) { - switch q := query.Query.(type) { +func OrgMetadataQueryToQuery(metadataQuery *meta_pb.MetadataQuery) (query.SearchQuery, error) { + switch q := metadataQuery.Query.(type) { case *meta_pb.MetadataQuery_KeyQuery: - return MetadataKeyQueryToQuery(q.KeyQuery) + return query.NewOrgMetadataKeySearchQuery(q.KeyQuery.Key, object.TextMethodToQuery(q.KeyQuery.Method)) default: return nil, zerrors.ThrowInvalidArgument(nil, "METAD-fdg23", "List.Query.Invalid") } } -func MetadataKeyQueryToQuery(q *meta_pb.MetadataKeyQuery) (query.SearchQuery, error) { - return query.NewOrgMetadataKeySearchQuery(q.Key, object.TextMethodToQuery(q.Method)) +func UserMetadataQueriesToQuery(queries []*meta_pb.MetadataQuery) (_ []query.SearchQuery, err error) { + q := make([]query.SearchQuery, len(queries)) + for i, query := range queries { + q[i], err = UserMetadataQueryToQuery(query) + if err != nil { + return nil, err + } + } + return q, nil +} + +func UserMetadataQueryToQuery(metadataQuery *meta_pb.MetadataQuery) (query.SearchQuery, error) { + switch q := metadataQuery.Query.(type) { + case *meta_pb.MetadataQuery_KeyQuery: + return query.NewUserMetadataKeySearchQuery(q.KeyQuery.Key, object.TextMethodToQuery(q.KeyQuery.Method)) + default: + return nil, zerrors.ThrowInvalidArgument(nil, "METAD-Vn7qy", "List.Query.Invalid") + } }