|
|
@@ -7,6 +7,7 @@ import ( |
|
|
|
db "code.fnuoos.com/zhimeng/model.git/src" |
|
|
|
"code.fnuoos.com/zhimeng/model.git/src/implement" |
|
|
|
"code.fnuoos.com/zhimeng/model.git/src/model" |
|
|
|
implement2 "code.fnuoos.com/zhimeng/model.git/src/super/implement" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
@@ -67,6 +68,56 @@ func CheckUserRole(c *gin.Context, cacheKey, uri string, admId int) (isHasPermis |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func CheckUserRoleByOpen(c *gin.Context, cacheKey, uri string, masterId int) (isHasPermission bool, err error) { |
|
|
|
uri = utils.UriFilterExcludeQueryString(uri) // 去除uri中?后的query参数 |
|
|
|
isHasPermission = false |
|
|
|
var rolePermission []string |
|
|
|
var rolePermissionString string |
|
|
|
rolePermissionString, _ = cache.GetString(cacheKey) |
|
|
|
|
|
|
|
// TODO::判断是否在白名单中 |
|
|
|
if utils.InArr(uri, md.WhiteUri) { |
|
|
|
isHasPermission = true |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if rolePermissionString != "" { |
|
|
|
if err = json.Unmarshal([]byte(rolePermissionString), &rolePermission); err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
} else { |
|
|
|
userOpenPermissionDb := implement2.NewUserOpenPermissionDb(db.Db) |
|
|
|
list, _, err1 := userOpenPermissionDb.GetUserOpenPermission(masterId) |
|
|
|
if err1 != nil { |
|
|
|
return isHasPermission, err1 |
|
|
|
} |
|
|
|
for _, v := range list { |
|
|
|
rolePermission = append(rolePermission, v.OpenPermission.Action) |
|
|
|
} |
|
|
|
marshal, err1 := json.Marshal(rolePermission) |
|
|
|
if err1 != nil { |
|
|
|
return isHasPermission, err1 |
|
|
|
} |
|
|
|
rolePermissionString = string(marshal) |
|
|
|
_, err = cache.SetEx(cacheKey, rolePermissionString, md.AdminRolePermissionByOpenCacheTime) |
|
|
|
} |
|
|
|
|
|
|
|
if utils.InArr(uri, rolePermission) { |
|
|
|
isHasPermission = true |
|
|
|
} else { |
|
|
|
// 正则匹配占位符情况 |
|
|
|
compileRegex := regexp.MustCompile("[0-9]+") |
|
|
|
matchArr := compileRegex.FindAllString(uri, -1) |
|
|
|
if len(matchArr) > 0 { |
|
|
|
uri = strings.Replace(uri, matchArr[len(matchArr)-1], ":id", 1) |
|
|
|
if utils.InArr(uri, rolePermission) { |
|
|
|
isHasPermission = true |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func DeleteRole(c *gin.Context, roleId int) (err error) { |
|
|
|
engine := db.DBs[GetMasterId(c)] |
|
|
|
session := engine.NewSession() |
|
|
|