mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	修复用户无法修改关联集群的Bug
This commit is contained in:
		@@ -1205,19 +1205,10 @@ func (this *ServerDAO) CheckUserServer(tx *dbs.Tx, userId int64, serverId int64)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateUserServersClusterId 设置一个用户下的所有服务的所属集群
 | 
					// UpdateUserServersClusterId 设置一个用户下的所有服务的所属集群
 | 
				
			||||||
func (this *ServerDAO) UpdateUserServersClusterId(tx *dbs.Tx, userId int64, clusterId int64) error {
 | 
					func (this *ServerDAO) UpdateUserServersClusterId(tx *dbs.Tx, userId int64, oldClusterId, newClusterId int64) error {
 | 
				
			||||||
	// 之前的cluster
 | 
						_, err := this.Query(tx).
 | 
				
			||||||
	oldClusterId, err := SharedUserDAO.FindUserClusterId(tx, userId)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if oldClusterId == clusterId {
 | 
					 | 
				
			||||||
		return nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	_, err = this.Query(tx).
 | 
					 | 
				
			||||||
		Attr("userId", userId).
 | 
							Attr("userId", userId).
 | 
				
			||||||
		Set("clusterId", clusterId).
 | 
							Set("clusterId", newClusterId).
 | 
				
			||||||
		Update()
 | 
							Update()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
@@ -1232,14 +1223,22 @@ func (this *ServerDAO) UpdateUserServersClusterId(tx *dbs.Tx, userId int64, clus
 | 
				
			|||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
							err = dns.SharedDNSTaskDAO.CreateClusterTask(tx, oldClusterId, dns.DNSTaskTypeClusterChange)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if clusterId > 0 {
 | 
					 | 
				
			||||||
		err = SharedNodeTaskDAO.CreateClusterTask(tx, clusterId, NodeTaskTypeConfigChanged)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		err = SharedNodeTaskDAO.CreateClusterTask(tx, clusterId, NodeTaskTypeIPItemChanged)
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if newClusterId > 0 {
 | 
				
			||||||
 | 
							err = SharedNodeTaskDAO.CreateClusterTask(tx, newClusterId, NodeTaskTypeConfigChanged)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							err = SharedNodeTaskDAO.CreateClusterTask(tx, newClusterId, NodeTaskTypeIPItemChanged)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							err = dns.SharedDNSTaskDAO.CreateClusterTask(tx, newClusterId, dns.DNSTaskTypeClusterChange)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -108,7 +108,7 @@ func (this *UserDAO) CreateUser(tx *dbs.Tx, username string, password string, fu
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateUser 修改用户
 | 
					// UpdateUser 修改用户
 | 
				
			||||||
func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, password string, fullname string, mobile string, tel string, email string, remark string, isOn bool, clusterId int64) error {
 | 
					func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, password string, fullname string, mobile string, tel string, email string, remark string, isOn bool, nodeClusterId int64) error {
 | 
				
			||||||
	if userId <= 0 {
 | 
						if userId <= 0 {
 | 
				
			||||||
		return errors.New("invalid userId")
 | 
							return errors.New("invalid userId")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -123,8 +123,8 @@ func (this *UserDAO) UpdateUser(tx *dbs.Tx, userId int64, username string, passw
 | 
				
			|||||||
	op.Tel = tel
 | 
						op.Tel = tel
 | 
				
			||||||
	op.Email = email
 | 
						op.Email = email
 | 
				
			||||||
	op.Remark = remark
 | 
						op.Remark = remark
 | 
				
			||||||
 | 
						op.ClusterId = nodeClusterId
 | 
				
			||||||
	op.IsOn = isOn
 | 
						op.IsOn = isOn
 | 
				
			||||||
	op.ClusterId = clusterId
 | 
					 | 
				
			||||||
	err := this.Save(tx, op)
 | 
						err := this.Save(tx, op)
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,7 +53,7 @@ func (this *UserService) UpdateUser(ctx context.Context, req *pb.UpdateUserReque
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if oldClusterId != req.NodeClusterId {
 | 
						if oldClusterId != req.NodeClusterId {
 | 
				
			||||||
		err = models.SharedServerDAO.UpdateUserServersClusterId(tx, req.UserId, req.NodeClusterId)
 | 
							err = models.SharedServerDAO.UpdateUserServersClusterId(tx, req.UserId, oldClusterId, req.NodeClusterId)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user