check_chart_auth.go 953 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package middleware
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "hongze/hongze_yb/controller/response"
  5. "hongze/hongze_yb/services/company"
  6. "hongze/hongze_yb/services/user"
  7. )
  8. // CheckChartAuth 图库权限验证
  9. func CheckChartAuth() gin.HandlerFunc {
  10. return func(c *gin.Context) {
  11. userInfo := user.GetInfoByClaims(c)
  12. // 是否为内部员工
  13. ok, _, err := user.GetAdminByUserInfo(userInfo)
  14. if err != nil {
  15. response.FailMsg("图库权限验证失败", "获取系统用户信息失败" + err.Error(), c)
  16. c.Abort()
  17. return
  18. }
  19. if !ok {
  20. checkOk, permissionCheckInfo, tempErr := company.CheckUserChartPermission(userInfo.CompanyID, int(userInfo.UserID))
  21. if tempErr != nil {
  22. response.FailMsg("图库权限验证失败", "图库权限验证失败" + tempErr.Error(), c)
  23. c.Abort()
  24. return
  25. }
  26. if !checkOk {
  27. response.AuthError(permissionCheckInfo, "暂无权限", c)
  28. c.Abort()
  29. return
  30. }
  31. }
  32. c.Next()
  33. }
  34. }