Compare commits

...

4 Commits

Author SHA1 Message Date
Yang Luo
f5d3738e8f Update record.go 2026-02-11 01:29:49 +08:00
copilot-swe-agent[bot]
7e99bafe19 Address code review feedback: improve error handling and add comments
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
2026-02-07 14:35:28 +00:00
copilot-swe-agent[bot]
10f6719dfc Fix set-password webhook and record to capture target user information
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
2026-02-07 14:34:00 +00:00
copilot-swe-agent[bot]
fedb37c7f6 Initial plan 2026-02-07 14:28:35 +00:00

View File

@@ -65,6 +65,22 @@ func RecordMessage(ctx *context.Context) {
userId := getUser(ctx)
// Special handling for set-password endpoint to capture target user
if ctx.Request.URL.Path == "/api/set-password" {
// Parse form if not already parsed
if err := ctx.Request.ParseForm(); err != nil {
fmt.Printf("RecordMessage() error parsing form: %s\n", err.Error())
} else {
userOwner := ctx.Request.Form.Get("userOwner")
userName := ctx.Request.Form.Get("userName")
if userOwner != "" && userName != "" {
targetUserId := util.GetId(userOwner, userName)
ctx.Input.SetParam("recordTargetUserId", targetUserId)
}
}
}
ctx.Input.SetParam("recordUserId", userId)
}
@@ -76,7 +92,20 @@ func AfterRecordMessage(ctx *context.Context) {
}
userId := ctx.Input.Params()["recordUserId"]
if userId != "" {
targetUserId := ctx.Input.Params()["recordTargetUserId"]
// For set-password endpoint, use target user if available
// We use defensive error handling here (log instead of panic) because target user
// parsing is a new feature. If it fails, we gracefully fall back to the regular
// userId flow or empty user/org fields, maintaining backward compatibility.
if record.Action == "set-password" && targetUserId != "" {
owner, user, err := util.GetOwnerAndNameFromIdWithError(targetUserId)
if err != nil {
fmt.Printf("AfterRecordMessage() error parsing target user %s: %s\n", targetUserId, err.Error())
} else {
record.Organization, record.User = owner, user
}
} else if userId != "" {
owner, user, err := util.GetOwnerAndNameFromIdWithError(userId)
if err != nil {
panic(err)