mirror of
https://github.com/zitadel/zitadel.git
synced 2025-07-13 21:58:30 +00:00

<!-- Please inform yourself about the contribution guidelines on submitting a PR here: https://github.com/zitadel/zitadel/blob/main/CONTRIBUTING.md#submit-a-pull-request-pr. Take note of how PR/commit titles should be written and replace the template texts in the sections below. Don't remove any of the sections. It is important that the commit history clearly shows what is changed and why. Important: By submitting a contribution you agree to the terms from our Licensing Policy as described here: https://github.com/zitadel/zitadel/blob/main/LICENSING.md#community-contributions. --> # Which Problems Are Solved 1. The sorting columns in the gRPC endpoint `ListInstanceTrustedDomains()` are incorrect, and return the following error when invalid sorting options are chosen: ``` Unknown (2) ERROR: missing FROM-clause entry for table "instance_domains" (SQLSTATE 42P01) ``` The sorting columns that are valid to list `instance_trusted_domains` are * `trusted_domain_field_name_unspecified` * `trusted_domain_field_name_domain` * `trusted_domain_field_name_creation_date` However, the currently configured sorting columns are * `domain_field_name_unspecified` * `domain_field_name_domain` * `domain_field_name_primary` * `domain_field_name_generated` * `domain_field_name_creation_date` Configuring the actual columns of `instance_trusted_domains` makes this endpoint **backward incompatible**. Therefore, the fix in this PR is to no longer return an error when an invalid sorting column (non-existing column) is chosen and to sort the results by `creation_date` for invalid sorting columns. 2. This PR also fixes the `sorting_column` included in the responses of both `ListInstanceTrustedDomains()` and `ListInstanceDomains()` endpoints, as they now point to the default option irrespective of the chosen option in the request i.e., * `TRUSTED_DOMAIN_FIELD_NAME_UNSPECIFIED` in case of `ListInstanceTrustedDomains()`, and * `DOMAIN_FIELD_NAME_UNSPECIFIED` in case of `ListInstanceDomains()` # How the Problems Are Solved * Map the sorting columns to valid columns of `instance_trusted_domain` - If the sorting column is not one of the columns, the mapping defaults to `creation_date` * Set the `sorting_column` explicitly (from the request) in the `ListInstanceDomainsResponse` and `ListInstanceTrustedDomainsResponse` # Additional Changes A small fix to return the chosen `sorting_column` in the responses of the `ListInstanceTrustedDomains()` and `ListInstanceDomains()` endpoints # Additional Context - Closes #9839
81 lines
2.5 KiB
Go
81 lines
2.5 KiB
Go
package admin
|
|
|
|
import (
|
|
"context"
|
|
|
|
instance_grpc "github.com/zitadel/zitadel/internal/api/grpc/instance"
|
|
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
|
admin_pb "github.com/zitadel/zitadel/pkg/grpc/admin"
|
|
)
|
|
|
|
func (s *Server) GetMyInstance(ctx context.Context, _ *admin_pb.GetMyInstanceRequest) (*admin_pb.GetMyInstanceResponse, error) {
|
|
instance, err := s.query.Instance(ctx, true)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &admin_pb.GetMyInstanceResponse{
|
|
Instance: instance_grpc.InstanceDetailToPb(instance),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ListInstanceDomains(ctx context.Context, req *admin_pb.ListInstanceDomainsRequest) (*admin_pb.ListInstanceDomainsResponse, error) {
|
|
queries, err := ListInstanceDomainsRequestToModel(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
domains, err := s.query.SearchInstanceDomains(ctx, queries)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &admin_pb.ListInstanceDomainsResponse{
|
|
Result: instance_grpc.DomainsToPb(domains.Domains),
|
|
SortingColumn: req.SortingColumn,
|
|
Details: object.ToListDetails(
|
|
domains.Count,
|
|
domains.Sequence,
|
|
domains.LastRun,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) ListInstanceTrustedDomains(ctx context.Context, req *admin_pb.ListInstanceTrustedDomainsRequest) (*admin_pb.ListInstanceTrustedDomainsResponse, error) {
|
|
queries, err := ListInstanceTrustedDomainsRequestToModel(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
domains, err := s.query.SearchInstanceTrustedDomains(ctx, queries)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &admin_pb.ListInstanceTrustedDomainsResponse{
|
|
Result: instance_grpc.TrustedDomainsToPb(domains.Domains),
|
|
SortingColumn: req.SortingColumn,
|
|
Details: object.ToListDetails(
|
|
domains.Count,
|
|
domains.Sequence,
|
|
domains.LastRun,
|
|
),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) AddInstanceTrustedDomain(ctx context.Context, req *admin_pb.AddInstanceTrustedDomainRequest) (*admin_pb.AddInstanceTrustedDomainResponse, error) {
|
|
details, err := s.command.AddTrustedDomain(ctx, req.Domain)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &admin_pb.AddInstanceTrustedDomainResponse{
|
|
Details: object.DomainToAddDetailsPb(details),
|
|
}, nil
|
|
}
|
|
|
|
func (s *Server) RemoveInstanceTrustedDomain(ctx context.Context, req *admin_pb.RemoveInstanceTrustedDomainRequest) (*admin_pb.RemoveInstanceTrustedDomainResponse, error) {
|
|
details, err := s.command.RemoveTrustedDomain(ctx, req.Domain)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &admin_pb.RemoveInstanceTrustedDomainResponse{
|
|
Details: object.DomainToChangeDetailsPb(details),
|
|
}, nil
|
|
}
|