oficina / slides Public

Choose who can open a deck on its Share page

Paul, 2026-11-11: "Share should go where it does on Docs", and the deck's
settings belong in an inspector like Docs'. Docs keeps a document's
general access under Share; Slides kept the rung (private / team) as a
third field of the Deck settings form.

The rung moves to the share page: a section above the links, the same
three option cards as a real POST form (POST /d/{sqid}/share/access), so
it works with scripts off. Owner only (mayChangeRung): a roster owner on
an orphan may share it but not move it, and reads the rung as text with
a line saying only the owner can change it. The write is the row's rung
alone, under the member guard in the writer transaction, and does not
move the list's "edited" time. The page is now "Share", with "Share
links" as its second section.

The settings form keeps title and theme (the scriptless way to change
them) and says where the rung went. Its POST still takes a rung, and one
left out keeps the deck's own, so nothing that posts to it breaks.

The write-route lapse test covers the new route and now reads the rung
back too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 32b6aa9463c6c08f259d20d04d44c89ca38a6362 parent ab97638
9 files changed, +271 −51
  • internal/slides/app.go +7 −2
  • internal/slides/decks.go +45 −26
  • internal/slides/locales/en.toml +10 −1
  • internal/slides/share.go +84 −4
  • internal/slides/team_guard_test.go +5 −2
  • internal/slides/team_review_test.go +14 −1
  • internal/slides/templates/deck_settings.html +11 −9
  • internal/slides/templates/share.html +31 −5
  • internal/slidestest/share_test.go +64 −1
