diff --git a/internal/api/grpc/org/v2/integration_test/org_test.go b/internal/api/grpc/org/v2/integration_test/org_test.go index 1bce22e70b..e84da7a811 100644 --- a/internal/api/grpc/org/v2/integration_test/org_test.go +++ b/internal/api/grpc/org/v2/integration_test/org_test.go @@ -42,6 +42,8 @@ func TestMain(m *testing.M) { } func TestServer_AddOrganization(t *testing.T) { + t.Parallel() + idpResp := Instance.AddGenericOAuthProvider(CTX, Instance.DefaultOrg.Id) tests := []struct { diff --git a/internal/api/grpc/org/v2/integration_test/query_test.go b/internal/api/grpc/org/v2/integration_test/query_test.go index f543c3c3b6..e075ba66ea 100644 --- a/internal/api/grpc/org/v2/integration_test/query_test.go +++ b/internal/api/grpc/org/v2/integration_test/query_test.go @@ -26,6 +26,8 @@ type orgAttr struct { } func TestServer_ListOrganizations(t *testing.T) { + t.Parallel() + type args struct { ctx context.Context req *org.ListOrganizationsRequest @@ -37,6 +39,38 @@ func TestServer_ListOrganizations(t *testing.T) { want *org.ListOrganizationsResponse wantErr bool }{ + { + name: "list org by default, ok", + args: args{ + CTX, + &org.ListOrganizationsRequest{ + Queries: []*org.SearchQuery{ + DefaultOrganizationQuery(), + }, + }, + nil, + }, + want: &org.ListOrganizationsResponse{ + Details: &object.ListDetails{ + TotalResult: 1, + Timestamp: timestamppb.Now(), + }, + SortingColumn: 0, + Result: []*org.Organization{ + { + Id: Instance.DefaultOrg.Id, + Name: Instance.DefaultOrg.Name, + PrimaryDomain: Instance.DefaultOrg.PrimaryDomain, + State: org.OrganizationState_ORGANIZATION_STATE_ACTIVE, + Details: &object.Details{ + Sequence: Instance.DefaultOrg.Details.Sequence, + ChangeDate: Instance.DefaultOrg.Details.ChangeDate, + ResourceOwner: Instance.DefaultOrg.Details.ResourceOwner, + }, + }, + }, + }, + }, { name: "list org by id, ok, multiple", args: args{ @@ -401,6 +435,12 @@ func TestServer_ListOrganizations(t *testing.T) { } } +func DefaultOrganizationQuery() *org.SearchQuery { + return &org.SearchQuery{Query: &org.SearchQuery_DefaultQuery{ + DefaultQuery: &org.DefaultOrganizationQuery{}, + }} +} + func OrganizationIdQuery(resourceowner string) *org.SearchQuery { return &org.SearchQuery{Query: &org.SearchQuery_IdQuery{ IdQuery: &org.OrganizationIDQuery{ diff --git a/internal/api/grpc/org/v2/query.go b/internal/api/grpc/org/v2/query.go index 772726fd40..6c2919c5b8 100644 --- a/internal/api/grpc/org/v2/query.go +++ b/internal/api/grpc/org/v2/query.go @@ -3,6 +3,7 @@ package org import ( "context" + "github.com/zitadel/zitadel/internal/api/authz" "github.com/zitadel/zitadel/internal/api/grpc/object/v2" "github.com/zitadel/zitadel/internal/domain" "github.com/zitadel/zitadel/internal/query" @@ -11,7 +12,7 @@ import ( ) func (s *Server) ListOrganizations(ctx context.Context, req *org.ListOrganizationsRequest) (*org.ListOrganizationsResponse, error) { - queries, err := listOrgRequestToModel(req) + queries, err := listOrgRequestToModel(ctx, req) if err != nil { return nil, err } @@ -25,9 +26,9 @@ func (s *Server) ListOrganizations(ctx context.Context, req *org.ListOrganizatio }, nil } -func listOrgRequestToModel(req *org.ListOrganizationsRequest) (*query.OrgSearchQueries, error) { +func listOrgRequestToModel(ctx context.Context, req *org.ListOrganizationsRequest) (*query.OrgSearchQueries, error) { offset, limit, asc := object.ListQueryToQuery(req.Query) - queries, err := orgQueriesToQuery(req.Queries) + queries, err := orgQueriesToQuery(ctx, req.Queries) if err != nil { return nil, err } @@ -42,10 +43,10 @@ func listOrgRequestToModel(req *org.ListOrganizationsRequest) (*query.OrgSearchQ }, nil } -func orgQueriesToQuery(queries []*org.SearchQuery) (_ []query.SearchQuery, err error) { +func orgQueriesToQuery(ctx context.Context, queries []*org.SearchQuery) (_ []query.SearchQuery, err error) { q := make([]query.SearchQuery, len(queries)) for i, query := range queries { - q[i], err = orgQueryToQuery(query) + q[i], err = orgQueryToQuery(ctx, query) if err != nil { return nil, err } @@ -53,7 +54,7 @@ func orgQueriesToQuery(queries []*org.SearchQuery) (_ []query.SearchQuery, err e return q, nil } -func orgQueryToQuery(orgQuery *org.SearchQuery) (query.SearchQuery, error) { +func orgQueryToQuery(ctx context.Context, orgQuery *org.SearchQuery) (query.SearchQuery, error) { switch q := orgQuery.Query.(type) { case *org.SearchQuery_DomainQuery: return query.NewOrgDomainSearchQuery(object.TextMethodToQuery(q.DomainQuery.Method), q.DomainQuery.Domain) @@ -63,6 +64,8 @@ func orgQueryToQuery(orgQuery *org.SearchQuery) (query.SearchQuery, error) { return query.NewOrgStateSearchQuery(orgStateToDomain(q.StateQuery.State)) case *org.SearchQuery_IdQuery: return query.NewOrgIDSearchQuery(q.IdQuery.Id) + case *org.SearchQuery_DefaultQuery: + return query.NewOrgIDSearchQuery(authz.GetInstance(ctx).DefaultOrganisationID()) default: return nil, zerrors.ThrowInvalidArgument(nil, "ORG-vR9nC", "List.Query.Invalid") } diff --git a/proto/zitadel/org/v2/query.proto b/proto/zitadel/org/v2/query.proto index bf0d8fb92a..0606dd357e 100644 --- a/proto/zitadel/org/v2/query.proto +++ b/proto/zitadel/org/v2/query.proto @@ -20,6 +20,7 @@ message SearchQuery { OrganizationDomainQuery domain_query = 2; OrganizationStateQuery state_query = 3; OrganizationIDQuery id_query = 4; + DefaultOrganizationQuery default_query = 5; } } @@ -80,4 +81,6 @@ message OrganizationIDQuery { enum OrganizationFieldName { ORGANIZATION_FIELD_NAME_UNSPECIFIED = 0; ORGANIZATION_FIELD_NAME_NAME = 1; -} \ No newline at end of file +} + +message DefaultOrganizationQuery {} \ No newline at end of file