fix(clients): keep a hand-disabled client off through auto-renew

autoRenewClients re-enabled every renewing client whose traffic row was
off, as if only the panel's quota and expiry check cleared that flag.
The operator's disable routes (the client editor and bulk disable)
clear it too, so a client disabled by hand came back on with a fresh
period and zeroed counters as soon as its Auto Renew period ended.

A renewal now restores only a client the lifecycle job switched off:
its quota is spent, counting cross-panel usage, or its record was
stamped at or after its deadline, which the job does and a disable of a
live client cannot.
This commit is contained in:
MHSanaei
2026-11-01 08:23:48 +01:00
parent 30f17ef5a3
commit 67820dc20d
3 changed files with 130 additions and 6 deletions
+29
View File
@@ -288,3 +288,32 @@ func (s *InboundService) DepletedClientEmails(emails []string) (map[string]struc
}
return depleted, nil
}
// lifecycleDisabledEmails picks, out of switched-off stats rows, the ones that
// disableInvalidClients cleared; an operator's disable clears the flag as well.
func lifecycleDisabledEmails(tx *gorm.DB, rows []xray.ClientTraffic) (map[string]struct{}, error) {
emails := make([]string, 0, len(rows))
for i := range rows {
emails = append(emails, rows[i].Email)
}
records, err := clientRecordsByEmail(tx, emails)
if err != nil {
return nil, err
}
// Cross-panel usage depletes too (depletedClientsCond); the overlay raises
// the counters in place, so callers hand it copies.
overlayGlobalTrafficValues(tx, rows)
disabled := make(map[string]struct{}, len(rows))
for i := range rows {
r := &rows[i]
depleted := r.Total > 0 && r.Up+r.Down >= r.Total
// The job stamps the record once the deadline has passed (whole seconds
// is all a stamp pushed to a node keeps); an operator's disable came earlier.
record := records[r.Email]
expired := record != nil && r.ExpiryTime > 0 && record.UpdatedAt >= r.ExpiryTime/1000*1000
if depleted || expired {
disabled[r.Email] = struct{}{}
}
}
return disabled, nil
}