mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:27:42 +00:00
fix(import/export): fix for deactivated user/organization being imported as active (#9992)
This commit is contained in:
@@ -8,7 +8,9 @@ import (
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
authn_grpc "github.com/zitadel/zitadel/internal/api/grpc/authn"
|
||||
"github.com/zitadel/zitadel/internal/api/grpc/org"
|
||||
text_grpc "github.com/zitadel/zitadel/internal/api/grpc/text"
|
||||
user_converter "github.com/zitadel/zitadel/internal/api/grpc/user"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||
@@ -65,7 +67,7 @@ func (s *Server) ExportData(ctx context.Context, req *admin_pb.ExportDataRequest
|
||||
/******************************************************************************************************************
|
||||
Organization
|
||||
******************************************************************************************************************/
|
||||
org := &admin_pb.DataOrg{OrgId: queriedOrg.ID, Org: &management_pb.AddOrgRequest{Name: queriedOrg.Name}}
|
||||
org := &admin_pb.DataOrg{OrgId: queriedOrg.ID, OrgState: org.OrgStateToPb(queriedOrg.State), Org: &management_pb.AddOrgRequest{Name: queriedOrg.Name}}
|
||||
orgs[i] = org
|
||||
}
|
||||
|
||||
@@ -567,6 +569,7 @@ func (s *Server) getUsers(ctx context.Context, org string, withPasswords bool, w
|
||||
case domain.UserTypeHuman:
|
||||
dataUser := &v1_pb.DataHumanUser{
|
||||
UserId: user.ID,
|
||||
State: user_converter.UserStateToPb(user.State),
|
||||
User: &management_pb.ImportHumanUserRequest{
|
||||
UserName: user.Username,
|
||||
Profile: &management_pb.ImportHumanUserRequest_Profile{
|
||||
@@ -620,6 +623,7 @@ func (s *Server) getUsers(ctx context.Context, org string, withPasswords bool, w
|
||||
case domain.UserTypeMachine:
|
||||
machineUsers = append(machineUsers, &v1_pb.DataMachineUser{
|
||||
UserId: user.ID,
|
||||
State: user_converter.UserStateToPb(user.State),
|
||||
User: &management_pb.AddMachineUserRequest{
|
||||
UserName: user.Username,
|
||||
Name: user.Machine.Name,
|
||||
@@ -647,7 +651,6 @@ func (s *Server) getUsers(ctx context.Context, org string, withPasswords bool, w
|
||||
ExpirationDate: timestamppb.New(key.Expiration),
|
||||
PublicKey: key.PublicKey,
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -888,7 +891,6 @@ func (s *Server) getNecessaryProjectGrantMembersForOrg(ctx context.Context, org
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -940,7 +942,6 @@ func (s *Server) getNecessaryOrgMembersForOrg(ctx context.Context, org string, p
|
||||
}
|
||||
|
||||
func (s *Server) getNecessaryProjectGrantsForOrg(ctx context.Context, org string, processedOrgs []string, processedProjects []string) ([]*v1_pb.DataProjectGrant, error) {
|
||||
|
||||
projectGrantSearchOrg, err := query.NewProjectGrantResourceOwnerSearchQuery(org)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -991,7 +992,7 @@ func (s *Server) getNecessaryUserGrantsForOrg(ctx context.Context, org string, p
|
||||
for _, userGrant := range queriedUserGrants.UserGrants {
|
||||
for _, projectID := range processedProjects {
|
||||
if projectID == userGrant.ProjectID {
|
||||
//if usergrant is on a granted project
|
||||
// if usergrant is on a granted project
|
||||
if userGrant.GrantID != "" {
|
||||
for _, grantID := range processedGrants {
|
||||
if grantID == userGrant.GrantID {
|
||||
@@ -1024,6 +1025,7 @@ func (s *Server) getNecessaryUserGrantsForOrg(ctx context.Context, org string, p
|
||||
}
|
||||
return userGrants, nil
|
||||
}
|
||||
|
||||
func (s *Server) getCustomLoginTexts(ctx context.Context, org string, languages []string) ([]*management_pb.SetCustomLoginTextsRequest, error) {
|
||||
customTexts := make([]*management_pb.SetCustomLoginTextsRequest, 0, len(languages))
|
||||
for _, lang := range languages {
|
||||
|
@@ -22,6 +22,7 @@ import (
|
||||
action_grpc "github.com/zitadel/zitadel/internal/api/grpc/action"
|
||||
"github.com/zitadel/zitadel/internal/api/grpc/authn"
|
||||
"github.com/zitadel/zitadel/internal/api/grpc/management"
|
||||
org_converter "github.com/zitadel/zitadel/internal/api/grpc/org"
|
||||
"github.com/zitadel/zitadel/internal/command"
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
@@ -305,7 +306,8 @@ func importOrg1(ctx context.Context, s *Server, errors *[]*admin_pb.ImportDataEr
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
|
||||
_, err = s.command.AddOrgWithID(ctx, org.GetOrg().GetName(), ctxData.UserID, ctxData.ResourceOwner, org.GetOrgId(), []string{})
|
||||
setOrgInactive := org_converter.OrgStateToDomain(org.OrgState) == domain.OrgStateInactive
|
||||
_, err = s.command.AddOrgWithID(ctx, org.GetOrg().GetName(), ctxData.UserID, ctxData.ResourceOwner, org.GetOrgId(), setOrgInactive, []string{})
|
||||
if err != nil {
|
||||
*errors = append(*errors, &admin_pb.ImportDataError{Type: "org", Id: org.GetOrgId(), Message: err.Error()})
|
||||
if _, err := s.query.OrgByID(ctx, true, org.OrgId); err != nil {
|
||||
@@ -474,7 +476,10 @@ func importHumanUsers(ctx context.Context, s *Server, errors *[]*admin_pb.Import
|
||||
logging.Debugf("import user: %s", user.GetUserId())
|
||||
human, passwordless, links := management.ImportHumanUserRequestToDomain(user.User)
|
||||
human.AggregateID = user.UserId
|
||||
_, _, err := s.command.ImportHuman(ctx, org.GetOrgId(), human, passwordless, links, initCodeGenerator, emailCodeGenerator, phoneCodeGenerator, passwordlessInitCode)
|
||||
userState := user.State.ToDomain()
|
||||
|
||||
//nolint:staticcheck
|
||||
_, _, err := s.command.ImportHuman(ctx, org.GetOrgId(), human, passwordless, &userState, links, initCodeGenerator, emailCodeGenerator, phoneCodeGenerator, passwordlessInitCode)
|
||||
if err != nil {
|
||||
*errors = append(*errors, &admin_pb.ImportDataError{Type: "human_user", Id: user.GetUserId(), Message: err.Error()})
|
||||
if isCtxTimeout(ctx) {
|
||||
@@ -510,7 +515,8 @@ func importMachineUsers(ctx context.Context, s *Server, errors *[]*admin_pb.Impo
|
||||
}
|
||||
for _, user := range org.GetMachineUsers() {
|
||||
logging.Debugf("import user: %s", user.GetUserId())
|
||||
_, err := s.command.AddMachine(ctx, management.AddMachineUserRequestToCommand(user.GetUser(), org.GetOrgId()), nil)
|
||||
userState := user.State.ToDomain()
|
||||
_, err := s.command.AddMachine(ctx, management.AddMachineUserRequestToCommand(user.GetUser(), org.GetOrgId()), &userState, nil)
|
||||
if err != nil {
|
||||
*errors = append(*errors, &admin_pb.ImportDataError{Type: "machine_user", Id: user.GetUserId(), Message: err.Error()})
|
||||
if isCtxTimeout(ctx) {
|
||||
@@ -609,7 +615,6 @@ func importUserLinks(ctx context.Context, s *Server, errors *[]*admin_pb.ImportD
|
||||
successOrg.UserLinks = append(successOrg.UserLinks, &admin_pb.ImportDataSuccessUserLinks{UserId: userLinks.GetUserId(), IdpId: userLinks.GetIdpId(), ExternalUserId: userLinks.GetProvidedUserId(), DisplayName: userLinks.GetProvidedUserName()})
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func importProjects(ctx context.Context, s *Server, errors *[]*admin_pb.ImportDataError, successOrg *admin_pb.ImportDataSuccessOrg, org *admin_pb.DataOrg, count *counts) (err error) {
|
||||
@@ -750,6 +755,7 @@ func importActions(ctx context.Context, s *Server, errors *[]*admin_pb.ImportDat
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func importProjectRoles(ctx context.Context, s *Server, errors *[]*admin_pb.ImportDataError, successOrg *admin_pb.ImportDataSuccessOrg, org *admin_pb.DataOrg, count *counts) (err error) {
|
||||
ctx, span := tracing.NewSpan(ctx)
|
||||
defer func() { span.EndWithError(err) }()
|
||||
@@ -805,6 +811,7 @@ func importResources(ctx context.Context, s *Server, errors *[]*admin_pb.ImportD
|
||||
importDomainClaimedMessageTexts(ctx, s, errors, org)
|
||||
importPasswordlessRegistrationMessageTexts(ctx, s, errors, org)
|
||||
importInviteUserMessageTexts(ctx, s, errors, org)
|
||||
|
||||
if err := importHumanUsers(ctx, s, errors, successOrg, org, count, initCodeGenerator, emailCodeGenerator, phoneCodeGenerator, passwordlessInitCode); err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user