广告平台(站长使用)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mw_admin_permission.go 1.2 KiB

2 月之前
2 月之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package mw
  2. import (
  3. "applet/app/e"
  4. "applet/app/enum"
  5. "applet/app/md"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. "fmt"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // CheckPermission 检查权限
  12. func CheckPermission(c *gin.Context) {
  13. admin := svc.GetUser(c)
  14. masterId := svc.GetMasterId(c)
  15. if c.GetBool("is_open") {
  16. rolePermissionKey := fmt.Sprintf(md.AdminRolePermissionByOpenKey, masterId)
  17. isHasPermission, err := svc.CheckUserRoleByOpen(c, rolePermissionKey, c.Request.RequestURI, utils.StrToInt(masterId))
  18. if err != nil {
  19. e.OutErr(c, e.ERR, err.Error())
  20. return
  21. }
  22. if !isHasPermission {
  23. e.OutErr(c, e.ERR_FORBIDEN, "当前用户暂未拥有该路由权限,请联系管理员")
  24. return
  25. }
  26. c.Next()
  27. }
  28. // TODO::判断是否为超管
  29. if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
  30. c.Next()
  31. } else {
  32. rolePermissionKey := fmt.Sprintf(md.AdminRolePermissionKey, masterId, utils.AnyToString(admin.AdmId))
  33. isHasPermission, err := svc.CheckUserRole(c, rolePermissionKey, c.Request.RequestURI, admin.AdmId)
  34. if err != nil {
  35. e.OutErr(c, e.ERR, err.Error())
  36. return
  37. }
  38. if !isHasPermission {
  39. e.OutErr(c, e.ERR_FORBIDEN, "当前用户暂未拥有该路由权限,请联系管理员")
  40. return
  41. }
  42. c.Next()
  43. }
  44. }