From efbc82e8b30eeed6d21286cf0f36ca2a427b47cb Mon Sep 17 00:00:00 2001 From: lvxinyu-1117 Date: Thu, 7 Aug 2025 12:10:26 +0800 Subject: [PATCH] fix: Correct userID propagation for agent-triggered workflows (#603) --- backend/crossdomain/workflow/database/database.go | 10 +++++----- .../domain/workflow/crossdomain/database/database.go | 10 +++++----- .../domain/workflow/internal/nodes/database/common.go | 8 ++++++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/backend/crossdomain/workflow/database/database.go b/backend/crossdomain/workflow/database/database.go index 8f7b22e2..8e5beb48 100644 --- a/backend/crossdomain/workflow/database/database.go +++ b/backend/crossdomain/workflow/database/database.go @@ -19,7 +19,6 @@ package database import ( "context" "fmt" - "strconv" "strings" "github.com/spf13/cast" @@ -63,7 +62,7 @@ func (d *DatabaseRepository) Execute(ctx context.Context, request *nodedatabase. OperateType: database.OperateType_Custom, SQL: &request.SQL, TableType: tableType, - UserID: strconv.FormatInt(request.UserID, 10), + UserID: request.UserID, ConnectorID: ptr.Of(request.ConnectorID), } @@ -106,7 +105,7 @@ func (d *DatabaseRepository) Delete(ctx context.Context, request *nodedatabase.D DatabaseID: databaseInfoID, OperateType: database.OperateType_Delete, TableType: tableType, - UserID: strconv.FormatInt(request.UserID, 10), + UserID: request.UserID, ConnectorID: ptr.Of(request.ConnectorID), } @@ -142,7 +141,7 @@ func (d *DatabaseRepository) Query(ctx context.Context, request *nodedatabase.Qu DatabaseID: databaseInfoID, OperateType: database.OperateType_Select, TableType: tableType, - UserID: strconv.FormatInt(request.UserID, 10), + UserID: request.UserID, ConnectorID: ptr.Of(request.ConnectorID), } @@ -199,6 +198,7 @@ func (d *DatabaseRepository) Update(ctx context.Context, request *nodedatabase.U OperateType: database.OperateType_Update, SQLParams: make([]*database.SQLParamVal, 0), TableType: tableType, + UserID: request.UserID, ConnectorID: ptr.Of(request.ConnectorID), } @@ -246,7 +246,7 @@ func (d *DatabaseRepository) Insert(ctx context.Context, request *nodedatabase.I DatabaseID: databaseInfoID, OperateType: database.OperateType_Insert, TableType: tableType, - UserID: strconv.FormatInt(request.UserID, 10), + UserID: request.UserID, ConnectorID: ptr.Of(request.ConnectorID), } diff --git a/backend/domain/workflow/crossdomain/database/database.go b/backend/domain/workflow/crossdomain/database/database.go index 8675ce1e..5a9e6750 100644 --- a/backend/domain/workflow/crossdomain/database/database.go +++ b/backend/domain/workflow/crossdomain/database/database.go @@ -29,7 +29,7 @@ type CustomSQLRequest struct { SQL string Params []SQLParam IsDebugRun bool - UserID int64 + UserID string ConnectorID int64 } @@ -91,7 +91,7 @@ type DeleteRequest struct { DatabaseInfoID int64 ConditionGroup *ConditionGroup IsDebugRun bool - UserID int64 + UserID string ConnectorID int64 } @@ -102,7 +102,7 @@ type QueryRequest struct { ConditionGroup *ConditionGroup OrderClauses []*OrderClause IsDebugRun bool - UserID int64 + UserID string ConnectorID int64 } @@ -115,7 +115,7 @@ type UpdateRequest struct { ConditionGroup *ConditionGroup Fields map[string]any IsDebugRun bool - UserID int64 + UserID string ConnectorID int64 } @@ -123,7 +123,7 @@ type InsertRequest struct { DatabaseInfoID int64 Fields map[string]any IsDebugRun bool - UserID int64 + UserID string ConnectorID int64 } diff --git a/backend/domain/workflow/internal/nodes/database/common.go b/backend/domain/workflow/internal/nodes/database/common.go index 3fd2c665..6af51830 100644 --- a/backend/domain/workflow/internal/nodes/database/common.go +++ b/backend/domain/workflow/internal/nodes/database/common.go @@ -415,12 +415,16 @@ func isDebugExecute(ctx context.Context) bool { return execCtx.RootCtx.ExeCfg.Mode == vo.ExecuteModeDebug || execCtx.RootCtx.ExeCfg.Mode == vo.ExecuteModeNodeDebug } -func getExecUserID(ctx context.Context) int64 { +func getExecUserID(ctx context.Context) string { execCtx := execute.GetExeCtx(ctx) if execCtx == nil { panic(fmt.Errorf("unable to get exe context")) } - return execCtx.RootCtx.ExeCfg.Operator + if execCtx.RootCtx.ExeCfg.AgentID != nil { + return execCtx.RootCtx.ExeCfg.ConnectorUID + } + uIDStr := strconv.FormatInt(execCtx.RootCtx.ExeCfg.Operator, 10) + return uIDStr } func getConnectorID(ctx context.Context) int64 {