[change] the permission session data format

This commit is contained in:
Max 2022-12-13 10:36:37 +08:00
parent ef96535b41
commit 4698784efb
3 changed files with 17 additions and 8 deletions

View file

@ -553,10 +553,17 @@ func (dsl *DSL) icons(cfg config.Config) {
}
// Permissions get the permission blacklist
func Permissions(process *gou.Process) map[string]bool {
// {"<widget>.<ID>":[<id...>]}
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

View file

@ -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()

View file

@ -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"}