Serve downloadable PDFs from a PocketBase documents collection

- New collection "documents" (title, slug, file, category, order, public);
  editors upload PDFs in the admin, no developer or redeploy needed
- The app serves each file at /dokumente/<slug>.pdf, a URL that survives a
  new upload (PocketBase's own file name gets a random suffix)
- New "documents" embed lists them as file cards, grouped by category;
  /downloads uses it
- List/view rules are "public = true", so a draft PDF is not reachable through
  the PocketBase API either
- Dev seed adds example documents with generated PDFs and fixes the
  const reassignment that broke seeding a fresh volume
- Docs: editor guide, architecture, and the manual production setup steps

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-10-12 22:15:18 +02:00
1 parent 97321e2b49
commit f1a06956f7
18 files changed
+641 -31

No files matched your search

+46
View File
@@ -102,6 +102,8 @@ public sealed partial class RouteSmokeTests : IDisposable
[InlineData("/gibt-es-nicht")]
[InlineData("/posts/gibt-es-nicht")]
[InlineData("/events/gibt-es-nicht.ics")]
[InlineData("/dokumente/gibt-es-nicht.pdf")]
[InlineData("/dokumente/internal-minutes.pdf")] // a draft: exists, but not public
public async Task Unknown_route_returns_404(string route)
{
var client = _factory.CreateClient();
@@ -180,6 +182,37 @@ public sealed partial class RouteSmokeTests : IDisposable
html.ShouldContain("Kommende Termine"); // events embed heading
}
[Fact]
public async Task Downloads_page_lists_the_documents_as_file_cards_by_category()
{
// /downloads opts into the documents embed. Each public document becomes a
// lone PDF link (the file card), grouped under its category; the draft is left out.
var client = _factory.CreateClient();
// Decoded, because Blazor HTML-encodes the umlauts of text from PocketBase.
var html = WebUtility.HtmlDecode(await client.GetStringAsync(new Uri("/downloads", UriKind.Relative)));
// [^>]* allows for the scoped-CSS attribute Blazor adds to each element.
html.ShouldMatch("<h2[^>]*>Förderverein</h2>");
html.ShouldMatch("""<li class="lone-link"[^>]*><a href="/dokumente/aufnahmeantrag-foerderverein.pdf"[^>]*>Aufnahmeantrag Förderverein</a></li>""");
html.ShouldContain("href=\"/dokumente/elternbrief.pdf\"");
html.ShouldNotContain("internal-minutes");
html.IndexOf("aufnahmeantrag-foerderverein", StringComparison.Ordinal)
.ShouldBeLessThan(html.IndexOf("einzugsermaechtigung", StringComparison.Ordinal));
}
[Fact]
public async Task Document_is_served_as_pdf_under_its_slug()
{
var client = _factory.CreateClient();
var response = await client.GetAsync(new Uri("/dokumente/einzugsermaechtigung.pdf", UriKind.Relative));
response.StatusCode.ShouldBe(HttpStatusCode.OK);
response.Content.Headers.ContentType?.MediaType.ShouldBe("application/pdf");
(await response.Content.ReadAsByteArrayAsync()).ShouldBe(PocketBaseFixture.DocumentContent);
}
[Fact]
public async Task Content_page_renders_its_body()
{
@@ -329,6 +362,19 @@ public sealed partial class RouteSmokeTests : IDisposable
(await response.Content.ReadAsStringAsync()).ShouldContain("Die Seite ist gerade nicht erreichbar");
}
[Fact]
public async Task Document_returns_503_when_PocketBase_is_unreachable()
{
// Not a page, so the gate lets it through; without PocketBase there is no file
// to hand out, and a 503 says "try again" where a 404 would say "gone".
await using var factory = UnreachablePocketBase();
var client = factory.CreateClient();
var response = await client.GetAsync(new Uri("/dokumente/elternbrief.pdf", UriKind.Relative));
response.StatusCode.ShouldBe(HttpStatusCode.ServiceUnavailable);
}
[Fact]
public async Task Calendar_feed_stays_an_empty_calendar_when_PocketBase_is_unreachable()
{