|
@@ -16,20 +16,20 @@ import ( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func CheckUserRole(c *gin.Context, cacheKey, uri string, admId int) (isHasPermission bool, err error) { |
|
|
func CheckUserRole(c *gin.Context, cacheKey, uri string, admId int) (isHasPermission bool, err error) { |
|
|
uri = utils.UriFilterExcludeQueryString(uri) //去除uri中?后的query参数 |
|
|
|
|
|
|
|
|
uri = utils.UriFilterExcludeQueryString(uri) // 去除uri中?后的query参数 |
|
|
isHasPermission = false |
|
|
isHasPermission = false |
|
|
var rolePermission []string |
|
|
var rolePermission []string |
|
|
var rolePermissionString string |
|
|
var rolePermissionString string |
|
|
rolePermissionString, _ = cache.GetString(cacheKey) |
|
|
rolePermissionString, _ = cache.GetString(cacheKey) |
|
|
|
|
|
|
|
|
//TODO::判断是否在白名单中 |
|
|
|
|
|
|
|
|
// TODO::判断是否在白名单中 |
|
|
if utils.InArr(uri, md.WhiteUri) { |
|
|
if utils.InArr(uri, md.WhiteUri) { |
|
|
isHasPermission = true |
|
|
isHasPermission = true |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if rolePermissionString != "" { |
|
|
if rolePermissionString != "" { |
|
|
//if false { |
|
|
|
|
|
|
|
|
// if false { |
|
|
if err = json.Unmarshal([]byte(rolePermissionString), &rolePermission); err != nil { |
|
|
if err = json.Unmarshal([]byte(rolePermissionString), &rolePermission); err != nil { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@@ -53,7 +53,7 @@ func CheckUserRole(c *gin.Context, cacheKey, uri string, admId int) (isHasPermis |
|
|
if utils.InArr(uri, rolePermission) { |
|
|
if utils.InArr(uri, rolePermission) { |
|
|
isHasPermission = true |
|
|
isHasPermission = true |
|
|
} else { |
|
|
} else { |
|
|
//正则匹配占位符情况 |
|
|
|
|
|
|
|
|
// 正则匹配占位符情况 |
|
|
compileRegex := regexp.MustCompile("[0-9]+") |
|
|
compileRegex := regexp.MustCompile("[0-9]+") |
|
|
matchArr := compileRegex.FindAllString(uri, -1) |
|
|
matchArr := compileRegex.FindAllString(uri, -1) |
|
|
if len(matchArr) > 0 { |
|
|
if len(matchArr) > 0 { |
|
@@ -67,19 +67,20 @@ func CheckUserRole(c *gin.Context, cacheKey, uri string, admId int) (isHasPermis |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func DeleteRole(c *gin.Context, roleId int) (err error) { |
|
|
func DeleteRole(c *gin.Context, roleId int) (err error) { |
|
|
session := db.Db.NewSession() |
|
|
|
|
|
|
|
|
engine := db.DBs[GetMasterId(c)] |
|
|
|
|
|
session := engine.NewSession() |
|
|
defer session.Close() |
|
|
defer session.Close() |
|
|
session.Begin() |
|
|
session.Begin() |
|
|
|
|
|
|
|
|
//1、删除 `role` |
|
|
|
|
|
roleDb := implement.NewRoleDb(db.DBs[GetMasterId(c)], roleId) |
|
|
|
|
|
|
|
|
// 1、删除 `role` |
|
|
|
|
|
roleDb := implement.NewRoleDb(engine, roleId) |
|
|
_, err = roleDb.RoleDeleteBySession(session, roleId) |
|
|
_, err = roleDb.RoleDeleteBySession(session, roleId) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
_ = session.Rollback() |
|
|
_ = session.Rollback() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//2、删除 `role_permission_group` |
|
|
|
|
|
|
|
|
// 2、删除 `role_permission_group` |
|
|
rolePermissionGroupDb := implement.NewRolePermissionGroupDb(db.DBs[GetMasterId(c)]) |
|
|
rolePermissionGroupDb := implement.NewRolePermissionGroupDb(db.DBs[GetMasterId(c)]) |
|
|
_, err = rolePermissionGroupDb.RolePermissionGroupDeleteForRoleBySession(session, roleId) |
|
|
_, err = rolePermissionGroupDb.RolePermissionGroupDeleteForRoleBySession(session, roleId) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@@ -87,7 +88,7 @@ func DeleteRole(c *gin.Context, roleId int) (err error) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//3、删除 `admin_role` |
|
|
|
|
|
|
|
|
// 3、删除 `admin_role` |
|
|
adminRoleDb := implement.NewAdminRoleDb(db.DBs[GetMasterId(c)]) |
|
|
adminRoleDb := implement.NewAdminRoleDb(db.DBs[GetMasterId(c)]) |
|
|
_, err = adminRoleDb.AdminRoleDeleteForRoleBySession(session, roleId) |
|
|
_, err = adminRoleDb.AdminRoleDeleteForRoleBySession(session, roleId) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@@ -99,10 +100,11 @@ func DeleteRole(c *gin.Context, roleId int) (err error) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func RoleBindPermissionGroup(c *gin.Context, req md.RoleBindPermissionGroupReq) (err error) { |
|
|
func RoleBindPermissionGroup(c *gin.Context, req md.RoleBindPermissionGroupReq) (err error) { |
|
|
session := db.Db.NewSession() |
|
|
|
|
|
|
|
|
engine := db.DBs[GetMasterId(c)] |
|
|
|
|
|
session := engine.NewSession() |
|
|
defer session.Close() |
|
|
defer session.Close() |
|
|
session.Begin() |
|
|
session.Begin() |
|
|
//1、查询 `role` |
|
|
|
|
|
|
|
|
// 1、查询 `role` |
|
|
roleDb := implement.NewRoleDb(db.DBs[GetMasterId(c)], req.RoleId) |
|
|
roleDb := implement.NewRoleDb(db.DBs[GetMasterId(c)], req.RoleId) |
|
|
role, err := roleDb.GetRole() |
|
|
role, err := roleDb.GetRole() |
|
|
if err != nil { |
|
|
if err != nil { |
|
@@ -112,7 +114,7 @@ func RoleBindPermissionGroup(c *gin.Context, req md.RoleBindPermissionGroupReq) |
|
|
return errors.New("未查询到相应记录") |
|
|
return errors.New("未查询到相应记录") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//1、删除 `role_permission_group` |
|
|
|
|
|
|
|
|
// 1、删除 `role_permission_group` |
|
|
rolePermissionGroupDb := implement.NewRolePermissionGroupDb(db.DBs[GetMasterId(c)]) |
|
|
rolePermissionGroupDb := implement.NewRolePermissionGroupDb(db.DBs[GetMasterId(c)]) |
|
|
_, err = rolePermissionGroupDb.RolePermissionGroupDeleteForRoleBySession(session, req.RoleId) |
|
|
_, err = rolePermissionGroupDb.RolePermissionGroupDeleteForRoleBySession(session, req.RoleId) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@@ -120,7 +122,7 @@ func RoleBindPermissionGroup(c *gin.Context, req md.RoleBindPermissionGroupReq) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//2、新增 `role_permission_group`` |
|
|
|
|
|
|
|
|
// 2、新增 `role_permission_group`` |
|
|
var mm []*model.RolePermissionGroup |
|
|
var mm []*model.RolePermissionGroup |
|
|
now := time.Now() |
|
|
now := time.Now() |
|
|
for _, v := range req.PermissionIds { |
|
|
for _, v := range req.PermissionIds { |
|
@@ -141,10 +143,11 @@ func RoleBindPermissionGroup(c *gin.Context, req md.RoleBindPermissionGroupReq) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func BindAdminRole(c *gin.Context, req md.BindAdminRoleReq) (err error) { |
|
|
func BindAdminRole(c *gin.Context, req md.BindAdminRoleReq) (err error) { |
|
|
session := db.Db.NewSession() |
|
|
|
|
|
|
|
|
engine := db.DBs[GetMasterId(c)] |
|
|
|
|
|
session := engine.NewSession() |
|
|
defer session.Close() |
|
|
defer session.Close() |
|
|
session.Begin() |
|
|
session.Begin() |
|
|
//1、查询 `role` |
|
|
|
|
|
|
|
|
// 1、查询 `role` |
|
|
adminDb := implement.NewAdminDb(db.DBs[GetMasterId(c)]) |
|
|
adminDb := implement.NewAdminDb(db.DBs[GetMasterId(c)]) |
|
|
role, err := adminDb.GetAdmin(req.AdmId) |
|
|
role, err := adminDb.GetAdmin(req.AdmId) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@@ -154,7 +157,7 @@ func BindAdminRole(c *gin.Context, req md.BindAdminRoleReq) (err error) { |
|
|
return errors.New("未查询到相应记录") |
|
|
return errors.New("未查询到相应记录") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//1、删除 `admin_role` |
|
|
|
|
|
|
|
|
// 1、删除 `admin_role` |
|
|
adminRoleDb := implement.NewAdminRoleDb(db.DBs[GetMasterId(c)]) |
|
|
adminRoleDb := implement.NewAdminRoleDb(db.DBs[GetMasterId(c)]) |
|
|
_, err = adminRoleDb.AdminRoleDeleteBySession(session, req.AdmId) |
|
|
_, err = adminRoleDb.AdminRoleDeleteBySession(session, req.AdmId) |
|
|
if err != nil { |
|
|
if err != nil { |
|
@@ -162,7 +165,7 @@ func BindAdminRole(c *gin.Context, req md.BindAdminRoleReq) (err error) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//2、新增 `删除 `admin_role`` |
|
|
|
|
|
|
|
|
// 2、新增 `删除 `admin_role`` |
|
|
var mm []*model.AdminRole |
|
|
var mm []*model.AdminRole |
|
|
now := time.Now() |
|
|
now := time.Now() |
|
|
for _, v := range req.RoleIds { |
|
|
for _, v := range req.RoleIds { |
|
|