diff --git a/internal/v2/business/iam/idp_oidc_config.go b/internal/v2/business/iam/idp_oidc_config.go index 2e4db7be13..ca5da4a6ec 100644 --- a/internal/v2/business/iam/idp_oidc_config.go +++ b/internal/v2/business/iam/idp_oidc_config.go @@ -11,14 +11,12 @@ import ( func (r *Repository) ChangeIDPOIDCConfig(ctx context.Context, config *iam_model.OIDCIDPConfig) (*iam_model.OIDCIDPConfig, error) { writeModel := iam.NewIDPOIDCConfigWriteModel(config.AggregateID, config.IDPConfigID) - err := r.eventstore.FilterToQueryReducer(ctx, writeModel) if err != nil { return nil, err } var clientSecret *crypto.CryptoValue - if config.ClientSecretString != "" { clientSecret, err = crypto.Crypt([]byte(config.ClientSecretString), r.secretCrypto) if err != nil { @@ -37,15 +35,10 @@ func (r *Repository) ChangeIDPOIDCConfig(ctx context.Context, config *iam_model. oidc.MappingField(config.UsernameMapping), config.Scopes...) - events, err := r.eventstore.PushAggregates(ctx, aggregate) + err = r.eventstore.PushAggregate(ctx, writeModel, aggregate) if err != nil { return nil, err } - writeModel.AppendEvents(events...) - if err = writeModel.Reduce(); err != nil { - return nil, err - } - return writeModelToIDPOIDCConfig(&writeModel.ConfigWriteModel), nil } diff --git a/internal/v2/business/iam/member.go b/internal/v2/business/iam/member.go index 25df66b00c..9d334ff390 100644 --- a/internal/v2/business/iam/member.go +++ b/internal/v2/business/iam/member.go @@ -5,7 +5,6 @@ import ( "github.com/caos/zitadel/internal/errors" caos_errs "github.com/caos/zitadel/internal/errors" - "github.com/caos/zitadel/internal/eventstore/v2" iam_model "github.com/caos/zitadel/internal/iam/model" "github.com/caos/zitadel/internal/tracing" iam_repo "github.com/caos/zitadel/internal/v2/repository/iam" @@ -86,17 +85,8 @@ func (r *Repository) MemberByID(ctx context.Context, iamID, userID string) (memb ctx, span := tracing.NewSpan(ctx) defer func() { span.EndWithError(err) }() - member = new(iam_repo.MemberReadModel) - - //query view - - query := eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, iam_repo.AggregateType). - AggregateIDs(iamID). - EventData(map[string]interface{}{ - "userId": userID, - }).SequenceGreater(member.ProcessedSequence) - - err = r.eventstore.FilterToReducer(ctx, query, member) + member = iam_repo.NewMemberReadModel(iamID, userID) + err = r.eventstore.FilterToQueryReducer(ctx, member) if err != nil { return nil, err } diff --git a/internal/v2/business/iam/policy_login.go b/internal/v2/business/iam/policy_login.go index 35287ddb54..89d1564b07 100644 --- a/internal/v2/business/iam/policy_login.go +++ b/internal/v2/business/iam/policy_login.go @@ -14,6 +14,7 @@ func (r *Repository) AddIDPProviderToLoginPolicy(ctx context.Context, idpProvide if err != nil { return nil, err } + aggregate := iam.AggregateFromWriteModel(&writeModel.WriteModel). PushLoginPolicyIDPProviderAddedEvent(ctx, idpProvider.IdpConfigID, provider.Type(idpProvider.Type)) diff --git a/internal/v2/repository/iam/aggregate.go b/internal/v2/repository/iam/aggregate.go index eea2f10d07..63105f3c27 100644 --- a/internal/v2/repository/iam/aggregate.go +++ b/internal/v2/repository/iam/aggregate.go @@ -155,6 +155,7 @@ func (a *Aggregate) PushIDPOIDCConfigChanged( userNameMapping oidc.MappingField, scopes ...string, ) *Aggregate { + event, err := NewIDPOIDCConfigChangedEvent(ctx, current, clientID, issuer, clientSecret, idpDisplayNameMapping, userNameMapping, scopes...) if err != nil { return a @@ -169,6 +170,7 @@ func (a *Aggregate) PushLoginPolicyIDPProviderAddedEvent( idpConfigID string, providerType provider.Type, ) *Aggregate { + a.Aggregate = *a.PushEvents(NewLoginPolicyIDPProviderAddedEvent(ctx, idpConfigID, providerType)) return a } @@ -178,6 +180,7 @@ func (a *Aggregate) PushLoginPolicyIDPProviderRemovedEvent( idpConfigID string, providerType provider.Type, ) *Aggregate { + a.Aggregate = *a.PushEvents(NewLoginPolicyIDPProviderRemovedEvent(ctx, idpConfigID)) return a } diff --git a/internal/v2/repository/iam/idp_config.go b/internal/v2/repository/iam/idp_config.go index 3203845785..9bc536885b 100644 --- a/internal/v2/repository/iam/idp_config.go +++ b/internal/v2/repository/iam/idp_config.go @@ -181,6 +181,7 @@ func NewIDPConfigChangedEvent( configType idp.ConfigType, stylingType idp.StylingType, ) (*IDPConfigChangedEvent, error) { + event, err := idp.NewConfigChangedEvent( eventstore.NewBaseEventForPush( ctx, diff --git a/internal/v2/repository/iam/member.go b/internal/v2/repository/iam/member.go index 0ab7b17688..a9146b58b6 100644 --- a/internal/v2/repository/iam/member.go +++ b/internal/v2/repository/iam/member.go @@ -16,6 +16,16 @@ var ( type MemberReadModel struct { member.ReadModel + + userID string + iamID string +} + +func NewMemberReadModel(iamID, userID string) *MemberReadModel { + return &MemberReadModel{ + iamID: iamID, + userID: userID, + } } func (rm *MemberReadModel) AppendEvents(events ...eventstore.EventReader) { @@ -31,6 +41,14 @@ func (rm *MemberReadModel) AppendEvents(events ...eventstore.EventReader) { } } +func (rm *MemberReadModel) Query() *eventstore.SearchQueryFactory { + return eventstore.NewSearchQueryFactory(eventstore.ColumnsEvent, AggregateType). + AggregateIDs(rm.iamID). + EventData(map[string]interface{}{ + "userId": rm.userID, + }) +} + type MemberWriteModel struct { eventstore.WriteModel Member member.WriteModel diff --git a/internal/v2/repository/member/aggregate.go b/internal/v2/repository/member/aggregate.go deleted file mode 100644 index 465cc6fb5d..0000000000 --- a/internal/v2/repository/member/aggregate.go +++ /dev/null @@ -1,18 +0,0 @@ -package member - -import "github.com/caos/zitadel/internal/eventstore/v2" - -type Aggregate struct { - eventstore.Aggregate - - UserID string - Roles []string -} - -func NewAggregate(aggregate *eventstore.Aggregate, userID string, roles ...string) *Aggregate { - return &Aggregate{ - Aggregate: *aggregate, - Roles: roles, - UserID: userID, - } -}