Skip to content

Commit

Permalink
v0.9.33 修复表格会话数据BUG & 安全更新
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Jan 19, 2022
1 parent d68acce commit 6d2cdaa
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 50 deletions.
2 changes: 1 addition & 1 deletion flow/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ func check(t *testing.T) {
for key := range gou.Flows {
keys = append(keys, key)
}
assert.Equal(t, 18, len(keys))
assert.Equal(t, 19, len(keys))
}
5 changes: 5 additions & 0 deletions share/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,20 @@ func (api API) MergeDefaultQueryParam(param gou.QueryParam, i int, sid string) g

// GetQueryParam 解析参数
func GetQueryParam(v interface{}, sid string) gou.QueryParam {
fmt.Println("\n==== GetQueryParam ===== SID:", sid)
data := map[string]interface{}{}
if sid != "" {
var err error
ss := session.Global().ID(sid)
data, err = ss.Dump()
utils.Dump(data)
if err != nil {
xlog.Printf("读取会话信息出错 %s", err.Error())
}
}
fmt.Println("==== GetQueryParam========================")
fmt.Println("")

v = share.Bind(v, maps.Of(data).Dot())
param, ok := gou.AnyToQueryParam(v)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion share/const.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package share

// VERSION 版本号
const VERSION = "0.9.32"
const VERSION = "0.9.33"

// DOMAIN 许可域(废弃)
const DOMAIN = "*.iqka.com"
Expand Down
2 changes: 1 addition & 1 deletion table/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func apiDefaultWhere(model *gou.Model, withs map[string]gou.With, name string, p
}

// apiDefaultSetting 数据表格配置默认值
func apiDefaultSetting(table *Table) share.API {
func apiDefaultSetting() share.API {
return share.API{
Name: "setting",
Guard: "bearer-jwt",
Expand Down
24 changes: 16 additions & 8 deletions table/process.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package table

import (
"fmt"
"strings"

"github.com/yaoapp/gou"
"github.com/yaoapp/kun/any"
"github.com/yaoapp/kun/maps"
"github.com/yaoapp/kun/utils"
)

func init() {
Expand Down Expand Up @@ -39,19 +41,25 @@ func ProcessSearch(process *gou.Process) interface{} {
}

// Before Hook
process.Args = table.Before(table.Hooks.BeforeSearch, process.Args)
process.Args = table.Before(table.Hooks.BeforeSearch, process.Args, process.Sid)

// 参数表
process.ValidateArgNums(4)
param := api.MergeDefaultQueryParam(process.ArgsQueryParams(1), 0, process.Sid)

fmt.Println("\n==== ProcessSearch ============= SID:", process.Sid)
utils.Dump(param)
fmt.Println("==== END ProcessSearch ===============================================")
fmt.Println("")

page := process.ArgsInt(2, api.DefaultInt(1))
pagesize := process.ArgsInt(3, api.DefaultInt(2))

// 查询数据
response := gou.NewProcess(api.Process, param, page, pagesize).Run()

// After Hook
return table.After(table.Hooks.AfterSearch, response)
return table.After(table.Hooks.AfterSearch, response, process.Sid)
}

// ProcessFind xiang.table.Find
Expand All @@ -67,7 +75,7 @@ func ProcessFind(process *gou.Process) interface{} {
}

// Before Hook
process.Args = table.Before(table.Hooks.BeforeFind, process.Args)
process.Args = table.Before(table.Hooks.BeforeFind, process.Args, process.Sid)

// 参数表
process.ValidateArgNums(2)
Expand All @@ -78,7 +86,7 @@ func ProcessFind(process *gou.Process) interface{} {
response := gou.NewProcess(api.Process, id, param).Run()

// After Hook
return table.After(table.Hooks.AfterFind, response)
return table.After(table.Hooks.AfterFind, response, process.Sid)
}

// ProcessSave xiang.table.Save
Expand All @@ -95,7 +103,7 @@ func ProcessSave(process *gou.Process) interface{} {
}

// Before Hook
process.Args = table.Before(table.Hooks.BeforeSave, process.Args)
process.Args = table.Before(table.Hooks.BeforeSave, process.Args, process.Sid)

// 参数处理
process.ValidateArgNums(2)
Expand All @@ -104,7 +112,7 @@ func ProcessSave(process *gou.Process) interface{} {
response := gou.NewProcess(api.Process, process.Args[1]).Run()

// After Hook
return table.After(table.Hooks.AfterSave, response)
return table.After(table.Hooks.AfterSave, response, process.Sid)
}

// ProcessDelete xiang.table.Delete
Expand Down Expand Up @@ -315,10 +323,10 @@ func ProcessSelect(process *gou.Process) interface{} {
}

// Before Hook
process.Args = table.Before(table.Hooks.BeforeSelect, process.Args)
process.Args = table.Before(table.Hooks.BeforeSelect, process.Args, process.Sid)

response := gou.NewProcess(api.Process, process.Args[1:]...).Run()

// After Hook
return table.After(table.Hooks.AfterSelect, response)
return table.After(table.Hooks.AfterSelect, response, process.Sid)
}
10 changes: 5 additions & 5 deletions table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (table *Table) loadAPIs() {
return
}
defaults := getDefaultAPIs(table.Bind)
defaults["setting"] = apiDefaultSetting(table)
defaults["setting"] = apiDefaultSetting()

for name := range table.APIs {
if _, has := defaults[name]; !has {
Expand Down Expand Up @@ -150,7 +150,7 @@ func getDefaultAPIs(bind Bind) map[string]share.API {
}

// Before 运行 Before hook
func (table *Table) Before(process string, processArgs []interface{}) []interface{} {
func (table *Table) Before(process string, processArgs []interface{}, sid string) []interface{} {
if process == "" {
return processArgs
}
Expand All @@ -161,7 +161,7 @@ func (table *Table) Before(process string, processArgs []interface{}) []interfac
res = append(res, processArgs[0])
}

response, err := gou.NewProcess(process, args...).Exec()
response, err := gou.NewProcess(process, args...).WithSID(sid).Exec()
if err != nil {
xlog.Println("Hook执行失败: ", err.Error(), maps.StrAny{"process": process, "args": args})
return processArgs
Expand All @@ -177,11 +177,11 @@ func (table *Table) Before(process string, processArgs []interface{}) []interfac
}

// After 运行 After hook
func (table *Table) After(process string, data interface{}) interface{} {
func (table *Table) After(process string, data interface{}, sid string) interface{} {
if process == "" {
return data
}
response, err := gou.NewProcess(process, data).Exec()
response, err := gou.NewProcess(process, data).WithSID(sid).Exec()
if err != nil {
xlog.Println("Hook执行失败: ", err.Error(), maps.StrAny{"process": process, "data": data})
return data
Expand Down
2 changes: 1 addition & 1 deletion table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ func check(t *testing.T) {
for key := range Tables {
keys = append(keys, key)
}
assert.Equal(t, 8, len(keys))
assert.Equal(t, 9, len(keys))
}
6 changes: 4 additions & 2 deletions tests/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "象传应用",
"short": "象传",
"description": "象传应用后台",
"option": {
"index": "/table/service"
},
"storage": {
"default": "oss",
"oss": {
Expand All @@ -14,6 +17,5 @@
},
"cos": {},
"s3": {}
},
"option": {}
}
}
17 changes: 17 additions & 0 deletions tests/flows/hooks/session.flow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"label": "会话测试",
"version": "1.0.0",
"description": "Before:Select",
"nodes": [
{
"name": "会话数据",
"process": "session.Dump"
},
{
"name": "打印数据",
"process": "xiang.helper.Print",
"args": ["会话数据:", "{{$res.会话数据}}"]
}
],
"output": "{{$in}}"
}
1 change: 0 additions & 1 deletion tests/tables/service.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"select": { "guard": "-" },
"search": {
"process": "models.service.Paginate",
"guard": "-",
"default": [null, null, 15]
},
"find": {
Expand Down
Loading

0 comments on commit 6d2cdaa

Please sign in to comment.