支持套餐相关操作

This commit is contained in:
GoEdgeLab
2021-11-09 15:36:18 +08:00
parent 92a0c7acbc
commit 63a09bb5a6
12 changed files with 294 additions and 23 deletions

View File

@@ -63,8 +63,12 @@ func (this *CreateAction) RunGet(params struct{}) {
func (this *CreateAction) RunPost(params struct {
Name string
Description string
ClusterId int64
GroupIds []int64
UserId int64
UserPlanId int64
ClusterId int64
GroupIds []int64
ServerType string
Addresses string
@@ -86,11 +90,22 @@ func (this *CreateAction) RunPost(params struct {
Field("name", params.Name).
Require("请输入服务名称")
if params.ClusterId <= 0 {
var clusterId = params.ClusterId
// 用户
var userId = params.UserId
clusterIdResp, err := this.RPC().UserRPC().FindUserNodeClusterId(this.AdminContext(), &pb.FindUserNodeClusterIdRequest{UserId: userId})
if err != nil {
this.ErrorPage(err)
return
}
clusterId = clusterIdResp.NodeClusterId
if clusterId <= 0 {
this.Fail("请选择部署的集群")
}
// TODO 验证集群ID
// 套餐
var userPlanId = params.UserPlanId
// 端口地址
var httpConfig *serverconfigs.HTTPProtocolConfig = nil
@@ -260,7 +275,7 @@ func (this *CreateAction) RunPost(params struct {
if len(allServerNames) > 0 {
dupResp, err := this.RPC().ServerRPC().CheckServerNameDuplicationInNodeCluster(this.AdminContext(), &pb.CheckServerNameDuplicationInNodeClusterRequest{
ServerNames: allServerNames,
NodeClusterId: params.ClusterId,
NodeClusterId: clusterId,
})
if err != nil {
this.ErrorPage(err)
@@ -359,13 +374,14 @@ func (this *CreateAction) RunPost(params struct {
}
req := &pb.CreateServerRequest{
UserId: 0,
UserId: userId,
UserPlanId: userPlanId,
AdminId: this.AdminId(),
Type: params.ServerType,
Name: params.Name,
ServerNamesJON: []byte(params.ServerNames),
Description: params.Description,
NodeClusterId: params.ClusterId,
NodeClusterId: clusterId,
IncludeNodesJSON: includeNodesJSON,
ExcludeNodesJSON: excludeNodesJSON,
WebId: webId,

View File

@@ -2,6 +2,7 @@ package servers
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/users"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
@@ -24,6 +25,12 @@ func init() {
GetPost("/addOriginPopup", new(AddOriginPopupAction)).
Get("/serverNamesPopup", new(ServerNamesPopupAction)).
Post("/status", new(StatusAction)).
//
Post("/users/options", new(users.OptionsAction)).
Post("/users/plans", new(users.PlansAction)).
//
EndAll()
})
}

View File

@@ -64,6 +64,36 @@ func (this *IndexAction) RunGet(params struct {
this.Data["user"] = nil
}
// 套餐
var userPlanMap = maps.Map{"id": server.UserPlanId, "dayTo": "", "plan": maps.Map{}}
if server.UserPlanId > 0 {
userPlanResp, err := this.RPC().UserPlanRPC().FindEnabledUserPlan(this.AdminContext(), &pb.FindEnabledUserPlanRequest{UserPlanId: server.UserPlanId})
if err != nil {
this.ErrorPage(err)
return
}
var userPlan = userPlanResp.UserPlan
if userPlan != nil {
planResp, err := this.RPC().PlanRPC().FindEnabledPlan(this.AdminContext(), &pb.FindEnabledPlanRequest{PlanId: userPlan.PlanId})
if err != nil {
this.ErrorPage(err)
return
}
var plan = planResp.Plan
if plan != nil {
userPlanMap = maps.Map{
"id": userPlan.Id,
"dayTo": userPlan.DayTo,
"plan": maps.Map{
"id": plan.Id,
"name": plan.Name,
},
}
}
}
}
this.Data["userPlan"] = userPlanMap
// 集群
clusterId := int64(0)
this.Data["clusterName"] = ""
@@ -123,6 +153,7 @@ func (this *IndexAction) RunPost(params struct {
ClusterId int64
GroupIds []int64
IsOn bool
UserPlanId int64
Must *actions.Must
}) {
@@ -137,6 +168,7 @@ func (this *IndexAction) RunPost(params struct {
this.Fail("请选择部署的集群")
}
// 修改基本信息
_, err := this.RPC().ServerRPC().UpdateServerBasic(this.AdminContext(), &pb.UpdateServerBasicRequest{
ServerId: params.ServerId,
Name: params.Name,
@@ -150,5 +182,17 @@ func (this *IndexAction) RunPost(params struct {
return
}
// 修改套餐
if params.UserPlanId > 0 {
_, err = this.RPC().ServerRPC().UpdateServerUserPlan(this.AdminContext(), &pb.UpdateServerUserPlanRequest{
ServerId: params.ServerId,
UserPlanId: params.UserPlanId,
})
if err != nil {
this.ErrorPage(err)
return
}
}
this.Success()
}

View File

@@ -98,7 +98,7 @@ func (this *LocationHelper) createMenus(serverIdString string, locationIdString
"name": "缓存",
"url": "/servers/server/settings/locations/cache?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "cache",
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Cache != nil && locationConfig.Web.Cache.IsPrior && locationConfig.Web.Cache.IsOn && len(locationConfig.Web.Cache.CacheRefs) > 0,
"isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Cache != nil && locationConfig.Web.Cache.IsPrior && locationConfig.Web.Cache.IsOn,
})
menuItems = append(menuItems, maps.Map{
"name": "访问控制",

View File

@@ -272,7 +272,7 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
"name": "缓存",
"url": "/servers/server/settings/cache?serverId=" + serverIdString,
"isActive": secondMenuItem == "cache",
"isOn": serverConfig.Web != nil && serverConfig.Web.Cache != nil && serverConfig.Web.Cache.IsOn && len(serverConfig.Web.Cache.CacheRefs) > 0,
"isOn": serverConfig.Web != nil && serverConfig.Web.Cache != nil && serverConfig.Web.Cache.IsOn,
})
menuItems = append(menuItems, maps.Map{
"name": "访问控制",

View File

@@ -0,0 +1,37 @@
package users
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type OptionsAction struct {
actionutils.ParentAction
}
func (this *OptionsAction) RunPost(params struct {
Keyword string
}) {
usersResp, err := this.RPC().UserRPC().ListEnabledUsers(this.AdminContext(), &pb.ListEnabledUsersRequest{
Keyword: params.Keyword,
Offset: 0,
Size: 10000, // TODO 改进 <plan-user-selector> 组件
})
if err != nil {
this.ErrorPage(err)
return
}
userMaps := []maps.Map{}
for _, user := range usersResp.Users {
userMaps = append(userMaps, maps.Map{
"id": user.Id,
"fullname": user.Fullname,
"username": user.Username,
})
}
this.Data["users"] = userMaps
this.Success()
}

View File

@@ -0,0 +1,49 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package users
import (
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type PlansAction struct {
actionutils.ParentAction
}
func (this *PlansAction) RunPost(params struct {
UserId int64
ServerId int64
}) {
if !teaconst.IsPlus || params.UserId <= 0 {
this.Data["plans"] = []maps.Map{}
this.Success()
}
// TODO 优化用户套餐查询
userPlansResp, err := this.RPC().UserPlanRPC().FindAllEnabledUserPlansForServer(this.AdminContext(), &pb.FindAllEnabledUserPlansForServerRequest{
UserId: params.UserId,
ServerId: params.ServerId,
})
if err != nil {
this.ErrorPage(err)
return
}
var userPlanMaps = []maps.Map{}
for _, userPlan := range userPlansResp.UserPlans {
if userPlan.Plan == nil {
continue
}
userPlanMaps = append(userPlanMaps, maps.Map{
"id": userPlan.Id,
"name": userPlan.Plan.Name,
"dayTo": userPlan.DayTo,
})
}
this.Data["plans"] = userPlanMaps
this.Success()
}