refactor(backend): authorization v2

This commit is contained in:
pycook
2025-07-16 18:11:04 +08:00
parent d8387323dd
commit 7e2c667fc4
48 changed files with 10593 additions and 554 deletions

View File

@@ -8,7 +8,6 @@ import (
"github.com/samber/lo"
"github.com/spf13/cast"
"github.com/veops/oneterm/internal/acl"
"github.com/veops/oneterm/internal/model"
"github.com/veops/oneterm/internal/repository"
"github.com/veops/oneterm/internal/service"
@@ -82,16 +81,21 @@ func (c *Controller) UpdateNode(ctx *gin.Context) {
// @Success 200 {object} HttpResponse{data=ListData{list=[]model.Node}}
// @Router /node [get]
func (c *Controller) GetNodes(ctx *gin.Context) {
currentUser, _ := acl.GetSessionFromCtx(ctx)
info := cast.ToBool(ctx.Query("info"))
recursive := cast.ToBool(ctx.Query("recursive"))
db, err := nodeService.BuildQuery(ctx, currentUser, info)
// Build query with integrated V2 authorization filter
db, err := nodeService.BuildQueryWithAuthorization(ctx)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, &errors.ApiError{Code: errors.ErrInternal, Data: map[string]any{"err": err}})
return
}
// Apply info mode settings
if info {
db = db.Select("id", "parent_id", "name")
}
if recursive {
treeNodes, err := nodeService.GetNodesTree(ctx, db, !info, config.RESOURCE_NODE)
if err != nil {