2bbf42b741
Remove Agent Desk users, roles, login sessions, tokens, and local permission persistence. Expose the backend as an embeddable ai-agent module with host-provided subject lookup and operation authorization callbacks, and complete the frontend/backend repository split.
26 lines
613 B
Go
26 lines
613 B
Go
package middleware
|
|
|
|
import (
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/httpx"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/services"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func ExternalUserMiddleware(ctx *gin.Context) {
|
|
channel := services.ChannelService.GetEnabledChannel(ctx)
|
|
if channel == nil {
|
|
ctx.JSON(200, httpx.JsonErrorMsg(ctx, "error.e0210"))
|
|
ctx.Abort()
|
|
return
|
|
}
|
|
external, err := services.SubjectService.CurrentExternal(ctx.Request.Context())
|
|
if err != nil {
|
|
ctx.JSON(200, httpx.JsonErrorMsg(ctx, "error.auth.expired"))
|
|
ctx.Abort()
|
|
return
|
|
}
|
|
httpx.SetExternalUser(ctx, external)
|
|
ctx.Next()
|
|
}
|