fix(clients): preserve enable on portable import (#6481)

* fix(clients): preserve enable on portable import

Stop BulkCreate and orphan ImportClients from forcing enable=true, and
restate Enable=false after GORM Create (clients.enable default:true drops
the zero value). Interactive Create still defaults new clients to enabled.
Fixes #6478.

* fix(clients): respect enable=false on node mirror; omit enable defaults true

---------

Co-authored-by: mrchatam <287639636+mrchatam@users.noreply.github.com>
This commit is contained in:
mrchatam
2026-09-12 12:43:42 +03:30
committed by GitHub
parent 8082ab4d74
commit 5fbd2b490c
7 changed files with 221 additions and 14 deletions
+17 -1
View File
@@ -169,11 +169,27 @@ func (s *ClientService) syncInboundClients(tx *gorm.DB, inboundId int, clients [
}
if len(toCreate) > 0 {
// Capture enable before Create: gorm default:true drops explicit false (#6478).
// Restate disabled rows after CreateInBatches.
wantEnable := make([]bool, len(toCreate))
for i, rec := range toCreate {
wantEnable[i] = rec.Enable
}
if err := tx.CreateInBatches(toCreate, 200).Error; err != nil {
return err
}
for _, rec := range toCreate {
disabledIDs := make([]int, 0)
for i, rec := range toCreate {
idByEmail[rec.Email] = rec.Id
if !wantEnable[i] {
disabledIDs = append(disabledIDs, rec.Id)
}
}
for _, batch := range chunkInts(disabledIDs, sqlInChunk) {
if err := tx.Model(&model.ClientRecord{}).Where("id IN ?", batch).
UpdateColumn("enable", false).Error; err != nil {
return err
}
}
}