diff --git a/README.md b/README.md
index f13821d..b7292a6 100644
--- a/README.md
+++ b/README.md
@@ -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 covers libraries, scanning and users so far (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, users and the external providers so far (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, 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.
+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. Providers have a card each that says what the provider is sent: turning one on asks first, the API key is write-only (never shown, and gone from the page once saved), and there are a test of the key, the contact or address, removing what a provider gave, and, for Lidarr, the profiles and root folder to use when an artist is added. 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 (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 bulk jobs screen and serving the app from the binary come later.
## Development
diff --git a/web/src/components/layout/Shell.test.tsx b/web/src/components/layout/Shell.test.tsx
index 18cfb67..6fe51f3 100644
--- a/web/src/components/layout/Shell.test.tsx
+++ b/web/src/components/layout/Shell.test.tsx
@@ -63,6 +63,23 @@ test('the admin area has a Users section next to Libraries', async () => {
expect(sections.getByRole('link', { name: 'Libraries' })).not.toHaveAttribute('aria-current')
})
+test('the admin area has a Providers section too', async () => {
+ sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: true } })
+ mockFetch({ ...adminRoutes, 'GET /api/v1/providers': () => ({ providers: [] }) })
+ renderAt('/admin/providers')
+ expect(await screen.findByRole('region', { name: 'Providers' })).toBeInTheDocument()
+ expect(within(screen.getByRole('navigation', { name: 'Admin sections' })).getByRole('link', { name: 'Providers' })).toHaveAttribute('aria-current', 'page')
+})
+
+test('someone who is not an admin who opens the providers 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/providers': () => ({ providers: [] }) })
+ renderAt('/admin/providers')
+ 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 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: [] }) })
diff --git a/web/src/pages/admin/AdminLayout.tsx b/web/src/pages/admin/AdminLayout.tsx
index fed5036..f37873c 100644
--- a/web/src/pages/admin/AdminLayout.tsx
+++ b/web/src/pages/admin/AdminLayout.tsx
@@ -8,6 +8,7 @@ import { cn } from '@/lib/utils'
const SECTIONS = [
{ to: '/admin/libraries', key: 'admin.sectionLibraries' },
{ to: '/admin/users', key: 'admin.sectionUsers' },
+ { to: '/admin/providers', key: 'admin.sectionProviders' },
]
/**
diff --git a/web/src/pages/admin/ProvidersPage.test.tsx b/web/src/pages/admin/ProvidersPage.test.tsx
new file mode 100644
index 0000000..de2caa1
--- /dev/null
+++ b/web/src/pages/admin/ProvidersPage.test.tsx
@@ -0,0 +1,52 @@
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { render, screen, within } from '@testing-library/react'
+import { beforeEach, expect, test, vi } from 'vitest'
+import { sessionStore } from '@/auth/session'
+import { initI18n } from '@/i18n'
+import { apiError, mockFetch } from '@/test/mockFetch'
+import ProvidersPage from './ProvidersPage'
+
+const provider = (name: string) => ({
+ name,
+ enabled: false,
+ needs_api_key: name === 'lastfm' || name === 'lidarr',
+ needs_url: name === 'lidarr',
+ has_api_key: false,
+ contact: '',
+ url: '',
+ sends: `What ${name} is sent.`,
+ notes: `Terms of ${name}.`,
+ updated_at: null,
+})
+
+const ORDER = ['lastfm', 'musicbrainz', 'wikipedia', 'commons', 'coverartarchive', 'lidarr']
+
+function renderPage() {
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } })
+ return render(
+
+
+ ,
+ )
+}
+
+beforeEach(async () => {
+ vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
+ await initI18n()
+ sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: true } })
+})
+
+test('it says providers are off until one is turned on, and shows one card for each in the server order', async () => {
+ mockFetch({ 'GET /api/v1/providers': () => ({ providers: ORDER.map(provider) }) })
+ renderPage()
+ expect(await screen.findByText(/Providers are off until you turn one on/)).toBeInTheDocument()
+ const names = (await screen.findAllByRole('heading', { level: 3 })).map((h) => h.textContent)
+ expect(names).toEqual(['Last.fm', 'MusicBrainz', 'Wikipedia', 'Wikimedia Commons', 'Cover Art Archive', 'Lidarr'])
+})
+
+test('a failure to read them is said in words with a way to try again', async () => {
+ mockFetch({ 'GET /api/v1/providers': () => apiError(500, 'internal') })
+ renderPage()
+ const alert = await screen.findByRole('alert')
+ expect(within(alert).getByRole('button', { name: 'Try again' })).toBeInTheDocument()
+})
diff --git a/web/src/pages/admin/ProvidersPage.tsx b/web/src/pages/admin/ProvidersPage.tsx
new file mode 100644
index 0000000..7cfcfa4
--- /dev/null
+++ b/web/src/pages/admin/ProvidersPage.tsx
@@ -0,0 +1,28 @@
+import { useTranslation } from 'react-i18next'
+import { useProviders } from '@/api/adminProviders'
+import Section from '@/components/Section'
+import { ErrorMessage, Loading } from '@/components/Status'
+import ProviderCard from './ProviderCard'
+
+/** Every external provider, one card each. They are all off until an admin turns one on. */
+export default function ProvidersPage() {
+ const { t } = useTranslation()
+ const providers = useProviders()
+
+ return (
+
+