diff --git a/internal/auth/repository/eventsourcing/handler/user_session.go b/internal/auth/repository/eventsourcing/handler/user_session.go index 31d8ffa112..7581e66365 100644 --- a/internal/auth/repository/eventsourcing/handler/user_session.go +++ b/internal/auth/repository/eventsourcing/handler/user_session.go @@ -41,23 +41,7 @@ func (u *UserSession) EventQuery() (*models.SearchQuery, error) { } func (u *UserSession) Process(event *models.Event) (err error) { - eventData, err := view_model.UserSessionFromEvent(event) - if err != nil { - return err - } - session, err := u.view.UserSessionByIDs(eventData.UserAgentID, event.AggregateID) - if err != nil { - if !errors.IsNotFound(err) { - return err - } - session = &view_model.UserSessionView{ - CreationDate: event.CreationDate, - ResourceOwner: event.ResourceOwner, - UserAgentID: eventData.UserAgentID, - UserID: event.AggregateID, - State: int32(req_model.UserSessionStateActive), - } - } + var session *view_model.UserSessionView switch event.Type { case es_model.UserPasswordCheckSucceeded, es_model.UserPasswordCheckFailed, @@ -65,6 +49,23 @@ func (u *UserSession) Process(event *models.Event) (err error) { es_model.MfaOtpCheckSucceeded, es_model.MfaOtpCheckFailed, es_model.MfaOtpRemoved: + eventData, err := view_model.UserSessionFromEvent(event) + if err != nil { + return err + } + session, err = u.view.UserSessionByIDs(eventData.UserAgentID, event.AggregateID) + if err != nil { + if !errors.IsNotFound(err) { + return err + } + session = &view_model.UserSessionView{ + CreationDate: event.CreationDate, + ResourceOwner: event.ResourceOwner, + UserAgentID: eventData.UserAgentID, + UserID: event.AggregateID, + State: int32(req_model.UserSessionStateActive), + } + } session.AppendEvent(event) default: return u.view.ProcessedUserSessionSequence(event.Sequence) diff --git a/migrations/cockroach/V1.6__management_user_view.sql b/migrations/cockroach/V1.6__management_user_view.sql new file mode 100644 index 0000000000..14ff398097 --- /dev/null +++ b/migrations/cockroach/V1.6__management_user_view.sql @@ -0,0 +1,9 @@ +BEGIN; + +ALTER TABLE management.users + ADD COLUMN password_set BOOLEAN, + ADD COLUMN password_change_required BOOLEAN, + ADD COLUMN mfa_max_set_up SMALLINT, + ADD COLUMN mfa_init_skipped TIMESTAMPTZ; + +COMMIT; \ No newline at end of file