Repository navigation
fix: admin dashboard and local-login checks skip deleted users - #468
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #215
What changed
GET /api/admin/metricscounts total users withdeletedAt: null, the same filter the Users page (GET /api/admin/users) uses.hasLocalUsersinGET /api/auth/providers(both the Audiobookshelf and the Plex branch) andhasLocalUsers/hasLocalAdminsinGET /api/admin/settingscount only non-deleted users.prisma.user.count()calls in the Plex callback, Plex profile switch,LocalAuthProvider.registerand bothOIDCAuthProviderpaths 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.tests/helpers/user-rows.ts: aprisma.user.countstand-in that applies the query'swhereto fixture rows, so a missing filter shows up as a wrong count.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,hasLocalUsersfilter, 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
deletedAtset. 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 readhasLocalUsers/hasLocalAdminsfromGET /api/admin/settings;PUT /api/admin/settings/oidcandPUT /api/admin/settings/registrationdon't check for local users or admins. Local login itself is turned off only by theDISABLE_LOCAL_LOGINenvironment 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,totalUsersis 2.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,hasLocalUsersis true andhasLocalAdminsfalse; an active local admin counts.tests/api/auth-misc.routes.test.ts: in Audiobookshelf mode a deleted local user doesn't sethasLocalUsersor show thelocalprovider, and an active one next to it still does; in Plex mode a deletedlocal-setup admin doesn't sethasLocalUsers.tests/services/auth/first-user-admin.test.ts: when the only existing user is deleted, the next local sign-up is created asuserwithisSetupAdmin: false; on an empty database it isadmin.main's source (8ee4a84) and this branch's tests: 5 failed, 15 passed, all on an assertion (expected 4 to be 2for the dashboard total;expected true to be falsefor the four flag cases). The first-user tests pass onmaintoo: they guard the behaviour that must stay. On this branch: 20/20 pass.Checks
vitest relatedon the 7 changed source files, plus the new test files): PASS, 13 files, 160/160tsc --noEmitclean; ESLint reports nothing new in the 15 touched files compared withmain)main(dad0daf):vitest relatedon the source changed on both sides: PASS, 113 files, 2191/2191;tsc --noEmitcleanRisk and rollback
requireAuth. An install that relied on the form showing for a deleted account has no working local login to lose.local-setup admin filter only matters for a row deleted some other way.Release note
🤖 Generated with Claude Code