|
123456789101112131415161718192021222324252627282930313233 |
- package mw
-
- import (
- "applet/app/e"
- "applet/app/enum"
- "applet/app/md"
- "applet/app/svc"
- "applet/app/utils"
- "fmt"
- "github.com/gin-gonic/gin"
- )
-
- // CheckPermission 检查权限
- func CheckPermission(c *gin.Context) {
- admin := svc.GetUser(c)
-
- // TODO::判断是否为超管
- if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
- c.Next()
- } else {
- rolePermissionKey := fmt.Sprintf(md.AdminRolePermissionKey, utils.AnyToString(admin.AdmId))
- isHasPermission, err := svc.CheckUserRole(c, rolePermissionKey, c.Request.RequestURI, admin.AdmId)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- if !isHasPermission {
- e.OutErr(c, e.ERR_FORBIDEN, "当前用户暂未拥有该路由权限,请联系管理员")
- return
- }
- c.Next()
- }
- }
|