feat: system manager.

This commit is contained in:
2026-04-29 08:41:23 +08:00
parent ea44ea0153
commit 77e7a612fc
6 changed files with 590 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
package middleware
import (
"hr_receiver/models"
"net/http"
"github.com/gin-gonic/gin"
)
func RequireSuperAdmin() gin.HandlerFunc {
return func(c *gin.Context) {
roleValue, exists := c.Get("role")
if !exists {
c.JSON(http.StatusForbidden, gin.H{"error": "missing user role"})
c.Abort()
return
}
role, ok := roleValue.(models.UserRole)
if !ok {
c.JSON(http.StatusForbidden, gin.H{"error": "invalid user role"})
c.Abort()
return
}
if role != models.UserRoleSuperAdmin {
c.JSON(http.StatusForbidden, gin.H{"error": "super admin required"})
c.Abort()
return
}
c.Next()
}
}