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 {
v1["auth"] = userAuth[v1.GetString("name")]
}
for k2, _ := range v1.GetSlice("menus") {
v2 := menus.GetMap(k2)
if userAuth[v1.GetString("table")] != nil {
v1["auth"] = userAuth[v1.GetString("table")]
}
v1menus := v1.GetSlice("menus")
for k2, _ := range v1menus {
v2 := v1menus.GetMap(k2)
if userAuth[v2.GetString("name")] != nil {
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)
}
@ -136,21 +143,211 @@ var TptProject = Proj{
}
}
}
}
if that.MakeCodeRouter[hotimeName].TableColumns[tableName]["auth"] != nil {
linkHasAuth := that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"]
if linkHasAuth != nil {
if inData["auth"] != 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"))})
linkAuth := linkAuthMap.GetMap("auth")
myAuth := Map{}
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
}
}
//}
}
}
@ -178,12 +375,32 @@ var TptProject = Proj{
hotimeName := that.RouterString[0]
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
inData := that.MakeCodeRouter[hotimeName].Edit(tableName, that.Req)
if inData == nil {
that.Display(3, "没有找到要更新的数据")
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 {
@ -191,16 +408,16 @@ var TptProject = Proj{
if err != nil {
that.Display(4, "找不到配置文件")
return
}
conf := ObjToMap(string(btes))
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")] {
if v.GetString("link") != "" {
linkHasAuth := that.MakeCodeRouter[hotimeName].TableColumns[v.GetString("link")]["auth"]
if linkHasAuth != nil {
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"))})
linkAuth := linkAuthMap.GetMap("auth")
@ -210,66 +427,183 @@ var TptProject = Proj{
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")]
}
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 {
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 {
if myAuth.GetMap(v1.GetString("name")) == nil && myAuth.GetMap(v1.GetString("table")) == nil {
continue
}
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"`) {
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"`) {
auth = append(auth, "add")
//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"`) {
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"`) {
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"`) {
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
}
}
//}
}
}
@ -493,14 +827,21 @@ var TptProject = Proj{
if userAuth[v1.GetString("name")] != nil {
v1["auth"] = userAuth[v1.GetString("name")]
}
for k2, _ := range v1.GetSlice("menus") {
v2 := menus.GetMap(k2)
if userAuth[v1.GetString("table")] != nil {
v1["auth"] = userAuth[v1.GetString("table")]
}
v1menus := v1.GetSlice("menus")
for k2, _ := range v1menus {
v2 := v1menus.GetMap(k2)
if userAuth[v2.GetString("name")] != nil {
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)
}
@ -610,12 +951,18 @@ var TptProject = Proj{
for k1, _ := range menus {
v1 := menus.GetMap(k1)
if linkAuth[v1.GetString("name")] != nil {
v1["auth"] = linkAuth[v1.GetString("name")]
}
if linkAuth[v1.GetString("table")] != nil {
v1["auth"] = linkAuth[v1.GetString("table")]
}
v1menus := v1.GetSlice("menus")
for k2, _ := range v1menus {
v2 := v1menus.GetMap(k2)
if linkAuth[v2.GetString("name")] != nil {
v2["auth"] = linkAuth[v2.GetString("name")]
}
if linkAuth[v2.GetString("table")] != nil {
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 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")]
continue
}
@ -692,6 +692,13 @@ func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
continue
}
if user[v.GetString("name")] != nil {
data[v.GetString("name")] = user[v.GetString("name")]
continue
}
if v.GetBool("must") {
return nil
} else {
@ -699,6 +706,7 @@ func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
}
}
reqValue := req.FormValue(v.GetString("name"))
if (reqValue == "" || reqValue == "null") && strings.Contains(v.GetString("name"), "id") {
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 parent_idsStr != "" {
where := Map{}
for _, v := range reqValue {
if len(where) == 0 {
where[parent_idsStr] = "," + v + ","
continue
}
where = Map{"OR": where, parent_idsStr: "," + v + ","}
}
//用户
if userData[searchItem.GetString("name")] != nil {
where = Map{"AND": Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
}
r := db.Select(searchItem.GetString("link"), "id", where)
for _, v := range r {
reqValue = append(reqValue, v.GetString("id"))
}
}
//if parent_idsStr != "" {
//
// where := Map{}
//
// for _, v := range reqValue {
// if len(where) == 0 {
// where[parent_idsStr] = "," + v + ","
// continue
// }
// where = Map{"OR": where, parent_idsStr: "," + v + ","}
// }
// //用户
// if userData[searchItem.GetString("name")] != nil {
// where = Map{"AND": Map{parent_idsStr: "," + ObjToStr(userData.GetCeilInt64(searchItem.GetString("name"))) + ",", "OR": where}}
// }
// r := db.Select(searchItem.GetString("link"), "id", where)
// for _, v := range r {
// reqValue = append(reqValue, v.GetString("id"))
// }
//
//}
parentID := ObjToInt(req.FormValue("parent_id"))
if parentID == 0 {