mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-04-26 07:05:19 +08:00
[API节点]显示API节点运行日志 [用户]增加可用功能控制
This commit is contained in:
@@ -23,6 +23,7 @@ func init() {
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/update", new(UpdateAction)).
|
||||
Get("/install", new(InstallAction)).
|
||||
Get("/logs", new(LogsAction)).
|
||||
|
||||
EndAll()
|
||||
})
|
||||
|
||||
71
internal/web/actions/default/api/node/logs.go
Normal file
71
internal/web/actions/default/api/node/logs.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type LogsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *LogsAction) Init() {
|
||||
this.Nav("", "node", "log")
|
||||
this.SecondMenu("nodes")
|
||||
}
|
||||
|
||||
func (this *LogsAction) RunGet(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
apiNodeResp, err := this.RPC().APINodeRPC().FindEnabledAPINode(this.AdminContext(), &pb.FindEnabledAPINodeRequest{NodeId: params.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
apiNode := apiNodeResp.Node
|
||||
if apiNode == nil {
|
||||
this.NotFound("apiNode", params.NodeId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["node"] = maps.Map{
|
||||
"id": apiNode.Id,
|
||||
"name": apiNode.Name,
|
||||
}
|
||||
|
||||
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
|
||||
Role: "api",
|
||||
NodeId: params.NodeId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
count := countResp.Count
|
||||
page := this.NewPage(count, 20)
|
||||
|
||||
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
|
||||
NodeId: params.NodeId,
|
||||
Role: "api",
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
|
||||
logs := []maps.Map{}
|
||||
for _, log := range logsResp.NodeLogs {
|
||||
logs = append(logs, maps.Map{
|
||||
"tag": log.Tag,
|
||||
"description": log.Description,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
||||
"level": log.Level,
|
||||
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
|
||||
})
|
||||
}
|
||||
this.Data["logs"] = logs
|
||||
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
this.Show()
|
||||
}
|
||||
78
internal/web/actions/default/users/features.go
Normal file
78
internal/web/actions/default/users/features.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package users
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/users/userutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type FeaturesAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *FeaturesAction) Init() {
|
||||
this.Nav("", "", "feature")
|
||||
}
|
||||
|
||||
func (this *FeaturesAction) RunGet(params struct {
|
||||
UserId int64
|
||||
}) {
|
||||
err := userutils.InitUser(this.Parent(), params.UserId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
featuresResp, err := this.RPC().UserRPC().FindAllUserFeatureDefinitions(this.AdminContext(), &pb.FindAllUserFeatureDefinitionsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
allFeatures := featuresResp.Features
|
||||
|
||||
userFeaturesResp, err := this.RPC().UserRPC().FindUserFeatures(this.AdminContext(), &pb.FindUserFeaturesRequest{UserId: params.UserId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
userFeatureCodes := []string{}
|
||||
for _, userFeature := range userFeaturesResp.Features {
|
||||
userFeatureCodes = append(userFeatureCodes, userFeature.Code)
|
||||
}
|
||||
|
||||
featureMaps := []maps.Map{}
|
||||
for _, feature := range allFeatures {
|
||||
featureMaps = append(featureMaps, maps.Map{
|
||||
"name": feature.Name,
|
||||
"code": feature.Code,
|
||||
"description": feature.Description,
|
||||
"isChecked": lists.ContainsString(userFeatureCodes, feature.Code),
|
||||
})
|
||||
}
|
||||
this.Data["features"] = featureMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *FeaturesAction) RunPost(params struct {
|
||||
UserId int64
|
||||
Codes []string
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo("设置用户 %d 的功能列表", params.UserId)
|
||||
|
||||
_, err := this.RPC().UserRPC().UpdateUserFeatures(this.AdminContext(), &pb.UpdateUserFeaturesRequest{
|
||||
UserId: params.UserId,
|
||||
FeatureCodes: params.Codes,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
@@ -17,6 +17,7 @@ func init() {
|
||||
Get("/user", new(UserAction)).
|
||||
GetPost("/update", new(UpdateAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
GetPost("/features", new(FeaturesAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user