diff --git a/internal/command/unique_constraints_model.go b/internal/command/unique_constraints_model.go index 196963611b..9fa3933458 100644 --- a/internal/command/unique_constraints_model.go +++ b/internal/command/unique_constraints_model.go @@ -200,6 +200,8 @@ func (rm *UniqueConstraintReadModel) Query() *eventstore.SearchQueryBuilder { project.GrantMemberRemovedType, project.RoleAddedType, project.RoleRemovedType, + user.UserV1AddedType, + user.UserV1RegisteredType, user.HumanAddedType, user.HumanRegisteredType, user.MachineAddedEventType, diff --git a/internal/command/user_grant_model.go b/internal/command/user_grant_model.go index 0e9e0d2c0d..160c48334b 100644 --- a/internal/command/user_grant_model.go +++ b/internal/command/user_grant_model.go @@ -151,7 +151,9 @@ func (wm *UserGrantPreConditionReadModel) Reduce() error { func (wm *UserGrantPreConditionReadModel) Query() *eventstore.SearchQueryBuilder { query := eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, user.AggregateType, project.AggregateType). AggregateIDs(wm.UserID, wm.ProjectID). - EventTypes(user.HumanAddedType, + EventTypes(user.UserV1AddedType, + user.HumanAddedType, + user.UserV1RegisteredType, user.HumanRegisteredType, user.MachineAddedEventType, user.UserRemovedType, diff --git a/internal/command/user_human_address_model.go b/internal/command/user_human_address_model.go index 14341e656d..dca7e6607e 100644 --- a/internal/command/user_human_address_model.go +++ b/internal/command/user_human_address_model.go @@ -73,7 +73,10 @@ func (wm *HumanAddressWriteModel) Query() *eventstore.SearchQueryBuilder { return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, user.AggregateType). AggregateIDs(wm.AggregateID). ResourceOwner(wm.ResourceOwner). - EventTypes(user.HumanAddedType, + EventTypes(user.UserV1AddedType, + user.UserV1RegisteredType, + user.UserV1AddressChangedType, + user.HumanAddedType, user.HumanRegisteredType, user.HumanAddressChangedType, user.UserRemovedType) diff --git a/internal/command/user_human_email_model.go b/internal/command/user_human_email_model.go index f39816d6d3..ce4dffc8fc 100644 --- a/internal/command/user_human_email_model.go +++ b/internal/command/user_human_email_model.go @@ -2,9 +2,10 @@ package command import ( "context" - "github.com/caos/zitadel/internal/eventstore" "time" + "github.com/caos/zitadel/internal/eventstore" + "github.com/caos/zitadel/internal/crypto" "github.com/caos/zitadel/internal/domain" "github.com/caos/zitadel/internal/repository/user" @@ -66,12 +67,19 @@ func (wm *HumanEmailWriteModel) Reduce() error { func (wm *HumanEmailWriteModel) Query() *eventstore.SearchQueryBuilder { query := eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, user.AggregateType). AggregateIDs(wm.AggregateID). - EventTypes(user.HumanAddedType, + EventTypes(user.UserV1AddedType, + user.HumanAddedType, + user.UserV1RegisteredType, user.HumanRegisteredType, + user.UserV1InitialCodeAddedType, user.HumanInitialCodeAddedType, + user.UserV1InitializedCheckSucceededType, user.HumanInitializedCheckSucceededType, + user.UserV1EmailChangedType, user.HumanEmailChangedType, + user.UserV1EmailCodeAddedType, user.HumanEmailCodeAddedType, + user.UserV1EmailVerifiedType, user.HumanEmailVerifiedType, user.UserRemovedType) if wm.ResourceOwner != "" { diff --git a/internal/command/user_human_init_model.go b/internal/command/user_human_init_model.go index b8fe2389c0..b37d202eae 100644 --- a/internal/command/user_human_init_model.go +++ b/internal/command/user_human_init_model.go @@ -68,11 +68,17 @@ func (wm *HumanInitCodeWriteModel) Reduce() error { func (wm *HumanInitCodeWriteModel) Query() *eventstore.SearchQueryBuilder { query := eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent, user.AggregateType). AggregateIDs(wm.AggregateID). - EventTypes(user.HumanAddedType, + EventTypes(user.UserV1AddedType, + user.HumanAddedType, + user.UserV1RegisteredType, user.HumanRegisteredType, + user.UserV1EmailChangedType, user.HumanEmailChangedType, + user.UserV1EmailVerifiedType, user.HumanEmailVerifiedType, + user.UserV1InitialCodeAddedType, user.HumanInitialCodeAddedType, + user.UserV1InitializedCheckSucceededType, user.HumanInitializedCheckSucceededType, user.UserRemovedType) if wm.ResourceOwner != "" { diff --git a/internal/command/user_human_model.go b/internal/command/user_human_model.go index a1d557243f..b1c7811ce2 100644 --- a/internal/command/user_human_model.go +++ b/internal/command/user_human_model.go @@ -70,6 +70,8 @@ func (wm *HumanWriteModel) Reduce() error { wm.reduceHumanPhoneChangedEvent(e) case *user.HumanPhoneVerifiedEvent: wm.reduceHumanPhoneVerifiedEvent() + case *user.HumanPhoneRemovedEvent: + wm.reduceHumanPhoneRemovedEvent() case *user.HumanPasswordChangedEvent: wm.reduceHumanPasswordChangedEvent(e) case *user.UserLockedEvent: @@ -109,12 +111,24 @@ func (wm *HumanWriteModel) Query() *eventstore.SearchQueryBuilder { user.HumanEmailVerifiedType, user.HumanPhoneChangedType, user.HumanPhoneVerifiedType, + user.HumanPhoneRemovedType, user.HumanPasswordChangedType, user.UserLockedType, user.UserUnlockedType, user.UserDeactivatedType, user.UserReactivatedType, - user.UserRemovedType) + user.UserRemovedType, + user.UserV1AddedType, + user.UserV1RegisteredType, + user.UserV1InitialCodeAddedType, + user.UserV1InitializedCheckSucceededType, + user.UserV1ProfileChangedType, + user.UserV1EmailChangedType, + user.UserV1EmailVerifiedType, + user.UserV1PhoneChangedType, + user.UserV1PhoneVerifiedType, + user.UserV1PhoneRemovedType, + user.UserV1PasswordChangedType) } func (wm *HumanWriteModel) reduceHumanAddedEvent(e *user.HumanAddedEvent) { @@ -196,6 +210,11 @@ func (wm *HumanWriteModel) reduceHumanPhoneVerifiedEvent() { wm.IsPhoneVerified = true } +func (wm *HumanWriteModel) reduceHumanPhoneRemovedEvent() { + wm.Phone = "" + wm.IsPhoneVerified = false +} + func (wm *HumanWriteModel) reduceHumanAddressChangedEvent(e *user.HumanAddressChangedEvent) { if e.Country != nil { wm.Country = *e.Country diff --git a/internal/command/user_human_otp_model.go b/internal/command/user_human_otp_model.go index a4b9924f87..70fbec6859 100644 --- a/internal/command/user_human_otp_model.go +++ b/internal/command/user_human_otp_model.go @@ -46,7 +46,10 @@ func (wm *HumanOTPWriteModel) Query() *eventstore.SearchQueryBuilder { EventTypes(user.HumanMFAOTPAddedType, user.HumanMFAOTPVerifiedType, user.HumanMFAOTPRemovedType, - user.UserRemovedType) + user.UserRemovedType, + user.UserV1MFAOTPAddedType, + user.UserV1MFAOTPVerifiedType, + user.UserV1MFAOTPRemovedType) if wm.ResourceOwner != "" { query.ResourceOwner(wm.ResourceOwner) } diff --git a/internal/command/user_human_password_model.go b/internal/command/user_human_password_model.go index 28261311a2..26d18347c0 100644 --- a/internal/command/user_human_password_model.go +++ b/internal/command/user_human_password_model.go @@ -75,7 +75,14 @@ func (wm *HumanPasswordWriteModel) Query() *eventstore.SearchQueryBuilder { user.HumanPasswordChangedType, user.HumanPasswordCodeAddedType, user.HumanEmailVerifiedType, - user.UserRemovedType) + user.UserRemovedType, + user.UserV1AddedType, + user.UserV1RegisteredType, + user.UserV1InitialCodeAddedType, + user.UserV1InitializedCheckSucceededType, + user.UserV1PasswordChangedType, + user.UserV1PasswordCodeAddedType, + user.UserV1EmailVerifiedType) if wm.ResourceOwner != "" { query.ResourceOwner(wm.ResourceOwner) } diff --git a/internal/command/user_human_phone_model.go b/internal/command/user_human_phone_model.go index 84d5d28af8..3757ca8bae 100644 --- a/internal/command/user_human_phone_model.go +++ b/internal/command/user_human_phone_model.go @@ -85,7 +85,15 @@ func (wm *HumanPhoneWriteModel) Query() *eventstore.SearchQueryBuilder { user.HumanPhoneVerifiedType, user.HumanPhoneCodeAddedType, user.HumanPhoneRemovedType, - user.UserRemovedType) + user.UserRemovedType, + user.UserV1AddedType, + user.UserV1RegisteredType, + user.UserV1InitialCodeAddedType, + user.UserV1InitializedCheckSucceededType, + user.UserV1PhoneCodeAddedType, + user.UserV1PhoneChangedType, + user.UserV1PhoneVerifiedType, + user.UserV1PhoneRemovedType) } func (wm *HumanPhoneWriteModel) NewChangedEvent( diff --git a/internal/command/user_human_profile_model.go b/internal/command/user_human_profile_model.go index 54c766f5fa..ab7896c165 100644 --- a/internal/command/user_human_profile_model.go +++ b/internal/command/user_human_profile_model.go @@ -84,7 +84,10 @@ func (wm *HumanProfileWriteModel) Query() *eventstore.SearchQueryBuilder { EventTypes(user.HumanAddedType, user.HumanRegisteredType, user.HumanProfileChangedType, - user.UserRemovedType) + user.UserRemovedType, + user.UserV1AddedType, + user.UserV1RegisteredType, + user.UserV1ProfileChangedType) } func (wm *HumanProfileWriteModel) NewChangedEvent( diff --git a/internal/command/user_model.go b/internal/command/user_model.go index 66be376765..7038d0d7b5 100644 --- a/internal/command/user_model.go +++ b/internal/command/user_model.go @@ -80,7 +80,10 @@ func (wm *UserWriteModel) Query() *eventstore.SearchQueryBuilder { user.UserUnlockedType, user.UserDeactivatedType, user.UserReactivatedType, - user.UserRemovedType) + user.UserRemovedType, + user.UserV1AddedType, + user.UserV1RegisteredType, + user.UserV1InitializedCheckSucceededType) if wm.ResourceOwner != "" { query.ResourceOwner(wm.ResourceOwner) } diff --git a/internal/repository/user/v1.go b/internal/repository/user/v1.go index 3fee14fd94..010e1a235d 100644 --- a/internal/repository/user/v1.go +++ b/internal/repository/user/v1.go @@ -1,15 +1,5 @@ package user -import ( - "context" - "github.com/caos/zitadel/internal/eventstore" - "time" - - "github.com/caos/zitadel/internal/crypto" - "github.com/caos/zitadel/internal/domain" - "golang.org/x/text/language" -) - const ( UserV1AddedType = userEventTypePrefix + "added" UserV1RegisteredType = userEventTypePrefix + "selfregistered" @@ -57,440 +47,3 @@ const ( UserV1MFAOTPCheckSucceededType = userV1MFAOTPEventTypePrefix + "check.succeeded" UserV1MFAOTPCheckFailedType = userV1MFAOTPEventTypePrefix + "check.failed" ) - -func NewUserV1AddedEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, - - userName, - firstName, - lastName, - nickName, - displayName string, - preferredLanguage language.Tag, - gender domain.Gender, - emailAddress, - phoneNumber, - country, - locality, - postalCode, - region, - streetAddress string, -) *HumanAddedEvent { - return &HumanAddedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1AddedType, - ), - UserName: userName, - FirstName: firstName, - LastName: lastName, - NickName: nickName, - DisplayName: displayName, - PreferredLanguage: preferredLanguage, - Gender: gender, - EmailAddress: emailAddress, - PhoneNumber: phoneNumber, - Country: country, - Locality: locality, - PostalCode: postalCode, - Region: region, - StreetAddress: streetAddress, - } -} - -func NewUserV1RegisteredEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, - - userName, - firstName, - lastName, - nickName, - displayName string, - preferredLanguage language.Tag, - gender domain.Gender, - emailAddress, - phoneNumber, - country, - locality, - postalCode, - region, - streetAddress string, -) *HumanRegisteredEvent { - return &HumanRegisteredEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1RegisteredType, - ), - UserName: userName, - FirstName: firstName, - LastName: lastName, - NickName: nickName, - DisplayName: displayName, - PreferredLanguage: preferredLanguage, - Gender: gender, - EmailAddress: emailAddress, - PhoneNumber: phoneNumber, - Country: country, - Locality: locality, - PostalCode: postalCode, - Region: region, - StreetAddress: streetAddress, - } -} - -func NewUserV1InitialCodeAddedEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, - code *crypto.CryptoValue, - expiry time.Duration, -) *HumanInitialCodeAddedEvent { - return &HumanInitialCodeAddedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1InitialCodeAddedType, - ), - Code: code, - Expiry: expiry, - } -} - -func NewUserV1InitialCodeSentEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanInitialCodeSentEvent { - return &HumanInitialCodeSentEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1InitialCodeSentType, - ), - } -} - -func NewUserV1InitializedCheckSucceededEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanInitializedCheckSucceededEvent { - return &HumanInitializedCheckSucceededEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1InitializedCheckSucceededType, - ), - } -} - -func NewUserV1InitializedCheckFailedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanInitializedCheckFailedEvent { - return &HumanInitializedCheckFailedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1InitializedCheckFailedType, - ), - } -} - -func NewUserV1SignedOutEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanSignedOutEvent { - return &HumanSignedOutEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1SignedOutType, - ), - } -} - -func NewUserV1PasswordChangedEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, - secret *crypto.CryptoValue, - changeRequired bool, -) *HumanPasswordChangedEvent { - return &HumanPasswordChangedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1PasswordChangedType, - ), - Secret: secret, - ChangeRequired: changeRequired, - } -} - -func NewUserV1PasswordCodeAddedEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, - code *crypto.CryptoValue, - expiry time.Duration, - notificationType domain.NotificationType, -) *HumanPasswordCodeAddedEvent { - return &HumanPasswordCodeAddedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1PasswordCodeAddedType, - ), - Code: code, - Expiry: expiry, - NotificationType: notificationType, - } -} - -func NewUserV1PasswordCodeSentEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPasswordCodeSentEvent { - return &HumanPasswordCodeSentEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1PasswordCodeSentType, - ), - } -} - -func NewUserV1PasswordCheckSucceededEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPasswordCheckSucceededEvent { - return &HumanPasswordCheckSucceededEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1PasswordCheckSucceededType, - ), - } -} - -func NewUserV1PasswordCheckFailedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPasswordCheckFailedEvent { - return &HumanPasswordCheckFailedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1PasswordCheckFailedType, - ), - } -} - -func NewUserV1EmailChangedEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, - emailAddress string, -) *HumanEmailChangedEvent { - return &HumanEmailChangedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1EmailChangedType, - ), - EmailAddress: emailAddress, - } -} - -func NewUserV1EmailVerifiedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanEmailVerifiedEvent { - return &HumanEmailVerifiedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1EmailVerifiedType, - ), - } -} - -func NewUserV1EmailVerificationFailedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanEmailVerificationFailedEvent { - return &HumanEmailVerificationFailedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1EmailVerificationFailedType, - ), - } -} - -func NewUserV1EmailCodeAddedEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, - code *crypto.CryptoValue, - expiry time.Duration, -) *HumanEmailCodeAddedEvent { - return &HumanEmailCodeAddedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1EmailCodeAddedType, - ), - Code: code, - Expiry: expiry, - } -} - -func NewUserV1EmailCodeSentEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanEmailCodeSentEvent { - return &HumanEmailCodeSentEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1EmailCodeSentType, - ), - } -} - -func NewUserV1PhoneChangedEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, - phone string, -) *HumanPhoneChangedEvent { - return &HumanPhoneChangedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1PhoneChangedType, - ), - PhoneNumber: phone, - } -} - -func NewUserV1PhoneRemovedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPhoneRemovedEvent { - return &HumanPhoneRemovedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1PhoneRemovedType, - ), - } -} - -func NewUserV1PhoneVerifiedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPhoneVerifiedEvent { - return &HumanPhoneVerifiedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1PhoneVerifiedType, - ), - } -} - -func NewUserV1PhoneVerificationFailedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPhoneVerificationFailedEvent { - return &HumanPhoneVerificationFailedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1PhoneVerificationFailedType, - ), - } -} - -func NewUserV1PhoneCodeAddedEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, - code *crypto.CryptoValue, - expiry time.Duration, -) *HumanPhoneCodeAddedEvent { - return &HumanPhoneCodeAddedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1PhoneCodeAddedType, - ), - Code: code, - Expiry: expiry, - } -} - -func NewUserV1PhoneCodeSentEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanPhoneCodeSentEvent { - return &HumanPhoneCodeSentEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1PhoneCodeSentType, - ), - } -} - -func NewUserV1ProfileChangedEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, -) *HumanProfileChangedEvent { - return &HumanProfileChangedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1ProfileChangedType, - ), - } -} - -func NewUserV1AddressChangedEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, - country, - locality, - postalCode, - region, - streetAddress string, -) *HumanAddressChangedEvent { - return &HumanAddressChangedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1AddressChangedType, - ), - } -} - -func NewUserV1MFAInitSkippedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanMFAInitSkippedEvent { - return &HumanMFAInitSkippedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1MFAInitSkippedType, - ), - } -} - -func NewUserV1MFAOTPAddedEvent( - ctx context.Context, - aggregate *eventstore.Aggregate, - secret *crypto.CryptoValue, -) *HumanOTPAddedEvent { - return &HumanOTPAddedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1MFAOTPAddedType, - ), - Secret: secret, - } -} - -func NewUserV1MFAOTPVerifiedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanOTPVerifiedEvent { - return &HumanOTPVerifiedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1MFAOTPVerifiedType, - ), - } -} - -func NewUserV1MFAOTPRemovedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanOTPRemovedEvent { - return &HumanOTPRemovedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1MFAOTPRemovedType, - ), - } -} - -func NewUserV1MFAOTPCheckSucceededEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanOTPCheckSucceededEvent { - return &HumanOTPCheckSucceededEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1MFAOTPCheckSucceededType, - ), - } -} - -func NewUserV1MFAOTPCheckFailedEvent(ctx context.Context, aggregate *eventstore.Aggregate) *HumanOTPCheckFailedEvent { - return &HumanOTPCheckFailedEvent{ - BaseEvent: *eventstore.NewBaseEventForPush( - ctx, - aggregate, - UserV1MFAOTPCheckFailedType, - ), - } -}