29 lines
567 B
Go
29 lines
567 B
Go
package middleware
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"filestoragesystem/internal/utils"
|
|
)
|
|
|
|
// RequirePermission 权限检查中间件;super_admin拥有全部权限
|
|
func RequirePermission(code string) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
perms, ok := c.Get(CtxPermissions)
|
|
if !ok {
|
|
utils.Unauthorized(c, "未认证")
|
|
return
|
|
}
|
|
m, ok := perms.(map[string]bool)
|
|
if !ok {
|
|
utils.Forbidden(c, "权限信息异常")
|
|
return
|
|
}
|
|
if m["*"] || m[code] {
|
|
c.Next()
|
|
return
|
|
}
|
|
utils.Forbidden(c, "没有操作权限: "+code)
|
|
}
|
|
}
|