fix: 云端函数默认注入当前登录用户信息
- 当请求参数未指定 user_id 时,使用 token 中的用户 ID - 确保 user、subscription、devices 等变量始终有值
This commit is contained in:
@@ -173,9 +173,13 @@ func handleExecuteDynamicCode(c *gin.Context) {
|
|||||||
userVariables := map[string]interface{}{}
|
userVariables := map[string]interface{}{}
|
||||||
devices := []map[string]interface{}{}
|
devices := []map[string]interface{}{}
|
||||||
|
|
||||||
|
targetUserID := claims.UserID
|
||||||
if req.UserID != nil {
|
if req.UserID != nil {
|
||||||
|
targetUserID = *req.UserID
|
||||||
|
}
|
||||||
|
|
||||||
var user model.AppUser
|
var user model.AppUser
|
||||||
if err := database.DB.Where("id = ? AND application_id = ?", *req.UserID, app.ID).First(&user).Error; err == nil {
|
if err := database.DB.Where("id = ? AND application_id = ?", targetUserID, app.ID).First(&user).Error; err == nil {
|
||||||
userData = map[string]interface{}{
|
userData = map[string]interface{}{
|
||||||
"id": user.ID,
|
"id": user.ID,
|
||||||
"username": user.Username,
|
"username": user.Username,
|
||||||
@@ -217,7 +221,6 @@ func handleExecuteDynamicCode(c *gin.Context) {
|
|||||||
userVariables[v.VarName] = v.VarValue
|
userVariables[v.VarName] = v.VarValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if err := vm.Set("user", userData); err != nil {
|
if err := vm.Set("user", userData); err != nil {
|
||||||
response.Error(c, 500, "用户数据设置失败")
|
response.Error(c, 500, "用户数据设置失败")
|
||||||
|
|||||||
Reference in New Issue
Block a user