mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6238] [MERGED] feat(clients): cap how many times a client may auto-renew #6193
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6193
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6238
Author: @n0ctal
Created: 8/17/2026
Status: ✅ Merged
Merged: 8/18/2026
Merged by: @MHSanaei
Base:
main← Head:upstream-auto-renew-max-count📝 Commits (4)
f97b683feat(clients): cap how many times a client may auto-renewa5caeaefix(clients): persist the auto-renew cap and stop the capped churn5f3588cfix(clients): let the renewal cap be changed after creation8e3810achore: drop the accidentally committed dist build stub📊 Changes
29 files changed (+508 additions, -27 deletions)
View changed files
📝
frontend/public/openapi.json(+25 -0)📝
frontend/src/generated/examples.ts(+6 -0)📝
frontend/src/generated/schemas.ts(+21 -0)📝
frontend/src/generated/types.ts(+4 -0)📝
frontend/src/generated/zod.ts(+4 -0)📝
frontend/src/pages/clients/ClientBulkAddModal.tsx(+11 -0)📝
frontend/src/pages/clients/ClientFormModal.tsx(+14 -0)📝
frontend/src/pages/clients/ClientInfoModal.tsx(+10 -0)📝
frontend/src/schemas/client.ts(+5 -0)📝
internal/database/model/model.go(+10 -0)📝
internal/web/service/client_crud.go(+16 -0)📝
internal/web/service/client_link.go(+1 -0)📝
internal/web/service/client_paging.go(+2 -0)➕
internal/web/service/inbound_autorenew_maxcount_test.go(+287 -0)📝
internal/web/service/inbound_traffic.go(+23 -1)📝
internal/web/translation/ar-EG.json(+4 -1)📝
internal/web/translation/en-US.json(+4 -1)📝
internal/web/translation/es-ES.json(+4 -1)📝
internal/web/translation/fa-IR.json(+4 -1)📝
internal/web/translation/id-ID.json(+4 -1)...and 9 more files
📄 Description
Closes #5804.
Summary
Auto-renew runs forever. A prepaid or fixed-term client keeps receiving new periods until an operator remembers to switch it off, and there is no way to say "renew this three times, then let it lapse".
This adds a per-client maximum. Zero keeps today's behaviour, so nothing changes for anyone who does not set one.
The part that is easy to get wrong
Renewal catches up: if a client's expiry is three periods in the past, the existing loop advances it until it reaches the present. With a cap, that loop has to stop counting as well as stop renewing, otherwise a client who was away for three cycles receives all three regardless of what the operator paid for — the cap would only apply to clients who happened to be seen every period.
So the catch-up spends one allowance per period and stops at the last period the cap covers. A client capped at two, three periods behind, ends up exactly two periods forward — still expired, and correctly so, rather than jumping to the present.
Behaviour
resetMaxper client, default 0 = unlimited.resetCountrecords how many renewals have fired.Validation
Three tests: a capped client that has spent its allowance is not renewed while its neighbour with one left is; a three-periods-behind client capped at two lands exactly two periods forward and stays expired; a client with no cap renews as before.
Mutation-checked, both halves separately:
renewed count = 2, want 1: only the client with an allowance leftreset count = 4, want the 2 the cap allowedgo build ./...,go vet,golangci-lint,make gen-checkclean; 36 Go packages green; frontend typecheck, eslint and the unit suite green.Risk
Low. The new column defaults to 0 on existing rows, which is "no cap", so upgraded installs behave exactly as before until someone sets a value.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.