fix: correctly search for verified domain (#8820)

# Which Problems Are Solved

Searching orgs by domain currently only looked for the primary domain,
but should be possible with all verified domains (as documented)

# How the Problems Are Solved

- fixed the search query

# Additional Changes

None

# Additional Context

- closes https://github.com/zitadel/zitadel/issues/8749
This commit is contained in:
Livio Spring 2024-10-25 17:51:44 +02:00 committed by GitHub
parent 4eeb2be36a
commit 0b5079c11f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 61 additions and 4 deletions

View File

@ -22,7 +22,7 @@ func OrgQueriesToModel(queries []*org_pb.OrgQuery) (_ []query.SearchQuery, err e
func OrgQueryToModel(apiQuery *org_pb.OrgQuery) (query.SearchQuery, error) {
switch q := apiQuery.Query.(type) {
case *org_pb.OrgQuery_DomainQuery:
return query.NewOrgDomainSearchQuery(object.TextMethodToQuery(q.DomainQuery.Method), q.DomainQuery.Domain)
return query.NewOrgVerifiedDomainSearchQuery(object.TextMethodToQuery(q.DomainQuery.Method), q.DomainQuery.Domain)
case *org_pb.OrgQuery_NameQuery:
return query.NewOrgNameSearchQuery(object.TextMethodToQuery(q.NameQuery.Method), q.NameQuery.Name)
case *org_pb.OrgQuery_StateQuery:

View File

@ -15,6 +15,7 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/zitadel/zitadel/internal/integration"
"github.com/zitadel/zitadel/pkg/grpc/management"
"github.com/zitadel/zitadel/pkg/grpc/object/v2"
"github.com/zitadel/zitadel/pkg/grpc/org/v2"
)
@ -214,6 +215,46 @@ func TestServer_ListOrganizations(t *testing.T) {
},
},
},
{
name: "list org by domain (non primary), ok",
args: args{
CTX,
&org.ListOrganizationsRequest{},
func(ctx context.Context, request *org.ListOrganizationsRequest) ([]orgAttr, error) {
orgs := make([]orgAttr, 1)
name := fmt.Sprintf("ListOrgs-%s", gofakeit.AppName())
orgResp := Instance.CreateOrganization(ctx, name, gofakeit.Email())
orgs[0] = orgAttr{
ID: orgResp.GetOrganizationId(),
Name: name,
Details: orgResp.GetDetails(),
}
domain := gofakeit.DomainName()
_, err := Instance.Client.Mgmt.AddOrgDomain(integration.SetOrgID(ctx, orgResp.GetOrganizationId()), &management.AddOrgDomainRequest{
Domain: domain,
})
if err != nil {
return nil, err
}
request.Queries = []*org.SearchQuery{
OrganizationDomainQuery(domain),
}
return orgs, nil
},
},
want: &org.ListOrganizationsResponse{
Details: &object.ListDetails{
TotalResult: 1,
Timestamp: timestamppb.Now(),
},
SortingColumn: 0,
Result: []*org.Organization{
{
State: org.OrganizationState_ORGANIZATION_STATE_ACTIVE,
},
},
},
},
{
name: "list org by inactive state, ok",
args: args{

View File

@ -57,7 +57,7 @@ func orgQueriesToQuery(ctx context.Context, queries []*org.SearchQuery) (_ []que
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)
return query.NewOrgVerifiedDomainSearchQuery(object.TextMethodToQuery(q.DomainQuery.Method), q.DomainQuery.Domain)
case *org.SearchQuery_NameQuery:
return query.NewOrgNameSearchQuery(object.TextMethodToQuery(q.NameQuery.Method), q.NameQuery.Name)
case *org.SearchQuery_StateQuery:

View File

@ -308,8 +308,24 @@ func NewOrgIDSearchQuery(value string) (SearchQuery, error) {
return NewTextQuery(OrgColumnID, value, TextEquals)
}
func NewOrgDomainSearchQuery(method TextComparison, value string) (SearchQuery, error) {
return NewTextQuery(OrgColumnDomain, value, method)
func NewOrgVerifiedDomainSearchQuery(method TextComparison, value string) (SearchQuery, error) {
domainQuery, err := NewTextQuery(OrgDomainDomainCol, value, method)
if err != nil {
return nil, err
}
verifiedQuery, err := NewBoolQuery(OrgDomainIsVerifiedCol, true)
if err != nil {
return nil, err
}
subSelect, err := NewSubSelect(OrgDomainOrgIDCol, []SearchQuery{domainQuery, verifiedQuery})
if err != nil {
return nil, err
}
return NewListQuery(
OrgColumnID,
subSelect,
ListIn,
)
}
func NewOrgNameSearchQuery(method TextComparison, value string) (SearchQuery, error) {