mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-16 02:35:12 +00:00
fix: refactor system api (#3500)
* fix: refactor system api * fix: search domains on get instance * fix: search domains on get instance * fix: return instance detail * fix: implement user sorting column (#3469) * fix: implement user sorting column * fix: implement user sorting column * fix: string column * isOrderByLower Co-authored-by: Livio Amstutz <[email protected]> * fix: user converter import * Update instance.go Co-authored-by: Livio Amstutz <[email protected]>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
instance_grpc "github.com/zitadel/zitadel/internal/api/grpc/instance"
|
||||
"github.com/zitadel/zitadel/internal/api/grpc/object"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
object_pb "github.com/zitadel/zitadel/pkg/grpc/object"
|
||||
system_pb "github.com/zitadel/zitadel/pkg/grpc/system"
|
||||
)
|
||||
@@ -29,13 +30,13 @@ func (s *Server) ListInstances(ctx context.Context, req *system_pb.ListInstances
|
||||
}
|
||||
|
||||
func (s *Server) GetInstance(ctx context.Context, req *system_pb.GetInstanceRequest) (*system_pb.GetInstanceResponse, error) {
|
||||
ctx = authz.WithInstanceID(ctx, req.Id)
|
||||
ctx = authz.WithInstanceID(ctx, req.InstanceId)
|
||||
instance, err := s.query.Instance(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &system_pb.GetInstanceResponse{
|
||||
Instance: instance_grpc.InstanceToPb(instance),
|
||||
Instance: instance_grpc.InstanceDetailToPb(instance),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ func (s *Server) AddInstance(ctx context.Context, req *system_pb.AddInstanceRequ
|
||||
return nil, err
|
||||
}
|
||||
return &system_pb.AddInstanceResponse{
|
||||
Id: id,
|
||||
InstanceId: id,
|
||||
Details: object.AddToDetailsPb(
|
||||
details.Sequence,
|
||||
details.EventDate,
|
||||
@@ -55,8 +56,30 @@ func (s *Server) AddInstance(ctx context.Context, req *system_pb.AddInstanceRequ
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) ExistsDomain(ctx context.Context, req *system_pb.ExistsDomainRequest) (*system_pb.ExistsDomainResponse, error) {
|
||||
domainQuery, err := query.NewInstanceDomainDomainSearchQuery(query.TextEqualsIgnoreCase, req.Domain)
|
||||
|
||||
query := &query.InstanceDomainSearchQueries{
|
||||
SearchRequest: query.SearchRequest{
|
||||
Offset: 0,
|
||||
Limit: 1,
|
||||
Asc: true,
|
||||
},
|
||||
Queries: []query.SearchQuery{
|
||||
domainQuery,
|
||||
},
|
||||
}
|
||||
domains, err := s.query.SearchInstanceDomains(ctx, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &system_pb.ExistsDomainResponse{
|
||||
Exists: domains.Count > 0,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) ListDomains(ctx context.Context, req *system_pb.ListDomainsRequest) (*system_pb.ListDomainsResponse, error) {
|
||||
ctx = authz.WithInstanceID(ctx, req.Id)
|
||||
ctx = authz.WithInstanceID(ctx, req.InstanceId)
|
||||
queries, err := ListInstanceDomainsRequestToModel(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -77,7 +100,7 @@ func (s *Server) ListDomains(ctx context.Context, req *system_pb.ListDomainsRequ
|
||||
}
|
||||
|
||||
func (s *Server) AddDomain(ctx context.Context, req *system_pb.AddDomainRequest) (*system_pb.AddDomainResponse, error) {
|
||||
ctx = authz.WithInstanceID(ctx, req.Id)
|
||||
ctx = authz.WithInstanceID(ctx, req.InstanceId)
|
||||
instance, err := s.query.Instance(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -97,7 +120,7 @@ func (s *Server) AddDomain(ctx context.Context, req *system_pb.AddDomainRequest)
|
||||
}
|
||||
|
||||
func (s *Server) RemoveDomain(ctx context.Context, req *system_pb.RemoveDomainRequest) (*system_pb.RemoveDomainResponse, error) {
|
||||
ctx = authz.WithInstanceID(ctx, req.Id)
|
||||
ctx = authz.WithInstanceID(ctx, req.InstanceId)
|
||||
details, err := s.command.RemoveInstanceDomain(ctx, req.Domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -112,7 +135,7 @@ func (s *Server) RemoveDomain(ctx context.Context, req *system_pb.RemoveDomainRe
|
||||
}
|
||||
|
||||
func (s *Server) SetPrimaryDomain(ctx context.Context, req *system_pb.SetPrimaryDomainRequest) (*system_pb.SetPrimaryDomainResponse, error) {
|
||||
ctx = authz.WithInstanceID(ctx, req.Id)
|
||||
ctx = authz.WithInstanceID(ctx, req.InstanceId)
|
||||
details, err := s.command.SetPrimaryInstanceDomain(ctx, req.Domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
instance_pb "github.com/zitadel/zitadel/pkg/grpc/instance"
|
||||
system_pb "github.com/zitadel/zitadel/pkg/grpc/system"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
func AddInstancePbToSetupInstance(req *system_pb.AddInstanceRequest, defaultInstance command.InstanceSetup) *command.InstanceSetup {
|
||||
@@ -20,18 +21,32 @@ func AddInstancePbToSetupInstance(req *system_pb.AddInstanceRequest, defaultInst
|
||||
if req.FirstOrgName != "" {
|
||||
defaultInstance.Org.Name = req.FirstOrgName
|
||||
}
|
||||
if req.OwnerEmail != "" {
|
||||
defaultInstance.Org.Human.Email.Address = req.OwnerEmail
|
||||
if req.OwnerEmail.Email != "" {
|
||||
defaultInstance.Org.Human.Email.Address = req.OwnerEmail.Email
|
||||
defaultInstance.Org.Human.Email.Verified = req.OwnerEmail.IsEmailVerified
|
||||
}
|
||||
if req.OwnerUsername != "" {
|
||||
defaultInstance.Org.Human.Username = req.OwnerUsername
|
||||
if req.OwnerProfile != nil {
|
||||
if req.OwnerProfile.FirstName != "" {
|
||||
defaultInstance.Org.Human.FirstName = req.OwnerProfile.FirstName
|
||||
}
|
||||
if req.OwnerProfile.LastName != "" {
|
||||
defaultInstance.Org.Human.LastName = req.OwnerProfile.LastName
|
||||
}
|
||||
if req.OwnerProfile.PreferredLanguage != "" {
|
||||
lang, err := language.Parse(req.OwnerProfile.PreferredLanguage)
|
||||
if err == nil {
|
||||
defaultInstance.Org.Human.PreferredLang = lang
|
||||
}
|
||||
}
|
||||
}
|
||||
if req.OwnerFirstName != "" {
|
||||
defaultInstance.Org.Human.FirstName = req.OwnerFirstName
|
||||
if req.OwnerUserName != "" {
|
||||
defaultInstance.Org.Human.Username = req.OwnerUserName
|
||||
}
|
||||
if req.OwnerLastName != "" {
|
||||
defaultInstance.Org.Human.LastName = req.OwnerLastName
|
||||
if req.OwnerPassword != nil {
|
||||
defaultInstance.Org.Human.Password = req.OwnerPassword.Password
|
||||
defaultInstance.Org.Human.PasswordChangeRequired = req.OwnerPassword.PasswordChangeRequired
|
||||
}
|
||||
|
||||
return &defaultInstance
|
||||
}
|
||||
func ListInstancesRequestToModel(req *system_pb.ListInstancesRequest) (*query.InstanceSearchQueries, error) {
|
||||
|
||||
Reference in New Issue
Block a user