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:
mrchatamandmrchatam authored and GitHub committed 2026-09-12 11:13:42 +02:00 Unverified
1 parent 8082ab4d74
commit 5fbd2b490c
7 files changed
+221 -14

No files matched your search

+17 -4
View File
@@ -80,15 +80,28 @@ type clientPayloadWithHwid struct {
func (p *ClientCreatePayload) UnmarshalJSON(data []byte) error {
var raw struct {
Client clientPayloadWithHwid `json:"client"`
InboundIds []int `json:"inboundIds"`
Client json.RawMessage `json:"client"`
InboundIds []int `json:"inboundIds"`
}
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
p.Client = raw.Client.Client
var withHwid clientPayloadWithHwid
if len(raw.Client) > 0 {
if err := json.Unmarshal(raw.Client, &withHwid); err != nil {
return err
}
}
p.Client = withHwid.Client
p.InboundIds = raw.InboundIds
p.LimitHwid = raw.Client.LimitHwid
p.LimitHwid = withHwid.LimitHwid
// Omit enable → true (legacy API); explicit false is preserved (#6478).
var keys map[string]json.RawMessage
if len(raw.Client) > 0 && json.Unmarshal(raw.Client, &keys) == nil {
if _, ok := keys["enable"]; !ok {
p.Client.Enable = true
}
}
return nil
}
+1 -3
View File
@@ -1324,9 +1324,7 @@ func (s *ClientService) BulkCreate(inboundSvc *InboundService, payloads []Client
if client.SubID == "" {
client.SubID = uuid.NewString()
}
if !client.Enable {
client.Enable = true
}
// Preserve enable (omit→true in UnmarshalJSON; explicit false kept) (#6478).
now := time.Now().UnixMilli()
if client.CreatedAt == 0 {
client.CreatedAt = now
+1 -3
View File
@@ -154,9 +154,7 @@ func (s *ClientService) Create(inboundSvc *InboundService, payload *ClientCreate
if client.SubID == "" {
client.SubID = uuid.NewString()
}
if !client.Enable {
client.Enable = true
}
// Enable: omit defaults true via ClientCreatePayload.UnmarshalJSON; explicit false kept.
now := time.Now().UnixMilli()
if client.CreatedAt == 0 {
client.CreatedAt = now
Loaded 3 of 7 files, more files were not shown because too many files have changed in this diff. Show more