mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-10 13:21:00 +00:00
fix(clients): persist group for node-inbound clients
The client create/edit form left `group` out of the request payload, so choosing a group in the form was silently dropped (bulkAdd from the Groups page still worked because it writes the column directly). Add `group` to the payload next to `comment`. SyncInbound also overwrote group_name unconditionally; a group set via bulkAdd is never pushed to the node, so the next node snapshot — which lacks it — wiped the column. Keep group sticky (only overwrite when the incoming value is non-empty); group is only ever set/cleared via the Groups page. Preserve comment for node clients during snapshot sync the same way. Add tests.
This commit is contained in:
@@ -1589,6 +1589,32 @@ func (s *InboundService) setRemoteTrafficLocked(nodeID int, snap *runtime.Traffi
|
||||
}
|
||||
filtered = append(filtered, clients[i])
|
||||
}
|
||||
localEmails := make([]string, 0, len(filtered))
|
||||
for i := range filtered {
|
||||
if filtered[i].Email != "" {
|
||||
localEmails = append(localEmails, filtered[i].Email)
|
||||
}
|
||||
}
|
||||
if len(localEmails) > 0 {
|
||||
var localMeta []struct {
|
||||
Email string
|
||||
Comment string `gorm:"column:comment"`
|
||||
}
|
||||
if err := tx.Table("clients").
|
||||
Select("email, comment").
|
||||
Where("email IN ?", localEmails).
|
||||
Find(&localMeta).Error; err == nil {
|
||||
commentByEmail := make(map[string]string, len(localMeta))
|
||||
for _, m := range localMeta {
|
||||
commentByEmail[m.Email] = m.Comment
|
||||
}
|
||||
for i := range filtered {
|
||||
if cmt, ok := commentByEmail[filtered[i].Email]; ok {
|
||||
filtered[i].Comment = cmt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := s.clientService.SyncInbound(tx, c.Id, filtered); err != nil {
|
||||
logger.Warningf("setRemoteTraffic: sync clients for tag %q failed: %v", snapIb.Tag, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user