广告平台(总站长使用)
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

mw_admin_permission.go 817 B

pirms 2 mēnešiem
123456789101112131415161718192021222324252627282930313233
  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. // TODO::判断是否为超管
  16. if admin.IsSuperAdministrator == enum.IsSuperAdministratorTure {
  17. c.Next()
  18. } else {
  19. rolePermissionKey := fmt.Sprintf(md.AdminRolePermissionKey, masterId, utils.AnyToString(admin.AdmId))
  20. isHasPermission, err := svc.CheckUserRole(c, rolePermissionKey, c.Request.RequestURI, admin.AdmId)
  21. if err != nil {
  22. e.OutErr(c, e.ERR, err.Error())
  23. return
  24. }
  25. if !isHasPermission {
  26. e.OutErr(c, e.ERR_FORBIDEN, "当前用户暂未拥有该路由权限,请联系管理员")
  27. return
  28. }
  29. c.Next()
  30. }
  31. }