feat(web): a Users section in the admin area

Opens at /admin/users next to Libraries, for admins only; anyone else gets the notice and the server is not asked. README says what the admin area covers.
This commit is contained in:
tgiachi 2026-11-12 14:58:01 +01:00
commit 52569a0f8d
5 changed files with 40 additions and 4 deletions

View file

@ -27,7 +27,7 @@ It is a single executable, one database (SQLite by default, PostgreSQL if you pr
## What is not there yet
Radio queues, OpenSubsonic compatibility, transcoding, and the ListenBrainz integration. The web client exists (see [Web app](#web-app)) but `sondad` does not serve it yet, and its admin area only covers libraries and scanning so far (users, providers and the bulk jobs are still API-only).
Radio queues, OpenSubsonic compatibility, transcoding, and the ListenBrainz integration. The web client exists (see [Web app](#web-app)) but `sondad` does not serve it yet, and its admin area covers libraries, scanning and users so far (providers and the bulk jobs are still API-only).
## Requirements
@ -328,9 +328,9 @@ npm install
SONDA_URL=http://127.0.0.1:8080 npm run dev # open http://localhost:5173, /api is proxied to Sonda
```
What it does today: sign in (and create the first account of a new server), browse artists, albums and songs, search, and play with a queue, shuffle, repeat, media keys and a full-screen player. Artist pages show the Wikipedia text, similar artists and tags when those providers are on, each with its credit, and the photo credit next to the photo. It reports one listen per play. Discover suggests artists from the ones you pick, or from your listening only after you allow it (a dialog says that their names go to Last.fm), explains each score, and keeps your wishlist and the artists you are not interested in. An admin who set up the `lidarr` provider gets a "Request on Lidarr" button on an artist's page and on the Discover cards: it asks first, then sends that one artist to their own Lidarr, which does the downloading (the web app downloads nothing; the page of an artist reads what Lidarr has, the cards ask nothing until you send). An admin also gets an Admin area to add, rename, move and remove libraries and to start a scan (of one library or all, optionally reading every file again) and follow it. There are six themes (Sonda, Tokyo Night, Gruvbox dark, Gruvbox light, Dracula and Neon) and two languages (English and Italian), both chosen in Settings.
What it does today: sign in (and create the first account of a new server), browse artists, albums and songs, search, and play with a queue, shuffle, repeat, media keys and a full-screen player. Artist pages show the Wikipedia text, similar artists and tags when those providers are on, each with its credit, and the photo credit next to the photo. It reports one listen per play. Discover suggests artists from the ones you pick, or from your listening only after you allow it (a dialog says that their names go to Last.fm), explains each score, and keeps your wishlist and the artists you are not interested in. An admin who set up the `lidarr` provider gets a "Request on Lidarr" button on an artist's page and on the Discover cards: it asks first, then sends that one artist to their own Lidarr, which does the downloading (the web app downloads nothing; the page of an artist reads what Lidarr has, the cards ask nothing until you send). An admin also gets an Admin area to add, rename, move and remove libraries and to start a scan (of one library or all, optionally reading every file again) and follow it, and to manage accounts: add one by email, give or take away the admin role, reset a password (which ends that person's sessions) and delete an account. The last admin cannot be changed, and your own account has no buttons there. There are six themes (Sonda, Tokyo Night, Gruvbox dark, Gruvbox light, Dracula and Neon) and two languages (English and Italian), both chosen in Settings.
More commands, all run in `web/`: `npm test`, `npm run build`, and `npm run gen:api`, which rebuilds `src/api/schema.d.ts` from the OpenAPI spec (it fetches the generator with `npx`, so it needs the network once). The rest of the admin screens (users, providers, bulk jobs) and serving the app from the binary come later.
More commands, all run in `web/`: `npm test`, `npm run build`, and `npm run gen:api`, which rebuilds `src/api/schema.d.ts` from the OpenAPI spec (it fetches the generator with `npx`, so it needs the network once). The rest of the admin screens (providers, bulk jobs) and serving the app from the binary come later.
## Development

View file

@ -53,6 +53,25 @@ test('the Admin link opens the libraries and stays current inside the admin area
expect(within(mainNav()).getByRole('link', { name: 'Admin' })).toHaveAttribute('aria-current', 'page')
})
test('the admin area has a Users section next to Libraries', async () => {
sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: true } })
mockFetch({ ...adminRoutes, 'GET /api/v1/users': () => ({ users: [{ id: 1, email: 'tom@example.org', is_admin: true }] }) })
renderAt('/admin/users')
expect(await screen.findByRole('region', { name: 'Users' })).toBeInTheDocument()
const sections = within(screen.getByRole('navigation', { name: 'Admin sections' }))
expect(sections.getByRole('link', { name: 'Users' })).toHaveAttribute('aria-current', 'page')
expect(sections.getByRole('link', { name: 'Libraries' })).not.toHaveAttribute('aria-current')
})
test('someone who is not an admin who opens the users address gets a notice and no request', async () => {
sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'ann@example.org', is_admin: false } })
const { calls } = mockFetch({ 'GET /api/v1/users': () => ({ users: [] }) })
renderAt('/admin/users')
expect(screen.getByText('Only admins can see this page.')).toBeInTheDocument()
await new Promise((r) => setTimeout(r, 30))
expect(calls).toHaveLength(0)
})
test('someone who is not an admin who opens the admin address gets a notice and no request', async () => {
sessionStore.setState({ status: 'authenticated', user: { id: 2, email: 'ann@example.org', is_admin: false } })
const { calls } = mockFetch(adminRoutes)

View file

@ -5,7 +5,10 @@ import { EmptyMessage } from '@/components/Status'
import { cn } from '@/lib/utils'
/** The sections of the admin area; each is a route under `/admin`. */
const SECTIONS = [{ to: '/admin/libraries', key: 'admin.sectionLibraries' }]
const SECTIONS = [
{ to: '/admin/libraries', key: 'admin.sectionLibraries' },
{ to: '/admin/users', key: 'admin.sectionUsers' },
]
/**
* The frame of the admin area. Only an admin gets the sections: anyone else gets a notice, and since the

View file

@ -0,0 +1,12 @@
import AddUserForm from './AddUserForm'
import UserList from './UserList'
/** The accounts and the form to add one. */
export default function UsersPage() {
return (
<div className="flex flex-col gap-10">
<UserList />
<AddUserForm />
</div>
)
}

View file

@ -8,6 +8,7 @@ import DiscoverPage from '@/pages/DiscoverPage'
import HomePage from '@/pages/HomePage'
import AdminLayout from '@/pages/admin/AdminLayout'
import LibrariesPage from '@/pages/admin/LibrariesPage'
import UsersPage from '@/pages/admin/UsersPage'
import NotFoundPage from '@/pages/NotFoundPage'
import SearchPage from '@/pages/SearchPage'
import SettingsPage from '@/pages/SettingsPage'
@ -32,6 +33,7 @@ export const routes: RouteObject[] = [
children: [
{ index: true, element: <Navigate to="/admin/libraries" replace /> },
{ path: 'libraries', element: <LibrariesPage /> },
{ path: 'users', element: <UsersPage /> },
],
},
{ path: '*', element: <NotFoundPage /> },