Skip to content

fix: admin dashboard and local-login checks skip deleted users - #468

Merged
kikootwo merged 3 commits into
mainfrom
fix/215-active-user-count
Oct 27, 2026
Merged

kikootwo merged 3 commits into
mainfrom
fix/215-active-user-count

Conversation

@kikootwo

@kikootwo kikootwo commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #215

What changed

  • Admin dashboard: GET /api/admin/metrics counts total users with deletedAt: null, the same filter the Users page (GET /api/admin/users) uses.
  • Local-login flags: hasLocalUsers in GET /api/auth/providers (both the Audiobookshelf and the Plex branch) and hasLocalUsers/hasLocalAdmins in GET /api/admin/settings count only non-deleted users.
  • First-user checks are unchanged: the prisma.user.count() calls in the Plex callback, Plex profile switch, LocalAuthProvider.register and both OIDCAuthProvider paths still count deleted users. Each now has a one-line comment saying why: a deleted account must never make the next sign-up an admin.
  • New test helper tests/helpers/user-rows.ts: a prisma.user.count stand-in that applies the query's where to fixture rows, so a missing filter shows up as a wrong count.
  • Docs: documentation/admin-dashboard.md (Total users filter, Fixed {Bug} User Count on Admin Dash =/= Current User Count #215), documentation/backend/services/auth.md (first-user check note, hasLocalUsers filter, Fixed {Bug} User Count on Admin Dash =/= Current User Count #215), documentation/testing.md (new helper).

Why

Deleting a user is a soft delete: the row stays with deletedAt set. The dashboard counted every row, so its total ran higher than the Users page after any deletion.

The local-login flags had the same gap. A deleted local user can't sign in, but the flags still counted one. In Audiobookshelf mode that kept the local login form on the sign-in page when no local account could use it, and it kept the Auth tab's lockout warnings quiet ("no local users exist", "no local admin users exist") when a deleted local admin was the only one.

The lockout check is client-side only. validateAuthSettings() and the Auth tab warnings read hasLocalUsers/hasLocalAdmins from GET /api/admin/settings; PUT /api/admin/settings/oidc and PUT /api/admin/settings/registration don't check for local users or admins. Local login itself is turned off only by the DISABLE_LOCAL_LOGIN environment variable, not by a setting. With the corrected flags the existing warnings and the save validation now fire when they should; no server-side check was added.

Evidence

  • tests/api/admin-metrics.routes.test.ts: with two active and two deleted users, totalUsers is 2.
  • New tests/api/admin-settings-local-users.routes.test.ts: a deleted local admin counts as neither a local user nor a local admin; next to an active local non-admin, hasLocalUsers is true and hasLocalAdmins false; an active local admin counts.
  • tests/api/auth-misc.routes.test.ts: in Audiobookshelf mode a deleted local user doesn't set hasLocalUsers or show the local provider, and an active one next to it still does; in Plex mode a deleted local- setup admin doesn't set hasLocalUsers.
  • New tests/services/auth/first-user-admin.test.ts: when the only existing user is deleted, the next local sign-up is created as user with isSetupAdmin: false; on an empty database it is admin.
  • With main's source (8ee4a84) and this branch's tests: 5 failed, 15 passed, all on an assertion (expected 4 to be 2 for the dashboard total; expected true to be false for the four flag cases). The first-user tests pass on main too: they guard the behaviour that must stay. On this branch: 20/20 pass.

Checks

  • Unit tests for the changed code (vitest related on the 7 changed source files, plus the new test files): PASS, 13 files, 160/160
  • Type check and lint: PASS (tsc --noEmit clean; ESLint reports nothing new in the 15 touched files compared with main)
  • Image build and E2E smoke: PASS (image built from d26f784; smoke spec 1/1)
  • After merging main (dad0daf): vitest related on the source changed on both sides: PASS, 113 files, 2191/2191; tsc --noEmit clean
  • Full unit suite: PR Tests (CI)

Risk and rollback

  • In Audiobookshelf mode, the local login form now hides when the only local users are deleted and registration is off. That matches what those accounts can do: local sign-in skips deleted users, and the auth middleware refuses a deleted user's session on every route behind requireAuth. An install that relied on the form showing for a deleted account has no working local login to lose.
  • Plex mode: the setup admin can't be deleted through the API, so the local- setup admin filter only matters for a row deleted some other way.
  • The Auth tab can now show a lockout warning, and refuse to save, where it didn't before: OIDC and registration both off with only deleted local users, or registration on with OIDC off and only deleted local admins. Both are setups where no local account could sign in.
  • Dashboard total users drops by the number of deleted users. Display only.
  • First-user checks are untouched, so who becomes the first admin doesn't change.
  • Rollback: revert this PR. No data is written or migrated.

Release note

🤖 Generated with Claude Code

kikootwo and others added 3 commits October 27, 2026 02:23
…rs (#215)

The admin dashboard's total users now uses the Users page filter
(deletedAt: null). hasLocalUsers and hasLocalAdmins in the auth
providers and admin settings routes count only non-deleted users, so
a deleted local admin no longer keeps the login form shown or the
Auth tab lockout warnings quiet. First-user checks still count
deleted users, with a comment at each saying why.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kikootwo
kikootwo marked this pull request as ready for review October 27, 2026 06:53
@kikootwo
kikootwo merged commit b94297f into main Oct 27, 2026
1 check passed
@kikootwo
kikootwo deleted the fix/215-active-user-count branch October 27, 2026 06:58
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.

{Bug} User Count on Admin Dash =/= Current User Count

1 participant