oficina / slides Public

Readers: a parked slide reaches nobody outside the deck

Viewer, notes, share and follow links, projector, presenter and remote
pages, PDF export, /s/ and /p/ thumbnails and the font gate all work on
deck.ForReaders(); the list cover takes the first unparked slide. The
editor, /d/ thumbnails and the API stay complete.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev fa04dda72422145acf0182d9b510c0384e8b583c parent 283e3e9
7 files changed, +230 −4
  • internal/slides/decks.go +3 −2
  • internal/slides/export.go +1 −0
  • internal/slides/exports.go +2 −1
  • internal/slides/presentation.go +4 −1
  • internal/slides/thumbs.go +6 −0
  • internal/slides/viewer.go +2 −0
  • internal/slidestest/talk_readers_test.go +212 −0
diff --git a/internal/slides/decks.go b/internal/slides/decks.go
index 089492f..ddf3174 100644
--- a/internal/slides/decks.go
+++ b/internal/slides/decks.go
@@ -943,8 +943,9 @@ func (a *app) deckGlance(ctx context.Context, d Deck) (slides int, first string,
return 0, "", false
}
defer h.Close(ctx)
- if len(view.Slides) > 0 {
- first = view.Slides[0].ID
+ // The cover is the first slide that is not parked.
+ if shown := view.ForReaders(); len(shown.Slides) > 0 {
+ first = shown.Slides[0].ID
}
return len(view.Slides), first, true
}
diff --git a/internal/slides/export.go b/internal/slides/export.go
index 2c9d19a..413ebda 100644
--- a/internal/slides/export.go
+++ b/internal/slides/export.go
@@ -128,6 +128,7 @@ func Export(ctx context.Context, d *deck.Deck, o ExportOptions) ([]byte, []layou
if d == nil {
return nil, nil, errors.New("slides: export: no deck")
}
+ d = d.ForReaders()
if len(d.Slides) > MaxExportSlides {
return nil, nil, fmt.Errorf("%w: %d slides, the most is %d", ErrTooManySlides, len(d.Slides), MaxExportSlides)
}
diff --git a/internal/slides/exports.go b/internal/slides/exports.go
index b57454e..3dfd1f4 100644
--- a/internal/slides/exports.go
+++ b/internal/slides/exports.go
@@ -525,6 +525,7 @@ func (a *app) exportJob(id <-chan string, d Deck, actor string, withNotes bool,
return errors.New(words.open)
}
defer h.Close(ctx)
+ view = view.ForReaders()
if len(view.Slides) > MaxExportSlides {
return errors.New(words.tooMany)
}
@@ -973,7 +974,7 @@ func (a *app) exportWarningsFor(r *http.Request, held heldExport) []exportWarnin
if err := a.db.G.WithContext(r.Context()).Where("sqid = ?", held.deck).Take(&d).Error; err == nil {
if h, view, err := a.openDeck(r.Context(), d); err == nil {
defer h.Close(r.Context())
- for i, s := range view.Slides {
+ for i, s := range view.ForReaders().Slides {
labels[s.ID] = slideLabel(r, s, i+1)
}
}
diff --git a/internal/slides/presentation.go b/internal/slides/presentation.go
index 5ffe577..913c6c5 100644
--- a/internal/slides/presentation.go
+++ b/internal/slides/presentation.go
@@ -668,6 +668,7 @@ func (a *app) renderSurface(w http.ResponseWriter, r *http.Request, d Deck, p Pr
return
}
defer h.Close(r.Context())
+ view = view.ForReaders()
q := r.URL.Query()
sh := presentShellFor(r, view.Meta.Title)
@@ -817,6 +818,7 @@ func (a *app) presenterNotes(w http.ResponseWriter, r *http.Request) {
return
}
defer h.Close(r.Context())
+ view = view.ForReaders()
now := time.Now().UTC()
page := presenterPage{
@@ -1009,6 +1011,7 @@ func (a *app) remote(w http.ResponseWriter, r *http.Request) {
return
}
defer h.Close(r.Context())
+ view = view.ForReaders()
page := remotePage{
shell: presentShellFor(r, rastrillo.T(r, "slides.remote.title"), view.Meta.Title),
@@ -1447,7 +1450,7 @@ func (a *app) presentCommand(w http.ResponseWriter, r *http.Request) {
a.fail(w, r, "open deck", err)
return
}
- count = len(view.Slides)
+ count = len(view.ForReaders().Slides)
h.Close(r.Context())
if count == 0 {
a.errorPage(w, r, http.StatusUnprocessableEntity, kindStatus, "")
diff --git a/internal/slides/thumbs.go b/internal/slides/thumbs.go
index c320190..bfa6d71 100644
--- a/internal/slides/thumbs.go
+++ b/internal/slides/thumbs.go
@@ -135,6 +135,12 @@ func (a *app) serveThumb(w http.ResponseWriter, r *http.Request, d Deck, base st
return
}
defer h.Close(r.Context())
+ // The editor's route (/d/…) and the API describe the whole deck; a
+ // share link and a presentation session are readers, and a parked
+ // slide is not there for them.
+ if strings.HasPrefix(base, "/s/") || strings.HasPrefix(base, "/p/") {
+ view = view.ForReaders()
+ }
index := -1
for i, s := range view.Slides {
diff --git a/internal/slides/viewer.go b/internal/slides/viewer.go
index 535c78d..bdaff69 100644
--- a/internal/slides/viewer.go
+++ b/internal/slides/viewer.go
@@ -190,6 +190,7 @@ func (a *app) renderViewer(w http.ResponseWriter, r *http.Request, d Deck, mode,
return
}
defer h.Close(r.Context())
+ view = view.ForReaders()
q := r.URL.Query()
vp := q.Get("vp")
@@ -446,6 +447,7 @@ func (a *app) deckNotes(w http.ResponseWriter, r *http.Request) {
return
}
defer h.Close(r.Context())
+ view = view.ForReaders()
base := "/d/" + d.Sqid
page := notesPage{
diff --git a/internal/slidestest/talk_readers_test.go b/internal/slidestest/talk_readers_test.go
new file mode 100644
index 0000000..9a4912b
--- /dev/null
+++ b/internal/slidestest/talk_readers_test.go
@@ -0,0 +1,212 @@
+package slidestest
+
+import (
+ "net/http"
+ "net/url"
+ "strings"
+ "testing"
+)
+
+// talkSlide is one slide of a talk-marked deck: its id, how it is
+// marked ("" is core), and the words that identify it wherever they
+// leak.
+type talkSlide struct {
+ id, talk, marker string
+}
+
+// markedDeck makes a deck over the API whose slides carry a marker word
+// in their heading and their notes. It returns the deck's path, its sqid
+// and the agent token.
+func markedDeck(t *testing.T, a *testApp, cookies []*http.Cookie, slides []talkSlide) (path, sqid, token string) {
+ t.Helper()
+ token = mintAgent(t, a, cookies, "marked-deck")
+ sqid = apiDeck(t, a, token, "Marked")
+ view := apiJSON(t, a, http.MethodGet, "/api/v1/decks/"+sqid, token, "", http.StatusOK)
+ var ops []string
+ list, _ := view["slides"].([]any)
+ for _, s := range list {
+ id, _ := s.(map[string]any)["id"].(string)
+ ops = append(ops, `{"op":"remove_slide","id":`+quote(id)+`}`)
+ }
+ for _, s := range slides {
+ ops = append(ops,
+ `{"op":"add_slide","id":`+quote(s.id)+`,"layout":"flow","template":"title-body"}`,
+ `{"op":"add_block","slide":`+quote(s.id)+`,"id":`+quote("h"+s.id)+`,"type":"heading","region":"heading","markdown":`+quote(s.marker)+`,"level":1}`,
+ `{"op":"set_notes","id":`+quote(s.id)+`,"markdown":`+quote("notes "+s.marker)+`}`)
+ if s.talk != "" {
+ ops = append(ops, `{"op":"set_slide","id":`+quote(s.id)+`,"talk":`+quote(s.talk)+`}`)
+ }
+ }
+ apiJSON(t, a, http.MethodPost, "/api/v1/decks/"+sqid+"/ops", token, `{"ops":[`+strings.Join(ops, ",")+`]}`, http.StatusOK)
+ return "/d/" + sqid, sqid, token
+}
+
+var mixedTalk = []talkSlide{
+ {"pone", "parked", "PARKEDONE"},
+ {"stwo", "", "SHOWNTWO"},
+ {"fthree", "full", "FULLTHREE"},
+ {"pfour", "parked", "PARKEDFOUR"},
+ {"sfive", "", "SHOWNFIVE"},
+}
+
+// pageCount is the pages in a PDF, either spelling of the entry.
+func pageCount(pdf string) int {
+ n := func(entry string) int {
+ return strings.Count(pdf, entry) + strings.Count(pdf, strings.Replace(entry, " /", "/", 1))
+ }
+ return n("/Type /Page") - n("/Type /Pages")
+}
+
+// exportPDF runs the export flow and returns the PDF.
+func exportPDF(t *testing.T, a *testApp, deck string, cookies []*http.Cookie) string {
+ t.Helper()
+ status := startExport(t, a, deck, cookies, url.Values{})
+ fragment := waitForExport(t, a, status, cookies)
+ if strings.Contains(fragment, "rst-tone=\"negative\"") {
+ t.Fatalf("the export failed:\n%s", fragment)
+ }
+ return mustGet(t, a, status+".pdf", http.StatusOK, cookies).Body.String()
+}
+
+// TestAParkedSlideReachesNoReader: every place a reader looks leaves
+// the parked slides out, and the numbers they see count only what is
+// there.
+func TestAParkedSlideReachesNoReader(t *testing.T) {
+ a := newApp(t)
+ cookies := signedIn(t, a, allowedAddress)
+ path, _, _ := markedDeck(t, a, cookies, mixedTalk)
+ share := "/s/" + mintShareLink(t, a, path, cookies)
+ session, _ := startPresenting(t, a, path, cookies)
+
+ cases := []struct {
+ name string
+ target string
+ want int
+ cookies []*http.Cookie
+ shows string // present when the page is 200
+ }{
+ {"viewer first slide", path + "?slide=1", 200, cookies, "SHOWNTWO"},
+ {"viewer second slide", path + "?slide=2", 200, cookies, "FULLTHREE"},
+ {"viewer past the end", path + "?slide=4", 404, cookies, ""},
+ {"share link", share, 200, nil, "SHOWNTWO"},
+ {"share link past the end", share + "?slide=4", 404, nil, ""},
+ {"notes page", path + "/notes", 200, cookies, "notes SHOWNFIVE"},
+ {"projector", "/p/" + session, 200, cookies, "SHOWNTWO"},
+ {"projector past the end", "/p/" + session + "?slide=4", 404, cookies, ""},
+ {"presenter notes", "/p/" + session + "/notes", 200, cookies, "SHOWNTWO"},
+ {"follow link", share + "?follow=1", 200, nil, "SHOWNTWO"},
+ {"follow past the end", share + "?follow=1&slide=4", 404, nil, ""},
+ {"share thumbnail of a parked slide", share + "/slides/pone.svg", 404, nil, ""},
+ {"share thumbnail of a shown slide", share + "/slides/stwo.svg", 200, nil, ""},
+ {"session thumbnail of a parked slide", "/p/" + session + "/slides/pfour.svg", 404, nil, ""},
+ {"session thumbnail of a shown slide", "/p/" + session + "/slides/sfive.svg", 200, nil, ""},
+ }
+ for _, c := range cases {
+ t.Run(c.name, func(t *testing.T) {
+ rec := get(t, a, c.target, c.cookies...)
+ if rec.Code != c.want {
+ t.Fatalf("GET %s: status %d, want %d\n%s", c.target, rec.Code, c.want, rec.Body)
+ }
+ body := rec.Body.String()
+ if rec.Code == 200 && c.shows != "" && !strings.Contains(body, c.shows) {
+ t.Errorf("GET %s does not show %q:\n%s", c.target, c.shows, body)
+ }
+ if strings.Contains(body, "PARKED") || strings.Contains(body, "/pone.svg") || strings.Contains(body, "/pfour.svg") {
+ t.Errorf("GET %s carries a parked slide:\n%s", c.target, body)
+ }
+ })
+ }
+
+ t.Run("the counter counts what is there", func(t *testing.T) {
+ page := mustGet(t, a, share+"?slide=3", http.StatusOK, nil).Body.String()
+ if !strings.Contains(page, "SHOWNFIVE") || !strings.Contains(page, "3 of 3") {
+ t.Errorf("the third slide over a share link is not SHOWNFIVE of 3:\n%s", page)
+ }
+ })
+
+ t.Run("pdf", func(t *testing.T) {
+ if got := pageCount(exportPDF(t, a, path, cookies)); got != 3 {
+ t.Errorf("the PDF has %d pages, want 3 (the parked slides are left out)", got)
+ }
+ })
+}
+
+// TestAFullOnlySlideShowsToReaders: full only is a way of giving the
+// talk, not a way of hiding a slide: readers get it.
+func TestAFullOnlySlideShowsToReaders(t *testing.T) {
+ a := newApp(t)
+ cookies := signedIn(t, a, allowedAddress)
+ path, _, _ := markedDeck(t, a, cookies, mixedTalk)
+ share := "/s/" + mintShareLink(t, a, path, cookies)
+ if page := mustGet(t, a, share+"?slide=2", http.StatusOK, nil).Body.String(); !strings.Contains(page, "FULLTHREE") {
+ t.Errorf("a share link does not show the full-only slide:\n%s", page)
+ }
+ if rec := get(t, a, share+"/slides/fthree.svg"); rec.Code != http.StatusOK {
+ t.Errorf("the full-only slide's thumbnail over a share link: status %d, want 200", rec.Code)
+ }
+}
+
+// TestTheEditorAndAPIStillDescribeAParkedSlide: people with access to
+// the deck still see everything in it.
+func TestTheEditorAndAPIStillDescribeAParkedSlide(t *testing.T) {
+ a := newApp(t)
+ cookies := signedIn(t, a, allowedAddress)
+ path, sqid, token := markedDeck(t, a, cookies, mixedTalk)
+
+ if rec := get(t, a, path+"/slides/pone.svg", cookies...); rec.Code != http.StatusOK {
+ t.Errorf("the editor's thumbnail of a parked slide: status %d, want 200", rec.Code)
+ }
+ editor := mustGet(t, a, path+"/edit", http.StatusOK, cookies).Body.String()
+ if !strings.Contains(editor, "pone") {
+ t.Errorf("the editor does not describe the parked slide:\n%s", editor)
+ }
+ view := apiJSON(t, a, http.MethodGet, "/api/v1/decks/"+sqid, token, "", http.StatusOK)
+ if got := mustJSON(t, view["slides"]); !strings.Contains(got, "pone") || !strings.Contains(got, "pfour") {
+ t.Errorf("the API deck leaves a parked slide out:\n%s", got)
+ }
+ if rec := send(t, a, bearerRequest(t, http.MethodGet, "/api/v1/decks/"+sqid+"/slides/pone.svg", token, "")); rec.Code != http.StatusOK {
+ t.Errorf("the API's thumbnail of a parked slide: status %d, want 200\n%s", rec.Code, rec.Body)
+ }
+}
+
+// TestEveryParkedDeckIsEmptyToReaders: a deck with nothing but parked
+// slides is, for a reader, the deck with nothing in it.
+func TestEveryParkedDeckIsEmptyToReaders(t *testing.T) {
+ a := newApp(t)
+ cookies := signedIn(t, a, allowedAddress)
+ path, _, _ := markedDeck(t, a, cookies, []talkSlide{
+ {"pone", "parked", "PARKEDONE"},
+ {"ptwo", "parked", "PARKEDTWO"},
+ })
+ share := "/s/" + mintShareLink(t, a, path, cookies)
+
+ for _, target := range []string{share, path + "?slide=1", path + "/notes"} {
+ rec := get(t, a, target, cookies...)
+ if target == share {
+ rec = get(t, a, target)
+ }
+ body := rec.Body.String()
+ if rec.Code != http.StatusOK || strings.Contains(body, "PARKED") || strings.Contains(body, "<section slides-slide") {
+ t.Errorf("GET %s: status %d, want an empty page with no slide:\n%s", target, rec.Code, body)
+ }
+ }
+ // An empty deck answers any slide with its empty page, and so does this.
+ if rec := get(t, a, share+"?slide=1"); rec.Code != http.StatusOK || strings.Contains(rec.Body.String(), "<section slides-slide") {
+ t.Errorf("slide 1 of an all-parked deck over a share link: status %d, want the empty page", rec.Code)
+ }
+}
+
+// TestACoverSkipsAParkedFirstSlide: the deck list's cover is the first
+// slide that is not parked.
+func TestACoverSkipsAParkedFirstSlide(t *testing.T) {
+ a := newApp(t)
+ cookies := signedIn(t, a, allowedAddress)
+ _, sqid, _ := markedDeck(t, a, cookies, mixedTalk)
+ list := mustGet(t, a, "/", http.StatusOK, cookies).Body.String()
+ if !strings.Contains(list, "/d/"+sqid+"/slides/stwo.svg") {
+ t.Errorf("the list's cover for the deck is not its first unparked slide:\n%s", list)
+ }
+ if strings.Contains(list, "/d/"+sqid+"/slides/pone.svg") {
+ t.Errorf("the list's cover is a parked slide:\n%s", list)
+ }
+}