Browse Source

Merge remote-tracking branch 'origin/master'

master
huangjiajun 1 month ago
parent
commit
0ba7ca0dd0
2 changed files with 21 additions and 18 deletions
  1. +1
    -1
      app/lib/wechat/wechat_api.go
  2. +20
    -17
      app/svc/svc_role.go

+ 1
- 1
app/lib/wechat/wechat_api.go View File

@@ -35,7 +35,7 @@ func NewWxApiService(masterId, componentAppid, componentAppsecret string) (wxApi
if !cfg.Local {
return wxApiService, errors.New("微信验证票据ticket未获取到")
}
cacheComponentVerifyTicket = "ticket@@@5zpNCmCMQuTwW6SK65tKlbGvbdahQfkFvxL7KZwh8iO_bywglIDFqB_lemyXZ2zC5LK0sFVJ4ZWlbGtiwUpIzA"
cacheComponentVerifyTicket = "ticket@@@UFKPikftQ8YmNuw0tGT3LsHrpD08Y3c2XtaImAAs2ID2SPLtq2i1-PDzwOpbCPebRjlC8qyOm-djUOyL-_HXzA"
}
wxApiService.ComponentVerifyTicket = cacheComponentVerifyTicket
return


+ 20
- 17
app/svc/svc_role.go View File

@@ -16,20 +16,20 @@ import (
)

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
var rolePermission []string
var rolePermissionString string
rolePermissionString, _ = cache.GetString(cacheKey)

//TODO::判断是否在白名单中
// TODO::判断是否在白名单中
if utils.InArr(uri, md.WhiteUri) {
isHasPermission = true
return
}

if rolePermissionString != "" {
//if false {
// if false {
if err = json.Unmarshal([]byte(rolePermissionString), &rolePermission); err != nil {
return
}
@@ -53,7 +53,7 @@ func CheckUserRole(c *gin.Context, cacheKey, uri string, admId int) (isHasPermis
if utils.InArr(uri, rolePermission) {
isHasPermission = true
} else {
//正则匹配占位符情况
// 正则匹配占位符情况
compileRegex := regexp.MustCompile("[0-9]+")
matchArr := compileRegex.FindAllString(uri, -1)
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) {
session := db.Db.NewSession()
engine := db.DBs[GetMasterId(c)]
session := engine.NewSession()
defer session.Close()
session.Begin()

//1、删除 `role`
roleDb := implement.NewRoleDb(db.DBs[GetMasterId(c)], roleId)
// 1、删除 `role`
roleDb := implement.NewRoleDb(engine, roleId)
_, err = roleDb.RoleDeleteBySession(session, roleId)
if err != nil {
_ = session.Rollback()
return
}

//2、删除 `role_permission_group`
// 2、删除 `role_permission_group`
rolePermissionGroupDb := implement.NewRolePermissionGroupDb(db.DBs[GetMasterId(c)])
_, err = rolePermissionGroupDb.RolePermissionGroupDeleteForRoleBySession(session, roleId)
if err != nil {
@@ -87,7 +88,7 @@ func DeleteRole(c *gin.Context, roleId int) (err error) {
return
}

//3、删除 `admin_role`
// 3、删除 `admin_role`
adminRoleDb := implement.NewAdminRoleDb(db.DBs[GetMasterId(c)])
_, err = adminRoleDb.AdminRoleDeleteForRoleBySession(session, roleId)
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) {
session := db.Db.NewSession()
engine := db.DBs[GetMasterId(c)]
session := engine.NewSession()
defer session.Close()
session.Begin()
//1、查询 `role`
// 1、查询 `role`
roleDb := implement.NewRoleDb(db.DBs[GetMasterId(c)], req.RoleId)
role, err := roleDb.GetRole()
if err != nil {
@@ -112,7 +114,7 @@ func RoleBindPermissionGroup(c *gin.Context, req md.RoleBindPermissionGroupReq)
return errors.New("未查询到相应记录")
}

//1、删除 `role_permission_group`
// 1、删除 `role_permission_group`
rolePermissionGroupDb := implement.NewRolePermissionGroupDb(db.DBs[GetMasterId(c)])
_, err = rolePermissionGroupDb.RolePermissionGroupDeleteForRoleBySession(session, req.RoleId)
if err != nil {
@@ -120,7 +122,7 @@ func RoleBindPermissionGroup(c *gin.Context, req md.RoleBindPermissionGroupReq)
return
}

//2、新增 `role_permission_group``
// 2、新增 `role_permission_group``
var mm []*model.RolePermissionGroup
now := time.Now()
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) {
session := db.Db.NewSession()
engine := db.DBs[GetMasterId(c)]
session := engine.NewSession()
defer session.Close()
session.Begin()
//1、查询 `role`
// 1、查询 `role`
adminDb := implement.NewAdminDb(db.DBs[GetMasterId(c)])
role, err := adminDb.GetAdmin(req.AdmId)
if err != nil {
@@ -154,7 +157,7 @@ func BindAdminRole(c *gin.Context, req md.BindAdminRoleReq) (err error) {
return errors.New("未查询到相应记录")
}

//1、删除 `admin_role`
// 1、删除 `admin_role`
adminRoleDb := implement.NewAdminRoleDb(db.DBs[GetMasterId(c)])
_, err = adminRoleDb.AdminRoleDeleteBySession(session, req.AdmId)
if err != nil {
@@ -162,7 +165,7 @@ func BindAdminRole(c *gin.Context, req md.BindAdminRoleReq) (err error) {
return
}

//2、新增 `删除 `admin_role``
// 2、新增 `删除 `admin_role``
var mm []*model.AdminRole
now := time.Now()
for _, v := range req.RoleIds {


Loading…
Cancel
Save