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 -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
}