From b924fd59a5ca8f2d1e1fa47fd8a7d3db0341b3f3 Mon Sep 17 00:00:00 2001 From: Livio Spring Date: Fri, 17 May 2024 09:52:15 +0200 Subject: [PATCH] fix: allow sorting of MyProjectOrgs (by name) (#7970) --- internal/api/grpc/admin/org_converter.go | 12 +----------- internal/api/grpc/auth/user.go | 7 ++++--- internal/api/grpc/org/converter.go | 11 +++++++++++ internal/query/org.go | 5 +++-- proto/zitadel/auth.proto | 2 ++ 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/internal/api/grpc/admin/org_converter.go b/internal/api/grpc/admin/org_converter.go index 7f3066925e..62887cc34c 100644 --- a/internal/api/grpc/admin/org_converter.go +++ b/internal/api/grpc/admin/org_converter.go @@ -5,7 +5,6 @@ import ( org_grpc "github.com/zitadel/zitadel/internal/api/grpc/org" "github.com/zitadel/zitadel/internal/query" "github.com/zitadel/zitadel/pkg/grpc/admin" - "github.com/zitadel/zitadel/pkg/grpc/org" ) func listOrgRequestToModel(req *admin.ListOrgsRequest) (*query.OrgSearchQueries, error) { @@ -18,18 +17,9 @@ func listOrgRequestToModel(req *admin.ListOrgsRequest) (*query.OrgSearchQueries, SearchRequest: query.SearchRequest{ Offset: offset, Limit: limit, - SortingColumn: fieldNameToOrgColumn(req.SortingColumn), + SortingColumn: org_grpc.FieldNameToOrgColumn(req.SortingColumn), Asc: asc, }, Queries: queries, }, nil } - -func fieldNameToOrgColumn(fieldName org.OrgFieldName) query.Column { - switch fieldName { - case org.OrgFieldName_ORG_FIELD_NAME_NAME: - return query.OrgColumnName - default: - return query.Column{} - } -} diff --git a/internal/api/grpc/auth/user.go b/internal/api/grpc/auth/user.go index f32af2f74b..1efdbe8dd2 100644 --- a/internal/api/grpc/auth/user.go +++ b/internal/api/grpc/auth/user.go @@ -266,9 +266,10 @@ func ListMyProjectOrgsRequestToQuery(req *auth_pb.ListMyProjectOrgsRequest) (*qu } return &query.OrgSearchQueries{ SearchRequest: query.SearchRequest{ - Offset: offset, - Limit: limit, - Asc: asc, + Offset: offset, + Limit: limit, + Asc: asc, + SortingColumn: org.FieldNameToOrgColumn(req.SortingColumn), }, Queries: queries, }, nil diff --git a/internal/api/grpc/org/converter.go b/internal/api/grpc/org/converter.go index d3c3cb3c11..3f0084c978 100644 --- a/internal/api/grpc/org/converter.go +++ b/internal/api/grpc/org/converter.go @@ -186,3 +186,14 @@ func DomainValidationTypeFromModel(validationType domain.OrgDomainValidationType return org_pb.DomainValidationType_DOMAIN_VALIDATION_TYPE_UNSPECIFIED } } + +func FieldNameToOrgColumn(fieldName org_pb.OrgFieldName) query.Column { + switch fieldName { + case org_pb.OrgFieldName_ORG_FIELD_NAME_NAME: + return query.OrgColumnName + case org_pb.OrgFieldName_ORG_FIELD_NAME_UNSPECIFIED: + return query.Column{} + default: + return query.Column{} + } +} diff --git a/internal/query/org.go b/internal/query/org.go index eaeaf6eb29..18715d015e 100644 --- a/internal/query/org.go +++ b/internal/query/org.go @@ -52,8 +52,9 @@ var ( table: orgsTable, } OrgColumnName = Column{ - name: projection.OrgColumnName, - table: orgsTable, + name: projection.OrgColumnName, + table: orgsTable, + isOrderByLower: true, } OrgColumnDomain = Column{ name: projection.OrgColumnDomain, diff --git a/proto/zitadel/auth.proto b/proto/zitadel/auth.proto index 58767f9fe9..5e5dcd6fb9 100644 --- a/proto/zitadel/auth.proto +++ b/proto/zitadel/auth.proto @@ -1569,6 +1569,8 @@ message ListMyProjectOrgsRequest { zitadel.v1.ListQuery query = 1; //criteria the client is looking for repeated zitadel.org.v1.OrgQuery queries = 2; + // States by which field the results are sorted. + zitadel.org.v1.OrgFieldName sorting_column = 3; } message ListMyProjectOrgsResponse {