diff --git a/internal/slides/app.go b/internal/slides/app.go
index f082bc6..f814fc2 100644
--- a/internal/slides/app.go
+++ b/internal/slides/app.go
@@ -217,12 +217,17 @@ func New(d *db.DB, cfg Config) (*http.ServeMux, *app, error) {
// open the deck can read it to a room, so this is deckFor's
// audience rather than the owner's alone.
r.Post("/d/{sqid}/present", a.startPresenting)
- // Sharing is the owner's, all three of these (share.go says
+ // Sharing is the owner's, all four of these (share.go says
// why a team member who can read the deck still cannot mint a
- // link to it).
+ // link to it). Who can open the deck is here too, as general
+ // access is under Share in Docs.
r.Get("/d/{sqid}/share", a.deckShare)
r.Post("/d/{sqid}/share", a.mintShareLink)
+ r.Post("/d/{sqid}/share/access", a.saveDeckAccess)
r.Post("/d/{sqid}/share/{id}/revoke", a.revokeShareLink)
+ // The deck's title and theme as a form: the editor's inspector
+ // is where they are changed, and this page is that for somebody
+ // with scripts off (the editor's <noscript> links it).
r.Get("/d/{sqid}/settings", a.deckSettings)
r.Post("/d/{sqid}/settings", a.saveDeckSettings)
// Deleting gets its own URL and its own page, never a modal
diff --git a/internal/slides/decks.go b/internal/slides/decks.go
index 5ac28ec..1c1d6f7 100644
--- a/internal/slides/decks.go
+++ b/internal/slides/decks.go
@@ -100,8 +100,9 @@ const (
rungTeam = "team"
)
-// settableRungs is what the settings screen offers, in the order it
-// offers them. Not every rung there is — see the constants above.
+// settableRungs is what the share page offers (share.go's access
+// form), in the order it offers them. Not every rung there is — see
+// the constants above.
var settableRungs = []string{rungPrivate, rungTeam}
// themeIDs are the six themes a deck can wear, in the order the picker
@@ -1177,17 +1178,29 @@ func blankOpeningOps(title, theme string) ([]byte, error) {
}
// --- GET/POST /d/{sqid}/settings ---
+//
+// The deck's title and theme as a scriptless form. Nothing links it as a
+// destination any more: the editor's inspector holds both (with Docs'
+// shape, a deck's settings are an inspector, not a page), and who can
+// open the deck is on the share page. It stays for somebody with
+// scripts off — the editor's <noscript> links it — and the POST still
+// takes a rung, for a caller that posts one (the share page's form is
+// the screen that does now).
type deckSettingsPage struct {
shell
- Title string
- Action string
- TitleLabel string
- TitleValue string
- ThemeLabel string
- Themes []selectOption
- RungLegend string
- Rungs []choiceOption
+ Title string
+ Action string
+ TitleLabel string
+ TitleValue string
+ ThemeLabel string
+ Themes []selectOption
+ // AccessHref is the share page, where who can open the deck is
+ // chosen now (share.go's saveDeckAccess); empty for somebody who
+ // may not share it.
+ AccessHref string
+ AccessBody string
+ AccessLabel string
Submit string
CancelHref string
CancelLabel string
@@ -1199,7 +1212,7 @@ type deckSettingsPage struct {
Errors map[string]string
}
-func (a *app) settingsPage(r *http.Request, u User, d Deck, title, theme, rung string, errs map[string]string) deckSettingsPage {
+func (a *app) settingsPage(r *http.Request, u User, d Deck, title, theme string, errs map[string]string) deckSettingsPage {
base := "/d/" + d.Sqid
page := deckSettingsPage{
shell: a.shellFor(r, u, onDeck(rastrillo.T(r, "slides.deck.settings"), d.Title)),
@@ -1209,8 +1222,6 @@ func (a *app) settingsPage(r *http.Request, u User, d Deck, title, theme, rung s
TitleValue: title,
ThemeLabel: rastrillo.T(r, "slides.deck.theme.label"),
Themes: themeOptions(r, theme),
- RungLegend: rastrillo.T(r, "slides.deck.rung.legend"),
- Rungs: rungOptions(r, rung),
Submit: rastrillo.T(r, "slides.deck.settings.submit"),
CancelHref: base,
CancelLabel: rastrillo.T(r, "slides.cancel"),
@@ -1221,12 +1232,16 @@ func (a *app) settingsPage(r *http.Request, u User, d Deck, title, theme, rung s
BackLabel: rastrillo.T(r, "slides.deck.back"),
Errors: errs,
}
- // A roster owner on an orphan (team_owner.go) is offered what they
- // may change and nothing more: no rung, no delete. Outside team mode
- // the owner may do both and the page is as it always was.
- if !a.mayChangeRung(r.Context(), u, d) {
- page.Rungs = nil
+ // Who can open the deck is the share page's now (Docs' place for
+ // general access); this page says where it went.
+ if a.mayShareDeck(r.Context(), u, d) {
+ page.AccessHref = base + "/share"
+ page.AccessBody = rastrillo.T(r, "slides.deck.settings.access")
+ page.AccessLabel = rastrillo.T(r, "slides.share.action")
}
+ // A roster owner on an orphan (team_owner.go) is offered what they
+ // may change and nothing more: no delete. Outside team mode the
+ // owner may and the page is as it always was.
if !a.mayDeleteDeck(r.Context(), u, d) {
page.DeleteHref = ""
}
@@ -1242,7 +1257,7 @@ func (a *app) deckSettings(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
- render(w, "deck_settings", a.settingsPage(r, u, d, d.Title, d.Theme, d.Rung, nil))
+ render(w, "deck_settings", a.settingsPage(r, u, d, d.Title, d.Theme, nil))
}
// saveDeckSettings serves POST /d/{sqid}/settings.
@@ -1268,13 +1283,15 @@ func (a *app) saveDeckSettings(w http.ResponseWriter, r *http.Request) {
title := p.String("title")
theme := r.PostFormValue("theme")
rung := r.PostFormValue("rung")
+ // The form no longer carries the rung (it is the share page's): a
+ // POST without one leaves it where it is.
+ if rung == "" {
+ rung = d.Rung
+ }
if !a.mayChangeRung(r.Context(), u, d) {
// Team mode, a roster owner on an orphan (team_owner.go): title
- // and theme only. The page offers no rung; one posted anyway
- // must be the deck's own, never a narrowing.
- if rung == "" {
- rung = d.Rung
- }
+ // and theme only. A rung posted anyway must be the deck's own,
+ // never a narrowing.
if rung != d.Rung {
a.errorPage(w, r, http.StatusForbidden, kindStatus, "")
return
@@ -1287,12 +1304,14 @@ func (a *app) saveDeckSettings(w http.ResponseWriter, r *http.Request) {
if !validTheme(theme) {
errs["Theme"] = rastrillo.T(r, "slides.deck.theme.invalid")
}
- if !validRung(rung) {
+ // The deck's own rung passes even when it is one no screen sets
+ // (granted): leaving it alone is not choosing it.
+ if rung != d.Rung && !validRung(rung) {
errs["Rung"] = rastrillo.T(r, "slides.deck.rung.invalid")
}
if len(errs) > 0 {
w.WriteHeader(http.StatusUnprocessableEntity)
- render(w, "deck_settings", a.settingsPage(r, u, d, p.Echo()["title"], theme, rung, errs))
+ render(w, "deck_settings", a.settingsPage(r, u, d, p.Echo()["title"], theme, errs))
return
}
diff --git a/internal/slides/locales/en.toml b/internal/slides/locales/en.toml
index 1e9f4df..2933b0f 100644
--- a/internal/slides/locales/en.toml
+++ b/internal/slides/locales/en.toml
@@ -150,6 +150,7 @@ slides.when.yesterday.alone = "Yesterday"
# better to call it (viewer.go's slideLabel).
slides.deck.settings = "Deck settings"
slides.deck.settings.submit = "Save settings"
+slides.deck.settings.access = "Who can open this deck, and its share links, are on the Share page."
slides.deck.back = "Back to the deck"
slides.deck.slide = "Slide {n}"
slides.deck.title.label = "Title"
@@ -550,7 +551,15 @@ slides.notes.none = "No notes on this slide."
# The warning is stated before the button rather than in a help page: a
# share link is genuinely useful and genuinely means anyone who has it
# can read the deck, and the person deciding should see both.
-slides.share.title = "Share links"
+slides.share.title = "Share"
+# The bar's action on a deck, as on a document in Docs (docs.share.action):
+# it opens the page that asks who, so the ellipsis.
+slides.share.action = "Share…"
+slides.share.links = "Share links"
+slides.share.access.submit = "Save who can open it"
+# A roster owner on an orphaned deck (team_owner.go) may share it but not
+# change who can open it.
+slides.share.access.fixed = "Only the deck's owner can change who can open it."
slides.share.lead = "A share link opens this deck read-only, with no sign-in. The slides are what it shows — never the speaker notes, and never the settings."
slides.share.warning.title = "What a share link does"
slides.share.warning = "Anyone who has the link can open this deck, including anyone it gets forwarded to. It shows the deck as it is now, so later edits are visible through it too. Revoke it and the URL stops working."
diff --git a/internal/slides/share.go b/internal/slides/share.go
index 631ff9d..5be9e9f 100644
--- a/internal/slides/share.go
+++ b/internal/slides/share.go
@@ -85,8 +85,25 @@ type shareRow struct {
type sharePage struct {
shell
- Title string
- DeckTitle string
+ Title string
+ DeckTitle string
+
+ // Who can open the deck: the rung (spec §5), on this page because
+ // it is the deck's general access, and Docs puts that under Share.
+ // Rungs is the form, for somebody who may change it
+ // (mayChangeRung); a roster owner on an orphan may share it but not
+ // move it, and reads the rung as text instead (AccessCurrent).
+ AccessHeading string
+ AccessLegend string
+ AccessAction string
+ AccessSubmit string
+ AccessError string
+ Rungs []choiceOption
+ AccessCurrent string
+ AccessCurrentDesc string
+ AccessFixed string
+
+ LinksHeading string
Lead string
WarningTitle string
Warning string
@@ -125,10 +142,13 @@ func (a *app) deckShare(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
- a.renderSharePage(w, r, u, d, r.URL.Query().Get("new"))
+ a.renderSharePage(w, r, u, d, r.URL.Query().Get("new"), d.Rung, "")
}
-func (a *app) renderSharePage(w http.ResponseWriter, r *http.Request, u User, d Deck, newToken string) {
+// renderSharePage draws the share page. rung is the rung the access form
+// shows chosen (the deck's own, or what a refused POST asked for), and
+// accessErr the sentence under it when the POST was refused.
+func (a *app) renderSharePage(w http.ResponseWriter, r *http.Request, u User, d Deck, newToken, rung, accessErr string) {
var links []ShareLink
if err := a.db.G.WithContext(r.Context()).
Where("deck_id = ?", d.ID).
@@ -142,6 +162,7 @@ func (a *app) renderSharePage(w http.ResponseWriter, r *http.Request, u User, d
shell: a.shellFor(r, u, sharePageFrame(r, d)),
Title: rastrillo.T(r, "slides.share.title"),
DeckTitle: d.Title,
+ LinksHeading: rastrillo.T(r, "slides.share.links"),
Lead: rastrillo.T(r, "slides.share.lead"),
WarningTitle: rastrillo.T(r, "slides.share.warning.title"),
Warning: rastrillo.T(r, "slides.share.warning"),
@@ -152,6 +173,21 @@ func (a *app) renderSharePage(w http.ResponseWriter, r *http.Request, u User, d
EmptyTitle: rastrillo.T(r, "slides.share.empty.title"),
EmptyBody: rastrillo.T(r, "slides.share.empty.body"),
Links: make([]shareRow, 0, len(links)),
+
+ AccessHeading: rastrillo.T(r, "slides.deck.rung.legend"),
+ AccessLegend: rastrillo.T(r, "slides.deck.rung.legend"),
+ AccessError: accessErr,
+ }
+ if a.mayChangeRung(r.Context(), u, d) {
+ page.AccessAction = base + "/share/access"
+ page.AccessSubmit = rastrillo.T(r, "slides.share.access.submit")
+ page.Rungs = rungOptions(r, rung)
+ } else {
+ page.AccessCurrent = rungLabel(r, d.Rung)
+ if d.Rung == rungPrivate || d.Rung == rungGranted || d.Rung == rungTeam {
+ page.AccessCurrentDesc = rastrillo.T(r, "slides.rung."+d.Rung+".desc")
+ }
+ page.AccessFixed = rastrillo.T(r, "slides.share.access.fixed")
}
if newToken != "" {
page.NewURL = a.shareURL(newToken)
@@ -245,6 +281,50 @@ func (a *app) mintShareLink(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/d/"+d.Sqid+"/share?new="+token, http.StatusSeeOther)
}
+// --- POST /d/{sqid}/share/access ---
+
+// saveDeckAccess serves POST /d/{sqid}/share/access: who can open the
+// deck, the rung. It used to be one field of the settings form; it is on
+// the share page now, beside the links, as general access is in Docs.
+//
+// The owner's alone (mayChangeRung): a roster owner on an orphan may
+// share it but not move its rung, because making it private hides it
+// from everybody, them included (team_owner.go). Only the row changes —
+// the rung is not part of the document — under the member guard, inside
+// the writer transaction, as every owner action is.
+func (a *app) saveDeckAccess(w http.ResponseWriter, r *http.Request) {
+ u, ok := a.viewer(w, r)
+ if !ok {
+ return
+ }
+ d, ok := a.ownedDeckFor(w, r, u, a.mayChangeRung)
+ if !ok {
+ return
+ }
+ rung := r.PostFormValue("rung")
+ if !validRung(rung) {
+ w.WriteHeader(http.StatusUnprocessableEntity)
+ a.renderSharePage(w, r, u, d, "", rung, rastrillo.T(r, "slides.deck.rung.invalid"))
+ return
+ }
+ if rung != d.Rung {
+ err := a.guarded(r.Context(), a.memberGuard(r.Context(), u), func(db *gorm.DB) error {
+ // UpdateColumn: who can open a deck is not an edit of it,
+ // so the list's "edited 2 hours ago" does not move.
+ return db.Model(&Deck{}).Where("id = ? AND owner_id = ?", d.ID, d.OwnerID).
+ UpdateColumn("rung", rung).Error
+ })
+ if a.guardRefused(w, r, err) {
+ return
+ }
+ if err != nil {
+ a.fail(w, r, "change a deck's rung", err)
+ return
+ }
+ }
+ http.Redirect(w, r, "/d/"+d.Sqid+"/share", http.StatusSeeOther)
+}
+
// --- POST /d/{sqid}/share/{id}/revoke ---
// revokeShareLink serves POST /d/{sqid}/share/{id}/revoke.
diff --git a/internal/slides/team_guard_test.go b/internal/slides/team_guard_test.go
index 7912d1f..b15e861 100644
--- a/internal/slides/team_guard_test.go
+++ b/internal/slides/team_guard_test.go
@@ -102,7 +102,7 @@ func (f *teamFixture) api(token, method, path, body string) *httptest.ResponseRe
type teamSnapshot struct {
decks, updates, links, revoked, presentations int64
uploads, uploadsLanded, uploadsSpent, assets int64
- title string
+ title, rung string
seq int64
}
@@ -123,7 +123,7 @@ func (f *teamFixture) snapshot(d Deck) teamSnapshot {
if err := g.Take(&row, d.ID).Error; err != nil {
f.t.Fatalf("deck %d gone: %v", d.ID, err)
}
- s.title, s.seq = row.Title, row.Seq
+ s.title, s.rung, s.seq = row.Title, row.Rung, row.Seq
return s
}
@@ -187,6 +187,9 @@ func TestTeamEveryWriteRouteRefusesALapseBeforeCommit(t *testing.T) {
{"settings", nil, func() *httptest.ResponseRecorder {
return f.post(deckPath(plan)+"/settings", url.Values{"title": {"Renamed"}, "theme": {defaultTheme}, "rung": {rungPrivate}})
}},
+ {"share access", nil, func() *httptest.ResponseRecorder {
+ return f.post(deckPath(plan)+"/share/access", url.Values{"rung": {rungPrivate}})
+ }},
{"delete", nil, func() *httptest.ResponseRecorder { return f.post(deckPath(plan)+"/delete", nil) }},
{"share link", nil, func() *httptest.ResponseRecorder { return f.post(deckPath(plan)+"/share", nil) }},
{"share revoke", nil, func() *httptest.ResponseRecorder {
diff --git a/internal/slides/team_review_test.go b/internal/slides/team_review_test.go
index f630ec9..8137a5e 100644
--- a/internal/slides/team_review_test.go
+++ b/internal/slides/team_review_test.go
@@ -149,6 +149,9 @@ func TestTeamRosterOwnerSharesAndRetitlesOrphansOnly(t *testing.T) {
t.Fatalf("a member's %s on an orphan = %d, want 404", p, got.Code)
}
}
+ if got := f.post(deckPath(orphan)+"/share/access", url.Values{"rung": {rungPrivate}}); got.Code != 404 {
+ t.Fatalf("a member's rung change on an orphan = %d, want 404", got.Code)
+ }
// The departed owner re-added: the deck has a live owner again.
f.dir.Set(teamSubject('d'), "member")
@@ -160,9 +163,19 @@ func TestTeamRosterOwnerSharesAndRetitlesOrphansOnly(t *testing.T) {
// And the owner themselves still has every power, delete included.
f.freshHomeSignIn(teamSubject('d'))
- if got := f.post(deckPath(orphan)+"/settings", url.Values{"title": {"Mine"}, "theme": {"ink"}, "rung": {rungPrivate}}); got.Code != http.StatusSeeOther {
+ if got := f.get(deckPath(orphan) + "/share"); !strings.Contains(got.Body.String(), `name="rung"`) {
+ t.Fatalf("the owner's share page offers no rung:\n%s", got.Body.String())
+ }
+ if got := f.post(deckPath(orphan)+"/share/access", url.Values{"rung": {rungPrivate}}); got.Code != http.StatusSeeOther {
t.Fatalf("the owner's own rung change = %d", got.Code)
}
+ f.d.G.Take(&row, orphan.ID)
+ if row.Rung != rungPrivate {
+ t.Fatalf("the owner's rung change did not land: %q", row.Rung)
+ }
+ if got := f.post(deckPath(orphan)+"/settings", url.Values{"title": {"Mine"}, "theme": {"ink"}, "rung": {rungTeam}}); got.Code != http.StatusSeeOther {
+ t.Fatalf("the owner's own rung change through the settings POST = %d", got.Code)
+ }
if got := f.post(deckPath(orphan)+"/delete", nil); got.Code != http.StatusSeeOther {
t.Fatalf("the owner's own delete = %d", got.Code)
}
diff --git a/internal/slides/templates/deck_settings.html b/internal/slides/templates/deck_settings.html
index fad4935..298d747 100644
--- a/internal/slides/templates/deck_settings.html
+++ b/internal/slides/templates/deck_settings.html
@@ -1,10 +1,10 @@
{{/* deck_settings — GET/POST /d/{sqid}/settings.
- The deck's own settings and nothing else: name, theme, and who can
- open it. The rung is a choice-field rather than a select, because
- the three answers each need a sentence — "Private" on its own does
- not say who that leaves out — and because a radio group signals
- pick-one where a dropdown hides the alternatives.
+ The deck's name and theme as a form, for somebody with scripts off:
+ with them on, both are the editor's inspector (Docs' shape — a
+ document's settings are an inspector, not a page), and nothing
+ links here but the editor's <noscript>. Who can open the deck was a
+ third field; it is the share page's now, and this page says so.
Deleting is not a control on this form. It is a link to its own
page, which asks the question and carries the only button that
@@ -22,14 +22,16 @@
"ID" "theme" "Name" "theme" "Label" .ThemeLabel
"Options" .Themes "Required" true
"Error" (index .Errors "Theme")}}
- {{if .Rungs}}{{template "choice-field" dict
- "Legend" .RungLegend "Name" "rung" "Options" .Rungs}}
{{template "form-error" (index .Errors "Rung")}}
- {{end}}{{template "form-foot" dict
+ {{template "form-foot" dict
"Submit" .Submit "CancelHref" .CancelHref "CancelLabel" .CancelLabel}}
</form>
</div>
-{{if .DeleteHref}}<div rst-box-head><h2>{{.DeleteLabel}}</h2></div>
+{{if .AccessHref}}<div rst-box>
+ <p>{{.AccessBody}}</p>
+ <p><a rst-btn href="{{.AccessHref}}">{{.AccessLabel}}</a></p>
+</div>
+{{end}}{{if .DeleteHref}}<div rst-box-head><h2>{{.DeleteLabel}}</h2></div>
<div rst-box>
<p>{{.DeleteBody}}</p>
<p><a rst-btn href="{{.DeleteHref}}">{{.DeleteLabel}}</a></p>
diff --git a/internal/slides/templates/share.html b/internal/slides/templates/share.html
index 9e7611c..cddde74 100644
--- a/internal/slides/templates/share.html
+++ b/internal/slides/templates/share.html
@@ -1,8 +1,12 @@
-{{/* share — GET /d/{sqid}/share, a deck's read-only links.
+{{/* share — GET /d/{sqid}/share, who can open a deck: the rung, and
+ its read-only links.
- The screen is three things in the order they matter: the link that
- was just made (once, and never again), what a link costs to hand
- out, and the links that already exist with the one button that
+ Docs' shape (Paul, 2026-11-11): Share… in the bar opens one page for
+ everything about who reaches the deck. First the rung — who can open
+ it — as a real POST form of three cards, so it works with scripts
+ off; then the links, three things in the order they matter: the link
+ that was just made (once, and never again), what a link costs to
+ hand out, and the links that already exist with the one button that
turns each of them off.
The new link is a callout plus a read-only field rather than a line
@@ -11,7 +15,28 @@
you select cleanly with no script at all. */}}
{{define "content"}}
{{template "back-nav" dict "Href" .BackHref "Label" .BackLabel}}
-{{template "page-header" dict "Title" .Title}}
+{{template "page-header" dict "Title" .Title "Sub" .DeckTitle}}
+
+{{/* Who can open the deck. The owner chooses (mayChangeRung); a roster
+ owner on an orphan, who may share it but not move it, reads it. */}}
+<section slides-share-access aria-labelledby="slides-share-access">
+<div rst-box-head><h2 id="slides-share-access">{{.AccessHeading}}</h2></div>
+<div rst-box>
+ {{if .Rungs}}
+ <form rst-form method="post" action="{{.AccessAction}}">
+ {{template "choice-field" dict "Legend" .AccessLegend "LegendHidden" true "Name" "rung" "Options" .Rungs}}
+ {{template "form-error" .AccessError}}
+ <div rst-form-foot><button rst-btn="primary" type="submit">{{.AccessSubmit}}</button></div>
+ </form>
+ {{else}}
+ <p><strong>{{.AccessCurrent}}</strong>{{with .AccessCurrentDesc}} — {{.}}{{end}}</p>
+ <p rst-muted>{{.AccessFixed}}</p>
+ {{end}}
+</div>
+</section>
+
+<section slides-share-links aria-labelledby="slides-share-links">
+<div rst-box-head><h2 id="slides-share-links">{{.LinksHeading}}</h2></div>
{{if .NewURL}}
<div rst-box>
@@ -67,4 +92,5 @@
<form method="post" action="{{.Action}}" rst-form>
<button rst-btn="primary lg" type="submit">{{.CreateLabel}}</button>
</form>
+</section>
{{end}}
diff --git a/internal/slidestest/share_test.go b/internal/slidestest/share_test.go
index 311780c..a8fc1bd 100644
--- a/internal/slidestest/share_test.go
+++ b/internal/slidestest/share_test.go
@@ -225,7 +225,7 @@ func TestShareIsTheOwnersAlone(t *testing.T) {
}, mine...); rec.Code != http.StatusSeeOther {
t.Fatalf("raising the rung: status %d\n%s", rec.Code, rec.Body)
}
- mustGet(t, a, path, http.StatusOK, theirs)
+ mustGet(t, a, path+"?slide=1", http.StatusOK, theirs)
mustGet(t, a, path+"/share", http.StatusNotFound, theirs)
if rec := post(t, a, path+"/share", nil, theirs...); rec.Code != http.StatusNotFound {
@@ -243,3 +243,66 @@ func TestShareIsTheOwnersAlone(t *testing.T) {
}
mustGet(t, a, "/s/"+token, http.StatusOK, nil)
}
+
+// TestShareChoosesWhoCanOpenTheDeck: who can open a deck is chosen on
+// its share page, as general access is in Docs — a real POST form of
+// option cards, so it works with scripts off. It used to be a field of
+// the settings form, which still takes a rung but no longer shows one.
+func TestShareChoosesWhoCanOpenTheDeck(t *testing.T) {
+ a := newSharedApp(t)
+ mine := signedIn(t, a, allowedAddress)
+ theirs := signedIn(t, a, otherAddress)
+ path := createDeck(t, a, mine, "Offsite")
+
+ page := mustGet(t, a, path+"/share", http.StatusOK, mine).Body.String()
+ form := regexp.MustCompile(`(?s)<form rst-form method="post" action="` + path + `/share/access">(.*?)</form>`).FindStringSubmatch(page)
+ if form == nil {
+ t.Fatalf("the share page has no form for who can open the deck:\n%s", page)
+ }
+ for _, want := range []string{`<input type="radio" name="rung" value="private" checked>`, `<input type="radio" name="rung" value="team">`, "Only me", "Everyone here", `type="submit"`} {
+ if !strings.Contains(form[1], want) {
+ t.Errorf("the access form lacks %s:\n%s", want, form[1])
+ }
+ }
+ mustGet(t, a, path+"?slide=1", http.StatusNotFound, theirs)
+
+ if rec := post(t, a, path+"/share/access", url.Values{"rung": {"team"}}, mine...); rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != path+"/share" {
+ t.Fatalf("POST %s/share/access: status %d to %q, want 303 back to the share page", path, rec.Code, rec.Header().Get("Location"))
+ }
+ mustGet(t, a, path+"?slide=1", http.StatusOK, theirs)
+ if page := mustGet(t, a, path+"/share", http.StatusOK, mine).Body.String(); !strings.Contains(page, `value="team" checked`) {
+ t.Errorf("the share page does not show the new rung chosen:\n%s", page)
+ }
+
+ // A rung no screen sets, or none at all, is refused on the page
+ // with the form, and changes nothing.
+ for _, rung := range []string{"granted", "", "everyone"} {
+ rec := post(t, a, path+"/share/access", url.Values{"rung": {rung}}, mine...)
+ if rec.Code != http.StatusUnprocessableEntity || !strings.Contains(rec.Body.String(), "Pick who can open this deck.") {
+ t.Errorf("POST rung=%q: status %d, want 422 with the error\n%s", rung, rec.Code, rec.Body)
+ }
+ }
+ mustGet(t, a, path+"?slide=1", http.StatusOK, theirs)
+
+ // A member reads the deck and cannot move it.
+ if rec := post(t, a, path+"/share/access", url.Values{"rung": {"private"}}, theirs...); rec.Code != http.StatusNotFound {
+ t.Errorf("a member's rung change: status %d, want 404", rec.Code)
+ }
+ mustGet(t, a, path+"?slide=1", http.StatusOK, theirs)
+
+ // The settings form no longer carries the rung, and saving it
+ // leaves the rung where it is.
+ settings := mustGet(t, a, path+"/settings", http.StatusOK, mine).Body.String()
+ if strings.Contains(settings, `name="rung"`) || !strings.Contains(settings, `href="`+path+`/share"`) {
+ t.Errorf("the settings form still offers the rung, or does not say where it went:\n%s", settings)
+ }
+ if rec := post(t, a, path+"/settings", url.Values{"title": {"Offsite 2027"}, "theme": {"ink"}}, mine...); rec.Code != http.StatusSeeOther {
+ t.Fatalf("POST %s/settings without a rung: status %d\n%s", path, rec.Code, rec.Body)
+ }
+ mustGet(t, a, path+"?slide=1", http.StatusOK, theirs)
+
+ if rec := post(t, a, path+"/share/access", url.Values{"rung": {"private"}}, mine...); rec.Code != http.StatusSeeOther {
+ t.Fatalf("lowering the rung: status %d", rec.Code)
+ }
+ mustGet(t, a, path+"?slide=1", http.StatusNotFound, theirs)
+}