From 4698784efb2abf73d7a05143b9609e66056d6c9b Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 13 Dec 2022 10:36:37 +0800 Subject: [PATCH] [change] the permission session data format --- widgets/app/app.go | 11 +++++++++-- widgets/table/process.go | 2 +- widgets/table/process_test.go | 12 +++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/widgets/app/app.go b/widgets/app/app.go index bb1658cc..dfe93bcf 100644 --- a/widgets/app/app.go +++ b/widgets/app/app.go @@ -553,10 +553,17 @@ func (dsl *DSL) icons(cfg config.Config) { } // Permissions get the permission blacklist -func Permissions(process *gou.Process) map[string]bool { +// {".":[]} +func Permissions(process *gou.Process, widget string, id string) map[string]bool { permissions := map[string]bool{} sessionData, _ := session.Global().ID(process.Sid).Get("__permissions") - switch values := sessionData.(type) { + data, ok := sessionData.(map[string]interface{}) + if !ok && sessionData != nil { + log.Error("[Permissions] session data should be a map, but got %#v", sessionData) + return permissions + } + + switch values := data[fmt.Sprintf("%s.%s", widget, id)].(type) { case []interface{}: for _, value := range values { permissions[fmt.Sprintf("%v", value)] = true diff --git a/widgets/table/process.go b/widgets/table/process.go index eafca9c2..bcba7db6 100644 --- a/widgets/table/process.go +++ b/widgets/table/process.go @@ -47,7 +47,7 @@ func processXgen(process *gou.Process) interface{} { tab := MustGet(process) data := process.ArgsMap(1, map[string]interface{}{}) - excludes := app.Permissions(process) + excludes := app.Permissions(process, "tables", tab.ID) setting, err := tab.Xgen(data, excludes) if err != nil { exception.New(err.Error(), 500).Throw() diff --git a/widgets/table/process_test.go b/widgets/table/process_test.go index f2feae20..4f2a0149 100644 --- a/widgets/table/process_test.go +++ b/widgets/table/process_test.go @@ -438,11 +438,13 @@ func TestProcessXgenWithPermissions(t *testing.T) { clear(t) testData(t) - session.Global().Set("__permissions", []string{ - "8ca9bdf0fa2cbc8f1018f8566ed6ab5e", // fields.table.消费金额 - "f03f1ae60c46dd6cdeda87b919a51d7e", // fields.filter.状态 - "b1483ade34cd51261817558114e74e3f", // filter.actions[0] 添加宠物 - "e6a67850312980e8372e550c5b361097", // operation.actions[0] 查看 + session.Global().Set("__permissions", map[string]interface{}{ + "tables.pet": []string{ + "8ca9bdf0fa2cbc8f1018f8566ed6ab5e", // fields.table.消费金额 + "f03f1ae60c46dd6cdeda87b919a51d7e", // fields.filter.状态 + "b1483ade34cd51261817558114e74e3f", // filter.actions[0] 添加宠物 + "e6a67850312980e8372e550c5b361097", // operation.actions[0] 查看 + }, }) args := []interface{}{"pet"}