mirror of
https://github.com/veops/oneterm.git
synced 2026-09-03 07:25:15 +08:00
feat(backend): filter sensitive fields for non-admin users in account list API
This commit is contained in:
@@ -7,6 +7,7 @@ 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/service"
|
||||
"github.com/veops/oneterm/pkg/config"
|
||||
@@ -41,6 +42,20 @@ var (
|
||||
func(ctx *gin.Context, data []*model.Account) {
|
||||
accountService.DecryptSensitiveData(data)
|
||||
},
|
||||
// Filter sensitive fields for non-admin users
|
||||
func(ctx *gin.Context, data []*model.Account) {
|
||||
info := cast.ToBool(ctx.Query("info"))
|
||||
if !info {
|
||||
currentUser, _ := acl.GetSessionFromCtx(ctx)
|
||||
if !acl.IsAdmin(currentUser) {
|
||||
for _, account := range data {
|
||||
account.Password = ""
|
||||
account.Pk = ""
|
||||
account.Phrase = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
accountDcs = []deleteCheck{
|
||||
|
||||
Reference in New Issue
Block a user