mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	增加修改服务所在分组API
This commit is contained in:
		@@ -19,7 +19,7 @@ const (
 | 
				
			|||||||
	// 其他节点版本号,用来检测是否有需要升级的节点
 | 
						// 其他节点版本号,用来检测是否有需要升级的节点
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	NodeVersion          = "0.4.9"
 | 
						NodeVersion          = "0.4.9"
 | 
				
			||||||
	UserNodeVersion      = "0.3.4"
 | 
						UserNodeVersion      = "0.3.5"
 | 
				
			||||||
	AuthorityNodeVersion = "0.0.2"
 | 
						AuthorityNodeVersion = "0.0.2"
 | 
				
			||||||
	MonitorNodeVersion   = "0.0.4"
 | 
						MonitorNodeVersion   = "0.0.4"
 | 
				
			||||||
	DNSNodeVersion       = "0.2.3"
 | 
						DNSNodeVersion       = "0.2.3"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -338,12 +338,31 @@ func (this *ServerDAO) UpdateServerBasic(tx *dbs.Tx, serverId int64, name string
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// UpdateServerGroupIds 修改服务所在分组
 | 
				
			||||||
 | 
					func (this *ServerDAO) UpdateServerGroupIds(tx *dbs.Tx, serverId int64, groupIds []int64) error {
 | 
				
			||||||
 | 
						if groupIds == nil {
 | 
				
			||||||
 | 
							groupIds = []int64{}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						groupIdsJSON, err := json.Marshal(groupIds)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						err = this.Query(tx).
 | 
				
			||||||
 | 
							Pk(serverId).
 | 
				
			||||||
 | 
							Set("groupIds", groupIdsJSON).
 | 
				
			||||||
 | 
							UpdateQuickly()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return this.NotifyUpdate(tx, serverId)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateUserServerBasic 设置用户相关的基本信息
 | 
					// UpdateUserServerBasic 设置用户相关的基本信息
 | 
				
			||||||
func (this *ServerDAO) UpdateUserServerBasic(tx *dbs.Tx, serverId int64, name string) error {
 | 
					func (this *ServerDAO) UpdateUserServerBasic(tx *dbs.Tx, serverId int64, name string) error {
 | 
				
			||||||
	if serverId <= 0 {
 | 
						if serverId <= 0 {
 | 
				
			||||||
		return errors.New("serverId should not be smaller than 0")
 | 
							return errors.New("serverId should not be smaller than 0")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	op := NewServerOperator()
 | 
						var op = NewServerOperator()
 | 
				
			||||||
	op.Id = serverId
 | 
						op.Id = serverId
 | 
				
			||||||
	op.Name = name
 | 
						op.Name = name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -410,6 +410,17 @@ func (this *ServerGroupDAO) CheckUserGroup(tx *dbs.Tx, userId int64, groupId int
 | 
				
			|||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ExistsGroup 检查分组ID是否存在
 | 
				
			||||||
 | 
					func (this *ServerGroupDAO) ExistsGroup(tx *dbs.Tx, groupId int64) (bool, error) {
 | 
				
			||||||
 | 
						if groupId <= 0 {
 | 
				
			||||||
 | 
							return false, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return this.Query(tx).
 | 
				
			||||||
 | 
							Pk(groupId).
 | 
				
			||||||
 | 
							State(ServerGroupStateEnabled).
 | 
				
			||||||
 | 
							Exist()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NotifyUpdate 通知更新
 | 
					// NotifyUpdate 通知更新
 | 
				
			||||||
func (this *ServerGroupDAO) NotifyUpdate(tx *dbs.Tx, groupId int64) error {
 | 
					func (this *ServerGroupDAO) NotifyUpdate(tx *dbs.Tx, groupId int64) error {
 | 
				
			||||||
	serverIds, err := SharedServerDAO.FindAllEnabledServerIdsWithGroupId(tx, groupId)
 | 
						serverIds, err := SharedServerDAO.FindAllEnabledServerIdsWithGroupId(tx, groupId)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -192,6 +192,56 @@ func (this *ServerService) UpdateServerBasic(ctx context.Context, req *pb.Update
 | 
				
			|||||||
	return this.Success()
 | 
						return this.Success()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// UpdateServerGroupIds 修改服务所在分组
 | 
				
			||||||
 | 
					func (this *ServerService) UpdateServerGroupIds(ctx context.Context, req *pb.UpdateServerGroupIdsRequest) (*pb.RPCSuccess, error) {
 | 
				
			||||||
 | 
						_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var tx = this.NullTx()
 | 
				
			||||||
 | 
						if userId > 0 {
 | 
				
			||||||
 | 
							err = models.SharedServerDAO.CheckUserServer(tx, userId, req.ServerId)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 检查分组IDs
 | 
				
			||||||
 | 
						for _, groupId := range req.ServerGroupIds {
 | 
				
			||||||
 | 
							if userId > 0 {
 | 
				
			||||||
 | 
								err = models.SharedServerGroupDAO.CheckUserGroup(tx, userId, groupId)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return nil, err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								b, err := models.SharedServerGroupDAO.ExistsGroup(tx, groupId)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return nil, err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if !b {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 增加默认分组
 | 
				
			||||||
 | 
						if userId > 0 {
 | 
				
			||||||
 | 
							config, err := models.SharedSysSettingDAO.ReadUserServerConfig(tx)
 | 
				
			||||||
 | 
							if err == nil && config.GroupId > 0 && !lists.ContainsInt64(req.ServerGroupIds, config.GroupId) {
 | 
				
			||||||
 | 
								req.ServerGroupIds = append(req.ServerGroupIds, config.GroupId)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 修改
 | 
				
			||||||
 | 
						err = models.SharedServerDAO.UpdateServerGroupIds(tx, req.ServerId, req.ServerGroupIds)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return this.Success()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateServerIsOn 修改服务是否启用
 | 
					// UpdateServerIsOn 修改服务是否启用
 | 
				
			||||||
func (this *ServerService) UpdateServerIsOn(ctx context.Context, req *pb.UpdateServerIsOnRequest) (*pb.RPCSuccess, error) {
 | 
					func (this *ServerService) UpdateServerIsOn(ctx context.Context, req *pb.UpdateServerIsOnRequest) (*pb.RPCSuccess, error) {
 | 
				
			||||||
	_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
 | 
						_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
 | 
				
			||||||
@@ -199,7 +249,7 @@ func (this *ServerService) UpdateServerIsOn(ctx context.Context, req *pb.UpdateS
 | 
				
			|||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tx := this.NullTx()
 | 
						var tx = this.NullTx()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if userId > 0 {
 | 
						if userId > 0 {
 | 
				
			||||||
		err = models.SharedServerDAO.CheckUserServer(tx, userId, req.ServerId)
 | 
							err = models.SharedServerDAO.CheckUserServer(tx, userId, req.ServerId)
 | 
				
			||||||
@@ -834,6 +884,7 @@ func (this *ServerService) FindEnabledServer(ctx context.Context, req *pb.FindEn
 | 
				
			|||||||
			pbGroups = append(pbGroups, &pb.ServerGroup{
 | 
								pbGroups = append(pbGroups, &pb.ServerGroup{
 | 
				
			||||||
				Id:     int64(group.Id),
 | 
									Id:     int64(group.Id),
 | 
				
			||||||
				Name:   group.Name,
 | 
									Name:   group.Name,
 | 
				
			||||||
 | 
									UserId: int64(group.UserId),
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user