Skip to content

feat(admin): adjust a member's uploaded and downloaded totals - #95

Merged
florianjs merged 1 commit into
mainfrom
feat/admin-ratio-edit
Oct 20, 2026
Merged

florianjs merged 1 commit into
mainfrom
feat/admin-ratio-edit

Conversation

@florianjs

Copy link
Copy Markdown
Owner

Summary

Admins can now fix a member's ratio from Admin → Users: a Ratio button on each search result opens a panel to add to or remove from the uploaded and/or downloaded totals.

  • Amount in MB / GB / TB, add or remove, for upload and download independently
  • Required reason, shown in the history
  • Live preview of the resulting uploaded, downloaded and ratio before applying
  • History of the last 20 corrections: date, deltas, reason, admin

How it works

  • POST /api/admin/users/:id/stats { uploadedDelta, downloadedDelta, reason } (bytes, signed, ±1 PiB max) and GET for totals + history. Admin only.
  • Applied as deltas (greatest(0, uploaded + delta)) inside a transaction holding a row lock. The Rust tracker also writes traffic as deltas (ledger.rs), so an admin correction and an announce flush never overwrite each other. Totals never go below 0; the logged deltas are the ones actually applied, and a no-op (removing from 0) is refused.
  • New stat_adjustments table (migration 0019), with admin_id set to null if the admin account is deleted.
  • Tracker user cache invalidated after a change (ratio checks).
  • Panic mode encrypts/restores the adjustment reasons, like the bonus ledger descriptions.
  • Pure helpers in shared/utils/statAdjust.ts (units, clamp, ratio rule shared with the dashboard, zod schema) with unit tests.

Test plan

  • npx vitest run: all passing, including new stat-adjust tests
  • npm run build
  • Migration applied on the local DB; endpoints return 401 without a session
  • Signed in as admin: add 10 GB upload, remove 5 GB download, check totals, ratio preview and history; remove more than the current total (clamped to 0); check the member's dashboard

🤖 Generated with Claude Code

Admins can add to or remove from a member's uploaded/downloaded totals
from Admin → Users, with a required reason, a preview of the resulting
totals and ratio, and the history of previous corrections.

Adjustments are deltas applied under a row lock, like the tracker's own
traffic updates, so neither write is lost; totals never go below 0 and
the logged deltas are the ones really applied. Reasons are encrypted by
panic mode with the other ledgers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 36 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b8b59f77-e4e2-4055-b52e-6fe05d9c87bc
📥 Commits

Reviewing files that changed from the base of the PR and between 29645f9 and b1825fd.

📒 Files selected for processing: 18
  • app/components/admin/UserStats.vue
  • app/components/admin/Users.vue
  • i18n/locales/de/app.json
  • i18n/locales/en/app.json
  • i18n/locales/es/app.json
  • i18n/locales/fr/app.json
  • i18n/locales/it/app.json
  • i18n/locales/ja/app.json
  • i18n/locales/ru/app.json
  • i18n/locales/zh/app.json
  • server/api/admin/panic/encrypt.post.ts
  • server/api/admin/panic/restore.post.ts
  • server/api/admin/users/[id]/stats.get.ts
  • server/api/admin/users/[id]/stats.post.ts
  • server/db/migrations/0019_stat_adjustments.sql
  • server/db/schema.ts
  • shared/utils/statAdjust.ts
  • tests/stat-adjust.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@florianjs
florianjs merged commit 7f65428 into main Oct 20, 2026
1 check passed
@florianjs florianjs mentioned this pull request Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant