V2半封测

This commit is contained in:
hoteas 2022-07-27 17:09:56 +08:00
parent 952c3a1243
commit 21e0219568
2 changed files with 425 additions and 70 deletions

401
code.go
View File

@ -76,14 +76,21 @@ var TptProject = Proj{
if userAuth[v1.GetString("name")] != nil { if userAuth[v1.GetString("name")] != nil {
v1["auth"] = userAuth[v1.GetString("name")] v1["auth"] = userAuth[v1.GetString("name")]
} }
for k2, _ := range v1.GetSlice("menus") { if userAuth[v1.GetString("table")] != nil {
v2 := menus.GetMap(k2) v1["auth"] = userAuth[v1.GetString("table")]
}
v1menus := v1.GetSlice("menus")
for k2, _ := range v1menus {
v2 := v1menus.GetMap(k2)
if userAuth[v2.GetString("name")] != nil { if userAuth[v2.GetString("name")] != nil {
v2["auth"] = userAuth[v2.GetString("name")] v2["auth"] = userAuth[v2.GetString("name")]
} }
if userAuth[v2.GetString("table")] != nil {
v2["auth"] = userAuth[v2.GetString("table")]
} }
} }
re["auth"] = menus }
re["auth"] = menus.ToJsonString()
//that.Display(0,menus) //that.Display(0,menus)
} }
@ -136,21 +143,211 @@ var TptProject = Proj{
} }
} }
}
}
if that.MakeCodeRouter[hotimeName].TableColumns[tableName]["auth"] != nil { if inData["auth"] != nil {
linkHasAuth := that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"]
if linkHasAuth != nil { btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
if err != nil {
that.Display(4, "找不到配置文件")
return
}
conf := ObjToMap(string(btes))
menus := conf.GetSlice("menus")
for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] {
if v.GetString("link") != "" && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"] != nil {
//linkHasAuth := that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"]
//if linkHasAuth != nil {
linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": data.GetCeilInt(v.GetString("name"))}) linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": data.GetCeilInt(v.GetString("name"))})
linkAuth := linkAuthMap.GetMap("auth") linkAuth := linkAuthMap.GetMap("auth")
myAuth := Map{}
if linkAuth != nil { if linkAuth != nil {
inData["auth"] = ObjToStr(linkAuth)
for k1, _ := range menus {
v1 := menus.GetMap(k1)
if linkAuth[v1.GetString("table")] != nil {
v1["auth"] = linkAuth[v1.GetString("table")]
}
if linkAuth[v1.GetString("name")] != nil {
v1["auth"] = linkAuth[v1.GetString("name")]
} }
if v1.GetString("name") != "" && v1["auth"] == nil {
v1["auth"] = Slice{"show"}
}
if v1.GetString("table") != "" && v1["auth"] == nil {
v1["auth"] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v1.GetString("table"))["auth"]
}
if v1.GetString("table") != "" {
myAuth[v1.GetString("table")] = v1
}
if v1.GetString("name") != "" {
myAuth[v1.GetString("name")] = v1
}
v1menus := v1.GetSlice("menus")
for k2, _ := range v1menus {
v2 := v1menus.GetMap(k2)
if linkAuth[v2.GetString("table")] != nil {
v2["auth"] = linkAuth[v2.GetString("table")]
}
if linkAuth[v2.GetString("name")] != nil {
v2["auth"] = linkAuth[v2.GetString("name")]
}
if v2.GetString("name") != "" && v2["auth"] == nil {
v2["auth"] = Slice{"show"}
}
if v2.GetString("table") != "" && v2["auth"] == nil {
v2["auth"] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v2.GetString("table"))["auth"]
}
if v2.GetString("table") != "" {
myAuth[v2.GetString("table")] = v2
}
if v2.GetString("name") != "" {
myAuth[v2.GetString("name")] = v2
}
}
}
}
newAuth := inData.GetSlice("auth")
toDB := Map{}
for k1, _ := range newAuth {
v1 := newAuth.GetMap(k1)
if myAuth.GetMap(v1.GetString("name")) == nil && myAuth.GetMap(v1.GetString("table")) == nil {
continue
}
auth := Slice{}
str := v1.GetString("name")
if v1.GetString("table") != "" {
str = v1.GetString("table")
}
if v1.GetString("auth") == "" {
if myAuth.GetMap(str).GetString("table") != "" {
auth = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(str).GetSlice("auth")
} else {
auth = Slice{"show"}
}
} else {
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"show"`) &&
strings.Contains(v1.GetString("auth"), `"show"`) {
auth = append(auth, "show")
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"add"`) &&
strings.Contains(v1.GetString("auth"), `"add"`) {
auth = append(auth, "add")
//continue
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"edit"`) &&
strings.Contains(v1.GetString("auth"), `"edit"`) {
auth = append(auth, "edit")
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"delete"`) &&
strings.Contains(v1.GetString("auth"), `"delete"`) {
auth = append(auth, "delete")
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"info"`) &&
strings.Contains(v1.GetString("auth"), `"info"`) {
auth = append(auth, "info")
}
}
toDB[str] = auth
v1Menus := v1.GetSlice("menus")
for k2, _ := range v1Menus {
v2 := v1Menus.GetMap(k2)
if myAuth.GetMap(v2.GetString("name")) == nil && myAuth.GetMap(v2.GetString("table")) == nil {
continue
}
auth := Slice{}
str := v2.GetString("name")
if v2.GetString("table") != "" {
str = v2.GetString("table")
}
if v2.GetString("auth") == "" {
if myAuth.GetMap(str).GetString("table") != "" {
auth = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(str).GetSlice("auth")
} else {
auth = Slice{"show"}
}
} else {
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"show"`) &&
strings.Contains(v2.GetString("auth"), `"show"`) {
auth = append(auth, "show")
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"add"`) &&
strings.Contains(v2.GetString("auth"), `"add"`) {
auth = append(auth, "add")
//continue
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"edit"`) &&
strings.Contains(v2.GetString("auth"), `"edit"`) {
auth = append(auth, "edit")
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"delete"`) &&
strings.Contains(v2.GetString("auth"), `"delete"`) {
auth = append(auth, "delete")
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"info"`) &&
strings.Contains(v2.GetString("auth"), `"info"`) {
auth = append(auth, "info")
}
}
toDB[str] = auth
}
}
inData["auth"] = toDB.ToJsonString()
break break
} }
} //}
} }
} }
@ -178,12 +375,32 @@ var TptProject = Proj{
hotimeName := that.RouterString[0] hotimeName := that.RouterString[0]
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
inData := that.MakeCodeRouter[hotimeName].Edit(tableName, that.Req) inData := that.MakeCodeRouter[hotimeName].Edit(tableName, that.Req)
if inData == nil { if inData == nil {
that.Display(3, "没有找到要更新的数据") that.Display(3, "没有找到要更新的数据")
return return
} }
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
//树状结构不允许修改自身的属性,修改别人的可以
if fileConfig.GetString("table") == tableName && that.RouterString[2] == that.Session(fileConfig.GetString("table")+"_id").ToStr() {
for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] {
if v.GetString("link") == "" {
continue
}
if that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["parent_id"] != nil {
delete(inData, v.GetString("name"))
}
}
}
if inData["auth"] != nil { if inData["auth"] != nil {
@ -191,16 +408,16 @@ var TptProject = Proj{
if err != nil { if err != nil {
that.Display(4, "找不到配置文件") that.Display(4, "找不到配置文件")
return
} }
conf := ObjToMap(string(btes)) conf := ObjToMap(string(btes))
menus := conf.GetSlice("menus") menus := conf.GetSlice("menus")
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] { for _, v := range that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")] {
if v.GetString("link") != "" { if v.GetString("link") != "" && that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"] != nil {
linkHasAuth := that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"] //linkHasAuth := that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"]
if linkHasAuth != nil { //if linkHasAuth != nil {
linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": data.GetCeilInt(v.GetString("name"))}) linkAuthMap := that.Db.Get(v.GetString("link"), "auth", Map{"id": data.GetCeilInt(v.GetString("name"))})
linkAuth := linkAuthMap.GetMap("auth") linkAuth := linkAuthMap.GetMap("auth")
@ -210,66 +427,183 @@ var TptProject = Proj{
for k1, _ := range menus { for k1, _ := range menus {
v1 := menus.GetMap(k1) v1 := menus.GetMap(k1)
if linkAuth[v1.GetString("table")] != nil {
v1["auth"] = linkAuth[v1.GetString("table")]
}
if linkAuth[v1.GetString("name")] != nil { if linkAuth[v1.GetString("name")] != nil {
v1["auth"] = linkAuth[v1.GetString("name")] v1["auth"] = linkAuth[v1.GetString("name")]
} }
myAuth[v1.GetString("name")] = v1 if v1.GetString("name") != "" && v1["auth"] == nil {
v1["auth"] = Slice{"show"}
}
if v1.GetString("table") != "" && v1["auth"] == nil {
v1["auth"] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v1.GetString("table"))["auth"]
}
if v1.GetString("table") != "" {
myAuth[v1.GetString("table")] = v1
}
if v1.GetString("name") != "" {
myAuth[v1.GetString("name")] = v1
}
v1menus := v1.GetSlice("menus")
for k2, _ := range v1menus {
v2 := v1menus.GetMap(k2)
if linkAuth[v2.GetString("table")] != nil {
v2["auth"] = linkAuth[v2.GetString("table")]
}
for k2, _ := range v1.GetSlice("menus") {
v2 := menus.GetMap(k2)
if linkAuth[v2.GetString("name")] != nil { if linkAuth[v2.GetString("name")] != nil {
v2["auth"] = linkAuth[v2.GetString("name")] v2["auth"] = linkAuth[v2.GetString("name")]
} }
if v2.GetString("name") != "" && v2["auth"] == nil {
v2["auth"] = Slice{"show"}
}
if v2.GetString("table") != "" && v2["auth"] == nil {
v2["auth"] = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v2.GetString("table"))["auth"]
}
if v2.GetString("table") != "" {
myAuth[v2.GetString("table")] = v2
}
if v2.GetString("name") != "" {
myAuth[v2.GetString("name")] = v2 myAuth[v2.GetString("name")] = v2
} }
} }
} }
}
newAuth := inData.GetSlice("auth") newAuth := inData.GetSlice("auth")
toDB := Map{} toDB := Map{}
for k1, _ := range newAuth { for k1, _ := range newAuth {
v1 := newAuth.GetMap(k1) v1 := newAuth.GetMap(k1)
if myAuth.GetMap(v1.GetString("name")) == nil { if myAuth.GetMap(v1.GetString("name")) == nil && myAuth.GetMap(v1.GetString("table")) == nil {
continue continue
} }
auth := Slice{} auth := Slice{}
toDB[v1.GetString("name")] = auth
if strings.Contains(myAuth.GetMap(v1.GetString("name")).GetString("auth"), `"show"`) && str := v1.GetString("name")
if v1.GetString("table") != "" {
str = v1.GetString("table")
}
if v1.GetString("auth") == "" {
if myAuth.GetMap(str).GetString("table") != "" {
auth = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(str).GetSlice("auth")
} else {
auth = Slice{"show"}
}
} else {
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"show"`) &&
strings.Contains(v1.GetString("auth"), `"show"`) { strings.Contains(v1.GetString("auth"), `"show"`) {
auth = append(auth, "show") auth = append(auth, "show")
} }
if strings.Contains(myAuth.GetMap(v1.GetString("name")).GetString("auth"), `"add"`) && if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"add"`) &&
strings.Contains(v1.GetString("auth"), `"add"`) { strings.Contains(v1.GetString("auth"), `"add"`) {
auth = append(auth, "add") auth = append(auth, "add")
//continue //continue
} }
if strings.Contains(myAuth.GetMap(v1.GetString("name")).GetString("auth"), `"edit"`) && if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"edit"`) &&
strings.Contains(v1.GetString("auth"), `"edit"`) { strings.Contains(v1.GetString("auth"), `"edit"`) {
auth = append(auth, "edit") auth = append(auth, "edit")
} }
if strings.Contains(myAuth.GetMap(v1.GetString("name")).GetString("auth"), `"delete"`) && if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"delete"`) &&
strings.Contains(v1.GetString("auth"), `"delete"`) { strings.Contains(v1.GetString("auth"), `"delete"`) {
auth = append(auth, "delete") auth = append(auth, "delete")
} }
if strings.Contains(myAuth.GetMap(v1.GetString("name")).GetString("auth"), `"info"`) && if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"info"`) &&
strings.Contains(v1.GetString("auth"), `"info"`) { strings.Contains(v1.GetString("auth"), `"info"`) {
auth = append(auth, "info") auth = append(auth, "info")
} }
}
toDB[str] = auth
v1Menus := v1.GetSlice("menus")
for k2, _ := range v1Menus {
v2 := v1Menus.GetMap(k2)
if myAuth.GetMap(v2.GetString("name")) == nil && myAuth.GetMap(v2.GetString("table")) == nil {
continue
}
auth := Slice{}
str := v2.GetString("name")
if v2.GetString("table") != "" {
str = v2.GetString("table")
}
if v2.GetString("auth") == "" {
if myAuth.GetMap(str).GetString("table") != "" {
auth = that.MakeCodeRouter[hotimeName].TableConfig.GetMap(str).GetSlice("auth")
} else {
auth = Slice{"show"}
}
} else {
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"show"`) &&
strings.Contains(v2.GetString("auth"), `"show"`) {
auth = append(auth, "show")
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"add"`) &&
strings.Contains(v2.GetString("auth"), `"add"`) {
auth = append(auth, "add")
//continue
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"edit"`) &&
strings.Contains(v2.GetString("auth"), `"edit"`) {
auth = append(auth, "edit")
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"delete"`) &&
strings.Contains(v2.GetString("auth"), `"delete"`) {
auth = append(auth, "delete")
}
if strings.Contains(myAuth.GetMap(str).GetString("auth"), `"info"`) &&
strings.Contains(v2.GetString("auth"), `"info"`) {
auth = append(auth, "info")
}
}
toDB[str] = auth
}
} }
inData["auth"] = toDB.ToJsonString() inData["auth"] = toDB.ToJsonString()
break break
} }
} //}
} }
} }
@ -493,14 +827,21 @@ var TptProject = Proj{
if userAuth[v1.GetString("name")] != nil { if userAuth[v1.GetString("name")] != nil {
v1["auth"] = userAuth[v1.GetString("name")] v1["auth"] = userAuth[v1.GetString("name")]
} }
for k2, _ := range v1.GetSlice("menus") { if userAuth[v1.GetString("table")] != nil {
v2 := menus.GetMap(k2) v1["auth"] = userAuth[v1.GetString("table")]
}
v1menus := v1.GetSlice("menus")
for k2, _ := range v1menus {
v2 := v1menus.GetMap(k2)
if userAuth[v2.GetString("name")] != nil { if userAuth[v2.GetString("name")] != nil {
v2["auth"] = userAuth[v2.GetString("name")] v2["auth"] = userAuth[v2.GetString("name")]
} }
if userAuth[v2.GetString("table")] != nil {
v2["auth"] = userAuth[v2.GetString("table")]
} }
} }
re["auth"] = menus }
re["auth"] = menus.ToJsonString()
//that.Display(0,menus) //that.Display(0,menus)
} }
@ -610,12 +951,18 @@ var TptProject = Proj{
for k1, _ := range menus { for k1, _ := range menus {
v1 := menus.GetMap(k1) v1 := menus.GetMap(k1)
if linkAuth[v1.GetString("name")] != nil {
v1["auth"] = linkAuth[v1.GetString("name")]
}
if linkAuth[v1.GetString("table")] != nil { if linkAuth[v1.GetString("table")] != nil {
v1["auth"] = linkAuth[v1.GetString("table")] v1["auth"] = linkAuth[v1.GetString("table")]
} }
v1menus := v1.GetSlice("menus") v1menus := v1.GetSlice("menus")
for k2, _ := range v1menus { for k2, _ := range v1menus {
v2 := v1menus.GetMap(k2) v2 := v1menus.GetMap(k2)
if linkAuth[v2.GetString("name")] != nil {
v2["auth"] = linkAuth[v2.GetString("name")]
}
if linkAuth[v2.GetString("table")] != nil { if linkAuth[v2.GetString("table")] != nil {
v2["auth"] = linkAuth[v2.GetString("table")] v2["auth"] = linkAuth[v2.GetString("table")]
} }

View File

@ -680,9 +680,9 @@ func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
} }
if v.Get("add") == nil || v.GetBool("add") { if v.Get("add") == nil || v.GetBool("add") {
if len(req.Form[v.GetString("name")]) == 0 { if len(req.Form[v.GetString("name")]) == 0 || req.FormValue(v.GetString("name")) == "" {
if user[v.GetString("name")] != nil { if v["link"] != nil && user[v.GetString("name")] != nil {
data[v.GetString("name")] = user[v.GetString("name")] data[v.GetString("name")] = user[v.GetString("name")]
continue continue
} }
@ -692,6 +692,13 @@ func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
continue continue
} }
if user[v.GetString("name")] != nil {
data[v.GetString("name")] = user[v.GetString("name")]
continue
}
if v.GetBool("must") { if v.GetBool("must") {
return nil return nil
} else { } else {
@ -699,6 +706,7 @@ func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
} }
} }
reqValue := req.FormValue(v.GetString("name")) reqValue := req.FormValue(v.GetString("name"))
if (reqValue == "" || reqValue == "null") && strings.Contains(v.GetString("name"), "id") { if (reqValue == "" || reqValue == "null") && strings.Contains(v.GetString("name"), "id") {
data[v.GetString("name")] = nil data[v.GetString("name")] = nil
@ -1010,27 +1018,27 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
} }
//树节点模式搜索 //树节点模式搜索
if searchItemName == "parent_id" { if searchItemName == "parent_id" {
if parent_idsStr != "" { //if parent_idsStr != "" {
//
where := Map{} // where := Map{}
//
for _, v := range reqValue { // for _, v := range reqValue {
if len(where) == 0 { // if len(where) == 0 {
where[parent_idsStr] = "," + v + "," // where[parent_idsStr] = "," + v + ","
continue // continue
} // }
where = Map{"OR": where, parent_idsStr: "," + v + ","} // where = Map{"OR": where, parent_idsStr: "," + v + ","}
} // }
//用户 // //用户
if userData[searchItem.GetString("name")] != nil { // if userData[searchItem.GetString("name")] != nil {
where = Map{"AND": Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}} // where = Map{"AND": Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
} // }
r := db.Select(searchItem.GetString("link"), "id", where) // r := db.Select(searchItem.GetString("link"), "id", where)
for _, v := range r { // for _, v := range r {
reqValue = append(reqValue, v.GetString("id")) // reqValue = append(reqValue, v.GetString("id"))
} // }
//
} //}
parentID := ObjToInt(req.FormValue("parent_id")) parentID := ObjToInt(req.FormValue("parent_id"))
if parentID == 0 { if parentID == 0 {