更新前后端代码
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user