mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 22:26:38 +08:00
299ac30ee4
- Purify core micro-kernel by removing context hardcoded helpers and reverse dependencies - Eliminate init() side effects in infra plugins with reversible lifecycle disposal - Completely isolate plugins by removing cross-plugin imports and using core/contracts - Introduce TaskService and RiskControlService contracts for unified cross-plugin APIs - Regenerate Swagger documentation and update developer guide matrix - Achieve 0 violations in check_cordis_architecture.sh and 100% test pass
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package admin
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"Wavelet/core/contracts"
|
|
"Wavelet/pkg/logger"
|
|
"Wavelet/pkg/response"
|
|
"Wavelet/pkg/trace"
|
|
"Wavelet/pkg/util"
|
|
)
|
|
|
|
// LoginAdminRequired 返回管理员权限校验中间件
|
|
func LoginAdminRequired() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
ctx, span := trace.Start(c.Request.Context(), "LoginAdminRequired")
|
|
defer span.End()
|
|
|
|
user, _ := util.GetFromContext[*contracts.UserDTO](c, contracts.AuthUserObjKey)
|
|
if user == nil {
|
|
response.AbortNotFound(c, AdminRequired)
|
|
return
|
|
}
|
|
|
|
// 如果是通过 Access Token 鉴权,需要检查令牌本身是否具有管理员权限
|
|
if tokenAuth, _ := util.GetFromContext[bool](c, contracts.AuthTokenAuthKey); tokenAuth {
|
|
tokenAdmin, _ := util.GetFromContext[bool](c, contracts.AuthTokenAdminKey)
|
|
if !tokenAdmin {
|
|
response.AbortNotFound(c, TokenAdminRequired)
|
|
return
|
|
}
|
|
}
|
|
|
|
if !user.IsAdmin {
|
|
response.AbortNotFound(c, AdminRequired)
|
|
return
|
|
}
|
|
|
|
logger.InfoF(ctx, "[LoginAdminRequired] %d %s", user.ID, user.Username)
|
|
c.Next()
|
|
}
|
|
}
|