mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-14 22:56:35 +08:00
优化用户服务整体启用和禁用
This commit is contained in:
@@ -40,6 +40,7 @@ func (this *NodeTaskService) FindNodeTasks(ctx context.Context, req *pb.FindNode
|
||||
Version: int64(task.Version),
|
||||
IsPrimary: primaryNodeId == nodeId,
|
||||
ServerId: int64(task.ServerId),
|
||||
UserId: int64(task.UserId),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -139,6 +140,7 @@ func (this *NodeTaskService) FindNodeClusterTasks(ctx context.Context, req *pb.F
|
||||
Error: task.Error,
|
||||
UpdatedAt: int64(task.UpdatedAt),
|
||||
ServerId: int64(task.ServerId),
|
||||
UserId: int64(task.UserId),
|
||||
Node: &pb.Node{
|
||||
Id: int64(task.NodeId),
|
||||
Name: nodeName,
|
||||
@@ -264,6 +266,7 @@ func (this *NodeTaskService) FindNotifyingNodeTasks(ctx context.Context, req *pb
|
||||
UpdatedAt: int64(task.UpdatedAt),
|
||||
Node: &pb.Node{Id: int64(task.NodeId)},
|
||||
ServerId: int64(task.ServerId),
|
||||
UserId: int64(task.UserId),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1442,7 +1442,7 @@ func (this *ServerService) FindAllEnabledServerNamesWithUserId(ctx context.Conte
|
||||
req.UserId = userId
|
||||
}
|
||||
|
||||
servers, err := models.SharedServerDAO.FindAllEnabledServersWithUserId(tx, req.UserId)
|
||||
servers, err := models.SharedServerDAO.FindAllBasicServersWithUserId(tx, req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1478,7 +1478,7 @@ func (this *ServerService) FindAllUserServers(ctx context.Context, req *pb.FindA
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
servers, err := models.SharedServerDAO.FindAllEnabledServersWithUserId(tx, req.UserId)
|
||||
servers, err := models.SharedServerDAO.FindAllBasicServersWithUserId(tx, req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1498,6 +1498,39 @@ func (this *ServerService) FindAllUserServers(ctx context.Context, req *pb.FindA
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ComposeAllUserServersConfig 查找某个用户下的服务配置
|
||||
func (this *ServerService) ComposeAllUserServersConfig(ctx context.Context, req *pb.ComposeAllUserServersConfigRequest) (*pb.ComposeAllUserServersConfigResponse, error) {
|
||||
_, err := this.ValidateNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
servers, err := models.SharedServerDAO.FindAllAvailableServersWithUserId(tx, req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var configs = []*serverconfigs.ServerConfig{}
|
||||
var cacheMap = utils.NewCacheMap()
|
||||
for _, server := range servers {
|
||||
config, err := models.SharedServerDAO.ComposeServerConfig(tx, server, cacheMap, true, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
configs = append(configs, config)
|
||||
}
|
||||
|
||||
configsJSON, err := json.Marshal(configs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.ComposeAllUserServersConfigResponse{
|
||||
ServersConfigJSON: configsJSON,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FindEnabledUserServerBasic 查找服务基本信息
|
||||
func (this *ServerService) FindEnabledUserServerBasic(ctx context.Context, req *pb.FindEnabledUserServerBasicRequest) (*pb.FindEnabledUserServerBasicResponse, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, true)
|
||||
|
||||
@@ -762,3 +762,40 @@ func (this *UserService) CheckUserOTPWithUsername(ctx context.Context, req *pb.C
|
||||
}
|
||||
return &pb.CheckUserOTPWithUsernameResponse{RequireOTP: otpIsOn}, nil
|
||||
}
|
||||
|
||||
// CheckUserServersState 检查用户服务可用状态
|
||||
func (this *UserService) CheckUserServersState(ctx context.Context, req *pb.CheckUserServersStateRequest) (*pb.CheckUserServersStateResponse, error) {
|
||||
_, err := this.ValidateNode(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
isEnabled, err := models.SharedUserDAO.CheckUserServersEnabled(tx, req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.CheckUserServersStateResponse{
|
||||
IsEnabled: isEnabled,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// RenewUserServersState 更新用户服务可用状态
|
||||
func (this *UserService) RenewUserServersState(ctx context.Context, req *pb.RenewUserServersStateRequest) (*pb.RPCSuccess, error) {
|
||||
_, userId, err := this.ValidateAdminAndUser(ctx, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if userId > 0 {
|
||||
req.UserId = userId
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
err = models.SharedUserDAO.RenewUserServersState(tx, req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return this.Success()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user