mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:47:33 +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 <livio.a@gmail.com> * fix: user converter import * Update instance.go Co-authored-by: Livio Amstutz <livio.a@gmail.com>
This commit is contained in:
@@ -23,7 +23,22 @@ func InstanceToPb(instance *query.Instance) *instance_pb.Instance {
|
||||
instance.ChangeDate,
|
||||
instance.InstanceID(),
|
||||
),
|
||||
Id: instance.InstanceID(),
|
||||
Id: instance.InstanceID(),
|
||||
Name: instance.Name,
|
||||
}
|
||||
}
|
||||
|
||||
func InstanceDetailToPb(instance *query.Instance) *instance_pb.InstanceDetail {
|
||||
return &instance_pb.InstanceDetail{
|
||||
Details: object.ToViewDetailsPb(
|
||||
instance.Sequence,
|
||||
instance.CreationDate,
|
||||
instance.ChangeDate,
|
||||
instance.InstanceID(),
|
||||
),
|
||||
Id: instance.InstanceID(),
|
||||
Name: instance.Name,
|
||||
Domains: DomainsToPb(instance.Domains),
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
"github.com/zitadel/zitadel/pkg/grpc/user"
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
@@ -27,14 +28,38 @@ func ListUsersRequestToModel(req *mgmt_pb.ListUsersRequest) (*query.UserSearchQu
|
||||
}
|
||||
return &query.UserSearchQueries{
|
||||
SearchRequest: query.SearchRequest{
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
Asc: asc,
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
Asc: asc,
|
||||
SortingColumn: UserFieldNameToSortingColumn(req.SortingColumn),
|
||||
},
|
||||
Queries: queries,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func UserFieldNameToSortingColumn(field user.UserFieldName) query.Column {
|
||||
switch field {
|
||||
case user.UserFieldName_USER_FIELD_NAME_EMAIL:
|
||||
return query.HumanEmailCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_FIRST_NAME:
|
||||
return query.HumanFirstNameCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_LAST_NAME:
|
||||
return query.HumanLastNameCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_DISPLAY_NAME:
|
||||
return query.HumanDisplayNameCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_USER_NAME:
|
||||
return query.UserUsernameCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_STATE:
|
||||
return query.UserStateCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_TYPE:
|
||||
return query.UserTypeCol
|
||||
case user.UserFieldName_USER_FIELD_NAME_NICK_NAME:
|
||||
return query.HumanNickNameCol
|
||||
default:
|
||||
return query.UserIDCol
|
||||
}
|
||||
}
|
||||
|
||||
func BulkSetMetadataToDomain(req *mgmt_pb.BulkSetUserMetadataRequest) []*domain.Metadata {
|
||||
metadata := make([]*domain.Metadata, len(req.Metadata))
|
||||
for i, data := range req.Metadata {
|
||||
|
@@ -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