mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-19 19:48:45 +00:00
fix: change to repository event types and removed unused code (#3386)
* fix: change to repository event types and removed unused code * some fixes * remove unused code
This commit is contained in:
@@ -8,22 +8,22 @@ import (
|
||||
|
||||
"github.com/caos/logging"
|
||||
|
||||
"github.com/caos/zitadel/internal/notification/channels/fs"
|
||||
"github.com/caos/zitadel/internal/notification/channels/log"
|
||||
"github.com/caos/zitadel/internal/notification/channels/twilio"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/command"
|
||||
sd "github.com/caos/zitadel/internal/config/systemdefaults"
|
||||
"github.com/caos/zitadel/internal/crypto"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore"
|
||||
v1 "github.com/caos/zitadel/internal/eventstore/v1"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
queryv1 "github.com/caos/zitadel/internal/eventstore/v1/query"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/spooler"
|
||||
"github.com/caos/zitadel/internal/i18n"
|
||||
"github.com/caos/zitadel/internal/notification/channels/fs"
|
||||
"github.com/caos/zitadel/internal/notification/channels/log"
|
||||
"github.com/caos/zitadel/internal/notification/channels/smtp"
|
||||
"github.com/caos/zitadel/internal/notification/channels/twilio"
|
||||
"github.com/caos/zitadel/internal/notification/types"
|
||||
"github.com/caos/zitadel/internal/query"
|
||||
user_repo "github.com/caos/zitadel/internal/repository/user"
|
||||
@@ -96,7 +96,7 @@ func (n *Notification) Subscription() *v1.Subscription {
|
||||
}
|
||||
|
||||
func (_ *Notification) AggregateTypes() []models.AggregateType {
|
||||
return []models.AggregateType{es_model.UserAggregate}
|
||||
return []models.AggregateType{user_repo.AggregateType}
|
||||
}
|
||||
|
||||
func (n *Notification) CurrentSequence() (uint64, error) {
|
||||
@@ -116,22 +116,22 @@ func (n *Notification) EventQuery() (*models.SearchQuery, error) {
|
||||
}
|
||||
|
||||
func (n *Notification) Reduce(event *models.Event) (err error) {
|
||||
switch event.Type {
|
||||
case es_model.InitializedUserCodeAdded,
|
||||
es_model.InitializedHumanCodeAdded:
|
||||
switch eventstore.EventType(event.Type) {
|
||||
case user_repo.UserV1InitialCodeAddedType,
|
||||
user_repo.HumanInitialCodeAddedType:
|
||||
err = n.handleInitUserCode(event)
|
||||
case es_model.UserEmailCodeAdded,
|
||||
es_model.HumanEmailCodeAdded:
|
||||
case user_repo.UserV1EmailCodeAddedType,
|
||||
user_repo.HumanEmailCodeAddedType:
|
||||
err = n.handleEmailVerificationCode(event)
|
||||
case es_model.UserPhoneCodeAdded,
|
||||
es_model.HumanPhoneCodeAdded:
|
||||
case user_repo.UserV1PhoneCodeAddedType,
|
||||
user_repo.HumanPhoneCodeAddedType:
|
||||
err = n.handlePhoneVerificationCode(event)
|
||||
case es_model.UserPasswordCodeAdded,
|
||||
es_model.HumanPasswordCodeAdded:
|
||||
case user_repo.UserV1PasswordCodeAddedType,
|
||||
user_repo.HumanPasswordCodeAddedType:
|
||||
err = n.handlePasswordCode(event)
|
||||
case es_model.DomainClaimed:
|
||||
case user_repo.UserDomainClaimedType:
|
||||
err = n.handleDomainClaimed(event)
|
||||
case models.EventType(user_repo.HumanPasswordlessInitCodeRequestedType):
|
||||
case user_repo.HumanPasswordlessInitCodeRequestedType:
|
||||
err = n.handlePasswordlessRegistrationLink(event)
|
||||
}
|
||||
if err != nil {
|
||||
@@ -146,8 +146,8 @@ func (n *Notification) handleInitUserCode(event *models.Event) (err error) {
|
||||
return err
|
||||
}
|
||||
alreadyHandled, err := n.checkIfCodeAlreadyHandledOrExpired(event, initCode.Expiry,
|
||||
es_model.InitializedUserCodeAdded, es_model.InitializedUserCodeSent,
|
||||
es_model.InitializedHumanCodeAdded, es_model.InitializedHumanCodeSent)
|
||||
user_repo.UserV1InitialCodeAddedType, user_repo.UserV1InitialCodeSentType,
|
||||
user_repo.HumanInitialCodeAddedType, user_repo.HumanInitialCodeSentType)
|
||||
if err != nil || alreadyHandled {
|
||||
return err
|
||||
}
|
||||
@@ -185,8 +185,8 @@ func (n *Notification) handlePasswordCode(event *models.Event) (err error) {
|
||||
return err
|
||||
}
|
||||
alreadyHandled, err := n.checkIfCodeAlreadyHandledOrExpired(event, pwCode.Expiry,
|
||||
es_model.UserPasswordCodeAdded, es_model.UserPasswordCodeSent,
|
||||
es_model.HumanPasswordCodeAdded, es_model.HumanPasswordCodeSent)
|
||||
user_repo.UserV1PasswordCodeAddedType, user_repo.UserV1PasswordCodeSentType,
|
||||
user_repo.HumanPasswordCodeAddedType, user_repo.HumanPasswordCodeSentType)
|
||||
if err != nil || alreadyHandled {
|
||||
return err
|
||||
}
|
||||
@@ -223,8 +223,8 @@ func (n *Notification) handleEmailVerificationCode(event *models.Event) (err err
|
||||
return err
|
||||
}
|
||||
alreadyHandled, err := n.checkIfCodeAlreadyHandledOrExpired(event, emailCode.Expiry,
|
||||
es_model.UserEmailCodeAdded, es_model.UserEmailCodeSent,
|
||||
es_model.HumanEmailCodeAdded, es_model.HumanEmailCodeSent)
|
||||
user_repo.UserV1EmailCodeAddedType, user_repo.UserV1EmailCodeSentType,
|
||||
user_repo.HumanEmailCodeAddedType, user_repo.HumanEmailCodeSentType)
|
||||
if err != nil || alreadyHandled {
|
||||
return nil
|
||||
}
|
||||
@@ -262,8 +262,8 @@ func (n *Notification) handlePhoneVerificationCode(event *models.Event) (err err
|
||||
return err
|
||||
}
|
||||
alreadyHandled, err := n.checkIfCodeAlreadyHandledOrExpired(event, phoneCode.Expiry,
|
||||
es_model.UserPhoneCodeAdded, es_model.UserPhoneCodeSent,
|
||||
es_model.HumanPhoneCodeAdded, es_model.HumanPhoneCodeSent)
|
||||
user_repo.UserV1PhoneCodeAddedType, user_repo.UserV1PhoneCodeSentType,
|
||||
user_repo.HumanPhoneCodeAddedType, user_repo.HumanPhoneCodeSentType)
|
||||
if err != nil || alreadyHandled {
|
||||
return nil
|
||||
}
|
||||
@@ -283,7 +283,7 @@ func (n *Notification) handlePhoneVerificationCode(event *models.Event) (err err
|
||||
}
|
||||
|
||||
func (n *Notification) handleDomainClaimed(event *models.Event) (err error) {
|
||||
alreadyHandled, err := n.checkIfAlreadyHandled(event.AggregateID, event.Sequence, es_model.DomainClaimed, es_model.DomainClaimedSent)
|
||||
alreadyHandled, err := n.checkIfAlreadyHandled(event.AggregateID, event.Sequence, user_repo.UserDomainClaimedType, user_repo.UserDomainClaimedSentType)
|
||||
if err != nil || alreadyHandled {
|
||||
return nil
|
||||
}
|
||||
@@ -332,7 +332,7 @@ func (n *Notification) handlePasswordlessRegistrationLink(event *models.Event) (
|
||||
return err
|
||||
}
|
||||
for _, e := range events {
|
||||
if e.Type == models.EventType(user_repo.HumanPasswordlessInitCodeSentType) {
|
||||
if eventstore.EventType(e.Type) == user_repo.HumanPasswordlessInitCodeSentType {
|
||||
sentEvent := new(user_repo.HumanPasswordlessInitCodeSentEvent)
|
||||
if err := json.Unmarshal(e.Data, sentEvent); err != nil {
|
||||
return err
|
||||
@@ -369,21 +369,21 @@ func (n *Notification) handlePasswordlessRegistrationLink(event *models.Event) (
|
||||
return n.command.HumanPasswordlessInitCodeSent(ctx, event.AggregateID, event.ResourceOwner, addedEvent.ID)
|
||||
}
|
||||
|
||||
func (n *Notification) checkIfCodeAlreadyHandledOrExpired(event *models.Event, expiry time.Duration, eventTypes ...models.EventType) (bool, error) {
|
||||
func (n *Notification) checkIfCodeAlreadyHandledOrExpired(event *models.Event, expiry time.Duration, eventTypes ...eventstore.EventType) (bool, error) {
|
||||
if event.CreationDate.Add(expiry).Before(time.Now().UTC()) {
|
||||
return true, nil
|
||||
}
|
||||
return n.checkIfAlreadyHandled(event.AggregateID, event.Sequence, eventTypes...)
|
||||
}
|
||||
|
||||
func (n *Notification) checkIfAlreadyHandled(userID string, sequence uint64, eventTypes ...models.EventType) (bool, error) {
|
||||
func (n *Notification) checkIfAlreadyHandled(userID string, sequence uint64, eventTypes ...eventstore.EventType) (bool, error) {
|
||||
events, err := n.getUserEvents(userID, sequence)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, event := range events {
|
||||
for _, eventType := range eventTypes {
|
||||
if event.Type == eventType {
|
||||
if eventstore.EventType(event.Type) == eventType {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user