mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37:32 +00:00
fix(projections): pass context to statement execution method (#10328)
## Which problems are solved The execution of statements of projections did not have the context present. ## How the problems were solved Pass the context to the execute function ## Additional info This change is required to use the repositories of the relational tables in projections.
This commit is contained in:
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
const ExecutionUserID = "EXECUTION"
|
||||
|
||||
func HandlerContext(event *eventstore.Aggregate) context.Context {
|
||||
ctx := authz.WithInstanceID(context.Background(), event.InstanceID)
|
||||
func HandlerContext(parent context.Context, event *eventstore.Aggregate) context.Context {
|
||||
ctx := authz.WithInstanceID(parent, event.InstanceID)
|
||||
return authz.SetCtxData(ctx, authz.CtxData{UserID: ExecutionUserID, OrgID: event.ResourceOwner})
|
||||
}
|
||||
|
||||
|
@@ -113,7 +113,7 @@ func idsForEventType(eventType string) []string {
|
||||
}
|
||||
|
||||
func (u *eventHandler) reduce(e eventstore.Event) (*handler.Statement, error) {
|
||||
ctx := HandlerContext(e.Aggregate())
|
||||
ctx := HandlerContext(context.Background(), e.Aggregate())
|
||||
|
||||
targets, err := u.query.TargetsByExecutionID(ctx, idsForEventType(string(e.Type())))
|
||||
if err != nil {
|
||||
@@ -125,8 +125,8 @@ func (u *eventHandler) reduce(e eventstore.Event) (*handler.Statement, error) {
|
||||
return handler.NewNoOpStatement(e), nil
|
||||
}
|
||||
|
||||
return handler.NewStatement(e, func(ex handler.Executer, projectionName string) error {
|
||||
ctx := HandlerContext(e.Aggregate())
|
||||
return handler.NewStatement(e, func(ctx context.Context, ex handler.Executer, projectionName string) error {
|
||||
ctx = HandlerContext(ctx, e.Aggregate())
|
||||
req, err := NewRequest(e, targets)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -440,7 +440,7 @@ func TestActionProjection_reduces(t *testing.T) {
|
||||
assert.Nil(t, stmt.Execute)
|
||||
return
|
||||
}
|
||||
err = stmt.Execute(nil, "")
|
||||
err = stmt.Execute(t.Context(), nil, "")
|
||||
if w.stmtErr != nil {
|
||||
w.stmtErr(t, err)
|
||||
return
|
||||
|
Reference in New Issue
Block a user