diff --git a/internal/user/repository/eventsourcing/eventstore_mock_test.go b/internal/user/repository/eventsourcing/eventstore_mock_test.go index 44c8daff5..ec0e0cc9e 100644 --- a/internal/user/repository/eventsourcing/eventstore_mock_test.go +++ b/internal/user/repository/eventsourcing/eventstore_mock_test.go @@ -472,8 +472,8 @@ func GetMockManipulateUserWithExternalIDP(ctrl *gomock.Controller) *UserEventsto dataUser, _ := json.Marshal(user) dataIDP, _ := json.Marshal(externalIDP) events := []*es_models.Event{ - {AggregateID: "AggregateID", AggregateVersion: "v1", Sequence: 1, Type: model.UserAdded, Data: dataUser}, - {AggregateID: "AggregateID", AggregateVersion: "v1", Sequence: 1, Type: model.HumanExternalIDPAdded, Data: dataIDP}, + {AggregateID: "AggregateID", AggregateVersion: "v1", Sequence: 1, Type: model.UserAdded, Data: dataUser, ResourceOwner: "ResourceOwner"}, + {AggregateID: "AggregateID", AggregateVersion: "v1", Sequence: 1, Type: model.HumanExternalIDPAdded, Data: dataIDP, ResourceOwner: "ResourceOwner"}, } mockEs := mock.NewMockEventstore(ctrl) mockEs.EXPECT().FilterEvents(gomock.Any(), gomock.Any()).Return(events, nil) diff --git a/internal/user/repository/eventsourcing/user.go b/internal/user/repository/eventsourcing/user.go index 754991f1b..3dcf50a0d 100644 --- a/internal/user/repository/eventsourcing/user.go +++ b/internal/user/repository/eventsourcing/user.go @@ -836,7 +836,7 @@ func ExternalIDPRemovedAggregate(ctx context.Context, aggCreator *es_models.Aggr } aggregates := make([]*es_models.Aggregate, 0) - agg, err := UserAggregate(ctx, aggCreator, user) + agg, err := UserAggregateOverwriteContext(ctx, aggCreator, user, user.ResourceOwner, authz.GetCtxData(ctx).UserID) if err != nil { return nil, err } @@ -845,7 +845,7 @@ func ExternalIDPRemovedAggregate(ctx context.Context, aggCreator *es_models.Aggr } else { agg, err = agg.AppendEvent(model.HumanExternalIDPRemoved, externalIDP) } - uniqueReleasedAggregate, err := releasedUniqueExternalIDPAggregate(ctx, aggCreator, externalIDP) + uniqueReleasedAggregate, err := releasedUniqueExternalIDPAggregate(ctx, aggCreator, externalIDP, user.ResourceOwner) if err != nil { return nil, err } @@ -870,9 +870,10 @@ func reservedUniqueExternalIDPAggregate(ctx context.Context, aggCreator *es_mode return aggregate.SetPrecondition(UserExternalIDPUniqueQuery(uniqueExternlIDP), isEventValidation(aggregate, model.HumanExternalIDPReserved)), nil } -func releasedUniqueExternalIDPAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, externalIDP *model.ExternalIDP) (aggregate *es_models.Aggregate, err error) { +func releasedUniqueExternalIDPAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, externalIDP *model.ExternalIDP, resourceOwnerID string) (aggregate *es_models.Aggregate, err error) { uniqueExternlIDP := externalIDP.IDPConfigID + externalIDP.UserID - aggregate, err = aggCreator.NewAggregate(ctx, uniqueExternlIDP, model.UserExternalIDPAggregate, model.UserVersion, 0) + aggregate, err = aggCreator.NewAggregate(ctx, uniqueExternlIDP, model.UserExternalIDPAggregate, model.UserVersion, 0, es_models.OverwriteResourceOwner(resourceOwnerID), es_models.OverwriteEditorUser(authz.GetCtxData(ctx).UserID)) + if err != nil { return nil, err } diff --git a/internal/user/repository/eventsourcing/user_test.go b/internal/user/repository/eventsourcing/user_test.go index 7d4b978ef..9e5917b15 100644 --- a/internal/user/repository/eventsourcing/user_test.go +++ b/internal/user/repository/eventsourcing/user_test.go @@ -2388,8 +2388,9 @@ func TestExternalIDPRemovedAggregates(t *testing.T) { aggCreator: models.NewAggregateCreator("test"), user: &model.User{ ObjectRoot: models.ObjectRoot{ - AggregateID: "AggregateID", - Sequence: 5, + AggregateID: "AggregateID", + Sequence: 5, + ResourceOwner: "ResourceOwner", }, }, externalIDP: &model.ExternalIDP{