oficina / slides Public

Slides team mode: #33 round 1 — Paul's orphan ruling, the asset lapse routes, held streams

- Paul, 2026-10-30, on #33 ("share only, no delete for now"; "team-visible
  decks only"). On an orphan, a roster owner may share it (the share page and
  its links) and change its title and theme. They may not delete it or change
  its rung. The orphan rule covers team-rung decks only, so a departed member's
  private deck gets no owner powers, even with a read grant. Each power is its
  own predicate (mayShareDeck, mayRetitleDeck, mayChangeRung, mayDeleteDeck),
  which ownedDeckFor takes. The settings page offers no rung and no delete to
  a roster owner on an orphan, and a posted narrowing is a 403. Recorded in
  spec §6.4 with Fable's two allowlist consequences (deviation 4).
- Required test 2: PUT /d/{sqid}/uploads/{ref} and POST /d/{sqid}/assets are in
  the lapse table, and the snapshot reads back landed and spent receipts and
  DeckAsset rows.
- Note 1: under Unknown the deck stream and the projector stream are held
  open. They deliver nothing but comment pings, re-ask at the roster's
  RetryAfter, and catch up with the current seq or slide when standing
  returns. presentStream opens under Unknown (a projector's EventSource fails
  for good on a 503), and a gone presenter is still a 410.
- Note 3: a first local sign-in in team mode seeds no sample deck and logs no
  error.

Team mode off is still byte-identical except /api/team.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 80fd3c9936d7156cfb20f32728c005da7a0cf0fc parent 2298c52
15 files changed, +649 −192
  • AGENTS.md +15 −7
  • docs/superpowers/specs/2026-09-07-slides-design.md +27 −6
  • internal/slides/decks.go +37 −12
  • internal/slides/home.go +4 −0
  • internal/slides/live.go +59 −17
  • internal/slides/presentation.go +78 −23
  • internal/slides/share.go +4 −4
  • internal/slides/team_access.go +40 −10
  • internal/slides/team_guard_test.go +65 −20
  • internal/slides/team_owner.go +61 −34
  • internal/slides/team_review_test.go +73 −30
  • internal/slides/team_stream_test.go +145 −22
  • internal/slides/team_survivors_test.go +36 −2
  • internal/slides/templates/deck_settings.html +4 −4
  • internal/slides/viewer.go +1 −1

CI passed — run details

diff --git a/AGENTS.md b/AGENTS.md
index 31fdb4e..eabafad 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -617,13 +617,21 @@ non-team instance is `GET /api/team` answering `{"team_mode":false}`
presentation stands on its presenter's reach (`team_present.go`): every
`/p/…` request and every projector or follower delivery re-decides; a
presenter who is gone ends the talk (as offboarding does), one whose
- standing is unknown gets a 503 and the talk waits. Without a Member
- lease only a grant holds — asked after the reach query, because
- `State` latches.
-- **Ownership and orphans** (`team_owner.go`): an owner owns their deck
- only while Member. Paul's Sheets ruling, applied: a roster owner owns
- any deck they can already read whose owner the roster says is gone.
- A removed member's private decks reach nobody.
+ standing is unknown gets a 503 on pages and the talk waits. While
+ standing is unknown both streams are **held**, not ended: open,
+ delivering nothing but comment pings, re-asked at `streamHoldRetry`
+ (the roster's `RetryAfter`), and caught up when standing returns — a
+ projector's EventSource fails for good on a 503, so `presentStream`
+ opens under Unknown too. Without a Member lease only a grant holds —
+ asked after the reach query, because `State` latches.
+- **Ownership and orphans** (`team_owner.go`; Paul, 2026-10-30, #33): an
+ owner owns their deck only while Member. On an orphan — a team-rung
+ deck whose owner the roster says is gone — a roster owner may share it
+ and change its title and theme, and may not delete it or change its
+ rung. One predicate per power (`mayShareDeck`, `mayRetitleDeck`,
+ `mayChangeRung`, `mayDeleteDeck`), passed to `ownedDeckFor`: an owner
+ screen asks for the one power it needs. A departed member's private
+ deck is nobody's orphan.
- **Lists under Unknown** (Paul, 2026-10-28): the deck list shows the
grants with a notice (`teamPartial`, asked after listing, never for
NotMember); the dashboard feed and the API's JSON list are unavailable
diff --git a/docs/superpowers/specs/2026-09-07-slides-design.md b/docs/superpowers/specs/2026-09-07-slides-design.md
index c1a81a7..06393ed 100644
--- a/docs/superpowers/specs/2026-09-07-slides-design.md
+++ b/docs/superpowers/specs/2026-09-07-slides-design.md
@@ -795,7 +795,10 @@ ported after Sheets in Paul's order. A team instance (Alta's
Ownership (`owner_id`) holds only while Member, as Docs' `owner_id`
rule does.
- **Removal** takes effect within the lease, for existing sessions,
- agents, the deck stream and presentations alike. Sessions and agent
+ agents, the deck stream and presentations alike. While standing cannot
+ be read, the deck stream and a projector's stream are held open
+ delivering nothing and re-asked every 5 s, then caught up, rather than
+ ended: a projector's EventSource does not survive a 503. Sessions and agent
tokens are kept and reach grants only (Docs' and Sheets' rule, not
§6.1's revocation: the roster can re-add somebody at any moment, and a
removed person's grants are still theirs). A presentation stands on
@@ -808,11 +811,29 @@ ported after Sheets in Paul's order. A team instance (Alta's
rather than short. A deck page that needs standing is a retryable 503,
never a 404; creating a deck is members only (403 guest, 503
Unknown).
-- **Orphaned decks** (Paul's ruling for Sheets, 2026-10-28, applied):
- a roster owner owns any deck they can read whose owner the roster says
- is gone — settings, rung, share links, delete. Nothing is written; the
- owner's return ends it. A removed member's private decks are readable
- by nobody, as in Docs; widening that is Paul's call.
+- **Orphaned decks — RULED 2026-10-30 by Paul** (oficina/slides #33,
+ after his Sheets ruling of 2026-10-28 on oficina/sheets #52): "share
+ only, no delete for now (may change his mind later)", and "team-visible
+ decks only". An orphan is a deck **on the team rung** whose owner the
+ roster definitely says is gone (NotMember, or no owner row at all; an
+ owner whose standing cannot be read is not gone). On an orphan a
+ roster owner may **share** it (the share page, minting and revoking
+ links) and **change its title and theme**. A roster owner may **not
+ delete** it (delete stays `owner_id`, while Member), and may **not
+ change its rung**: making it private hides it from everybody, the
+ roster owner included, which Paul treats as a soft-delete. A departed
+ member's private deck is no orphan, even to a roster owner holding a
+ grant to read it. Nothing is written: the owner's return ends it. Each
+ power is its own predicate in `team_owner.go` (`mayShareDeck`,
+ `mayRetitleDeck`, `mayChangeRung`, `mayDeleteDeck`), so widening one
+ later is one line.
+- **The allowlist in team mode** (Fable's ruling on deviation 4, #33):
+ `SLIDES_ALLOWED_ADDRESSES` only decides who may use the local door. Two
+ consequences, accepted: (1) an address taken off the list keeps its
+ session, as a guest reaching grants only (or as the roster says, if
+ linked), until it expires — where §6.1 signs it out of every device;
+ (2) Alta must not write the owner's address into it, or that address
+ is the instance's one local door.
- **Home-only members**: a roster Member with no account here signs in
with Home alone as an addressless `users` row, shown as "Oficina
account …xxxx". Nothing can be granted to them by address, since they
diff --git a/internal/slides/decks.go b/internal/slides/decks.go
index 5c670bd..9b1d381 100644
--- a/internal/slides/decks.go
+++ b/internal/slides/decks.go
@@ -526,15 +526,18 @@ func (a *app) deckFor(w http.ResponseWriter, r *http.Request, u User) (Deck, boo
return Deck{}, false
}
-// ownedDeckFor is deckFor for a write: settings and delete are the
-// owner's alone, and a team member who can read the deck gets the same
-// 404 as a stranger rather than a 403 that would confirm it exists.
-func (a *app) ownedDeckFor(w http.ResponseWriter, r *http.Request, u User) (Deck, bool) {
+// ownedDeckFor is deckFor for an owner's screen: settings, sharing and
+// delete are the owner's, and a team member who can read the deck gets
+// the same 404 as a stranger rather than a 403 that would confirm it
+// exists. may is the one power the screen needs (team_owner.go): outside
+// team mode every one of them is the owner's alone; in team mode a
+// roster owner holds some of them on an orphan.
+func (a *app) ownedDeckFor(w http.ResponseWriter, r *http.Request, u User, may func(context.Context, User, Deck) bool) (Deck, bool) {
d, ok := a.deckFor(w, r, u)
if !ok {
return Deck{}, false
}
- if !a.ownsDeck(r.Context(), u, d) {
+ if !may(r.Context(), u, d) {
if a.teamUnknown(u) {
a.teamUnavailable(w, r)
return Deck{}, false
@@ -961,7 +964,7 @@ type deckSettingsPage struct {
func (a *app) settingsPage(r *http.Request, u User, d Deck, title, theme, rung string, errs map[string]string) deckSettingsPage {
base := "/d/" + d.Sqid
- return deckSettingsPage{
+ page := deckSettingsPage{
shell: a.shellFor(r, u, onDeck(rastrillo.T(r, "slides.deck.settings"), d.Title)),
Title: rastrillo.T(r, "slides.deck.settings"),
Action: base + "/settings",
@@ -981,6 +984,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
+ }
+ if !a.mayDeleteDeck(r.Context(), u, d) {
+ page.DeleteHref = ""
+ }
+ return page
}
func (a *app) deckSettings(w http.ResponseWriter, r *http.Request) {
@@ -988,7 +1001,7 @@ func (a *app) deckSettings(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
- d, ok := a.ownedDeckFor(w, r, u)
+ d, ok := a.ownedDeckFor(w, r, u, a.mayRetitleDeck)
if !ok {
return
}
@@ -1009,7 +1022,7 @@ func (a *app) saveDeckSettings(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
- d, ok := a.ownedDeckFor(w, r, u)
+ d, ok := a.ownedDeckFor(w, r, u, a.mayRetitleDeck)
if !ok {
return
}
@@ -1018,6 +1031,18 @@ func (a *app) saveDeckSettings(w http.ResponseWriter, r *http.Request) {
title := p.String("title")
theme := r.PostFormValue("theme")
rung := r.PostFormValue("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
+ }
+ if rung != d.Rung {
+ a.errorPage(w, r, http.StatusForbidden, kindStatus, "")
+ return
+ }
+ }
errs := map[string]string{}
if !p.OK() {
errs["Title"] = rastrillo.T(r, "slides.deck.title.required")
@@ -1072,7 +1097,7 @@ func (a *app) confirmDeleteDeck(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
- d, ok := a.ownedDeckFor(w, r, u)
+ d, ok := a.ownedDeckFor(w, r, u, a.mayDeleteDeck)
if !ok {
return
}
@@ -1108,7 +1133,7 @@ func (a *app) deleteDeck(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
- d, ok := a.ownedDeckFor(w, r, u)
+ d, ok := a.ownedDeckFor(w, r, u, a.mayDeleteDeck)
if !ok {
return
}
@@ -1135,8 +1160,8 @@ func (a *app) deleteDeck(w http.ResponseWriter, r *http.Request) {
// deleteDeckTx is deleteDeck's transaction: every row of d, and the live
// presentations it ended in live, to be told after the commit. The deck
-// row goes by its own owner_id, which ownedDeckFor confirmed is the
-// viewer's — or, in team mode, an orphan a roster owner holds.
+// row goes by its own owner_id, which ownedDeckFor (mayDeleteDeck)
+// confirmed is the viewer's.
func deleteDeckTx(tx *gorm.DB, d Deck, live *[]Presentation) error {
*live = nil
if err := tx.Where("deck_id = ? AND ended_at IS NULL", d.ID).
diff --git a/internal/slides/home.go b/internal/slides/home.go
index dacb14d..6ace455 100644
--- a/internal/slides/home.go
+++ b/internal/slides/home.go
@@ -217,6 +217,10 @@ func (a *app) homeLocalComplete(w http.ResponseWriter, r *http.Request) {
switch {
case err != nil:
a.logger.Error("slides: create user before resuming a Home link", "err", err)
+ case created && a.team != nil:
+ // Team mode: a local account made here has no link yet,
+ // so it is a guest, and guests create nothing; no sample
+ // deck (team_access.go's teamIdentify says the same).
case created:
if has, err := hasDeck(r.Context(), a.db.G, u); err != nil {
a.logger.Error("slides: check for an existing deck before seeding", "user", u.ID, "err", err)
diff --git a/internal/slides/live.go b/internal/slides/live.go
index dc1df5c..59ef67a 100644
--- a/internal/slides/live.go
+++ b/internal/slides/live.go
@@ -604,9 +604,13 @@ func (a *app) deckStream(w http.ResponseWriter, r *http.Request) {
// Team mode: the stream stands on the viewer's standing, so it is
// re-decided before every delivery and again when a Member lease
- // runs out (teamStreamAccess), and ends on anything but a renewed
- // answer. A silent stream cannot outlive a removal. Outside team
- // mode renewC is nil, never ready, and nothing here runs.
+ // runs out (teamStreamAccess), and ends on a definite "no". A silent
+ // stream cannot outlive a removal. While standing cannot be read the
+ // stream is HELD: open, delivering nothing but comment pings, re-asking
+ // at streamHoldRetry (the roster's RetryAfter), and caught up (the current seq and presence)
+ // the moment standing returns — so a Home blip neither leaks an
+ // update nor strands a tab on a failed reconnect (Fable #33, note 1).
+ // Outside team mode renewC is nil, never ready, and nothing here runs.
var renew *time.Timer
var renewC <-chan time.Time
defer func() {
@@ -614,14 +618,21 @@ func (a *app) deckStream(w http.ResponseWriter, r *http.Request) {
renew.Stop()
}
}()
+ held := false
stillReaches := func() bool {
if a.team == nil {
return true
}
- ok, next := a.teamStreamAccess(r, d.ID)
- switch {
- case !ok:
+ decision, next := a.teamStreamAccess(r, d.ID)
+ switch decision {
+ case streamEnds:
return false
+ case streamHolds:
+ held, next = true, streamHoldRetry
+ default:
+ held = false
+ }
+ switch {
case next <= 0:
renewC = nil
case renew == nil:
@@ -634,14 +645,11 @@ func (a *app) deckStream(w http.ResponseWriter, r *http.Request) {
return true
}
- // write is every byte's one exit: deadline armed, bytes, flush. The
+ // send is every byte's one exit: deadline armed, bytes, flush. The
// deadline error is ignored deliberately — a ResponseWriter that
// cannot set deadlines still streams, unbounded — while a write
// error ends the handler, because it means the client is gone.
- write := func(text string) bool {
- if !stillReaches() {
- return false
- }
+ send := func(text string) bool {
_ = rc.SetWriteDeadline(time.Now().Add(streamWriteDeadline))
if _, err := io.WriteString(w, text); err != nil {
return false
@@ -649,10 +657,10 @@ func (a *app) deckStream(w http.ResponseWriter, r *http.Request) {
fl.Flush()
return true
}
- seqEvent := func(seq int64) bool {
- return write("event: update\ndata: " + strconv.FormatInt(seq, 10) + "\n\n")
+ seqText := func(seq int64) string {
+ return "event: update\ndata: " + strconv.FormatInt(seq, 10) + "\n\n"
}
- presenceEvent := func(set live.PresenceSet) bool {
+ presenceText := func(set live.PresenceSet) (string, bool) {
// A nil set must go out as `[]`, not `null`: the client reads
// this as "everybody here", and null is a different sentence.
if set == nil {
@@ -661,9 +669,39 @@ func (a *app) deckStream(w http.ResponseWriter, r *http.Request) {
body, err := json.Marshal(set)
if err != nil {
a.logger.Error("slides: encode presence", "deck", d.Sqid, "err", err)
+ return "", false
+ }
+ return "event: presence\ndata: " + string(body) + "\n\n", true
+ }
+ // catchUp is what a held stream owes when standing returns: what the
+ // connect events say, read afresh.
+ catchUp := func() bool {
+ var now Deck
+ if err := a.db.G.WithContext(r.Context()).Take(&now, d.ID).Error; err != nil {
return false
}
- return write("event: presence\ndata: " + string(body) + "\n\n")
+ presence, ok := presenceText(a.live.Snapshot(d.Sqid))
+ return ok && send(seqText(now.Seq)) && send(presence)
+ }
+ // write re-decides (team mode) and then sends; while held only a
+ // comment carries, since it says nothing about the deck.
+ write := func(text string) bool {
+ wasHeld := held
+ if !stillReaches() {
+ return false
+ }
+ if held {
+ return !strings.HasPrefix(text, ":") || send(text)
+ }
+ if wasHeld && !catchUp() {
+ return false
+ }
+ return send(text)
+ }
+ seqEvent := func(seq int64) bool { return write(seqText(seq)) }
+ presenceEvent := func(set live.PresenceSet) bool {
+ text, ok := presenceText(set)
+ return ok && write(text)
}
if !seqEvent(current.Seq) {
@@ -716,11 +754,15 @@ func (a *app) deckStream(w http.ResponseWriter, r *http.Request) {
}
heartbeat.Reset(streamHeartbeat)
case <-renewC:
- // The Member lease this stream stood on is up: renewed under
- // a new one, or the stream ends.
+ // The Member lease this stream stood on is up, or a held
+ // stream's retry is due: renewed, still held, or ended.
+ wasHeld := held
if !stillReaches() {
return
}
+ if wasHeld && !held && !catchUp() {
+ return
+ }
}
}
}
diff --git a/internal/slides/presentation.go b/internal/slides/presentation.go
index 0df236b..aa5c20b 100644
--- a/internal/slides/presentation.go
+++ b/internal/slides/presentation.go
@@ -189,6 +189,28 @@ func eventFor(p Presentation) present.Event {
// dead pairing code is a 404 too (remotePair), because neither should
// confirm anything to a stranger who is guessing.
func (a *app) presentationFor(w http.ResponseWriter, r *http.Request) (Presentation, bool) {
+ p, ok := a.presentationRow(w, r)
+ if !ok {
+ return Presentation{}, false
+ }
+ // Team mode: the talk stands on its presenter's reach to the deck
+ // (team_present.go). Gone ends it, and it is over like any other.
+ switch reach, _ := a.presentationStands(r.Context(), p); reach {
+ case presenterGone:
+ a.gone(w, r)
+ return Presentation{}, false
+ case presenterUnknown:
+ a.teamUnavailable(w, r)
+ return Presentation{}, false
+ }
+ return p, true
+}
+
+// presentationRow is presentationFor before team mode's presenter check:
+// the row, 404 or 410. The projector's stream starts here, because it
+// holds rather than refuses while the presenter's standing is unknown
+// (streamPresentation).
+func (a *app) presentationRow(w http.ResponseWriter, r *http.Request) (Presentation, bool) {
var p Presentation
err := a.db.G.WithContext(r.Context()).
Where("sqid = ?", chi.URLParam(r, "session")).Take(&p).Error
@@ -205,16 +227,6 @@ func (a *app) presentationFor(w http.ResponseWriter, r *http.Request) (Presentat
a.gone(w, r)
return Presentation{}, false
}
- // Team mode: the talk stands on its presenter's reach to the deck
- // (team_present.go). Gone ends it, and it is over like any other.
- switch reach, _ := a.presentationStands(r.Context(), p); reach {
- case presenterGone:
- a.gone(w, r)
- return Presentation{}, false
- case presenterUnknown:
- a.teamUnavailable(w, r)
- return Presentation{}, false
- }
return p, true
}
@@ -1118,10 +1130,18 @@ const (
// (internal/slides/present), and why the connect event matters: a
// dropped page reconnects and is immediately right again.
func (a *app) presentStream(w http.ResponseWriter, r *http.Request) {
- p, ok := a.presentationFor(w, r)
+ // Not presentationFor: a projector's EventSource that is answered a
+ // 503 fails for good, so in team mode the stream opens while the
+ // presenter's standing is unknown and holds (streamPresentation). A
+ // presenter who is gone is still the 410.
+ p, ok := a.presentationRow(w, r)
if !ok {
return
}
+ if reach, _ := a.presentationStands(r.Context(), p); reach == presenterGone {
+ a.gone(w, r)
+ return
+ }
a.streamPresentation(w, r, p, nil)
}
@@ -1166,9 +1186,13 @@ func (a *app) streamPresentation(w http.ResponseWriter, r *http.Request, p Prese
// Team mode: the talk stands on its presenter's reach, re-decided
// before every delivery and again when the presenter's Member lease
// runs out (team_present.go). A presenter who is gone ends the talk
- // and the stream; one whose standing cannot be read ends the stream
- // alone, and the reconnect is answered 503 until it can. Outside
- // team mode renewC is nil and presentationStands always stands.
+ // and the stream. While the presenter's standing cannot be read the
+ // stream is HELD: open, delivering nothing but comment pings,
+ // re-asking at streamHoldRetry (the roster's RetryAfter), and sent the talk's current state
+ // the moment it can be read again — a projector's EventSource fails
+ // for good on a 503, so ending the stream would blank the room
+ // (Fable #33, note 1). Outside team mode renewC is nil and
+ // presentationStands always stands.
var renew *time.Timer
var renewC <-chan time.Time
defer func() {
@@ -1176,14 +1200,21 @@ func (a *app) streamPresentation(w http.ResponseWriter, r *http.Request, p Prese
renew.Stop()
}
}()
+ held := false
stands := func() bool {
if a.team == nil {
return true
}
reach, next := a.presentationStands(r.Context(), p)
- switch {
- case reach != presenterReaches:
+ switch reach {
+ case presenterGone:
return false
+ case presenterUnknown:
+ held, next = true, streamHoldRetry
+ default:
+ held = false
+ }
+ switch {
case next <= 0:
renewC = nil
case renew == nil:
@@ -1196,13 +1227,7 @@ func (a *app) streamPresentation(w http.ResponseWriter, r *http.Request, p Prese
return true
}
- write := func(text string) bool {
- if alive != nil && !alive() {
- return false
- }
- if !stands() {
- return false
- }
+ send := func(text string) bool {
// The deadline error is ignored deliberately: a
// ResponseWriter that cannot set deadlines still streams,
// unbounded. A write error ends the handler, because it means
@@ -1214,6 +1239,32 @@ func (a *app) streamPresentation(w http.ResponseWriter, r *http.Request, p Prese
fl.Flush()
return true
}
+ // catchUp is what a held stream owes when the presenter's standing
+ // returns: the talk as it is now, read afresh.
+ catchUp := func() bool {
+ var now Presentation
+ if err := a.db.G.WithContext(r.Context()).Take(&now, p.ID).Error; err != nil {
+ return false
+ }
+ body, err := json.Marshal(eventFor(now))
+ return err == nil && send("event: slide\ndata: "+string(body)+"\n\n")
+ }
+ write := func(text string) bool {
+ if alive != nil && !alive() {
+ return false
+ }
+ wasHeld := held
+ if !stands() {
+ return false
+ }
+ if held {
+ return !strings.HasPrefix(text, ":") || send(text)
+ }
+ if wasHeld && !catchUp() {
+ return false
+ }
+ return send(text)
+ }
event := func(e present.Event) bool {
body, err := json.Marshal(e)
if err != nil {
@@ -1263,9 +1314,13 @@ func (a *app) streamPresentation(w http.ResponseWriter, r *http.Request, p Prese
}
heartbeat.Reset(streamHeartbeat)
case <-renewC:
+ wasHeld := held
if !stands() {
return
}
+ if wasHeld && !held && !catchUp() {
+ return
+ }
}
}
}
diff --git a/internal/slides/share.go b/internal/slides/share.go
index 678dcf4..631ff9d 100644
--- a/internal/slides/share.go
+++ b/internal/slides/share.go
@@ -121,7 +121,7 @@ func (a *app) deckShare(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
- d, ok := a.ownedDeckFor(w, r, u)
+ d, ok := a.ownedDeckFor(w, r, u, a.mayShareDeck)
if !ok {
return
}
@@ -219,7 +219,7 @@ func (a *app) mintShareLink(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
- d, ok := a.ownedDeckFor(w, r, u)
+ d, ok := a.ownedDeckFor(w, r, u, a.mayShareDeck)
if !ok {
return
}
@@ -251,7 +251,7 @@ func (a *app) mintShareLink(w http.ResponseWriter, r *http.Request) {
//
// Scoped by deck as well as by id, so an id belonging to another deck
// is a 404 rather than a revocation somebody was not entitled to make;
-// the deck itself is already the owner's (ownedDeckFor).
+// the deck itself is already one this person may share (ownedDeckFor).
//
// Revoking twice is not an error. The URL is off either way, and a
// second POST from a double-clicked button should not look like a
@@ -261,7 +261,7 @@ func (a *app) revokeShareLink(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
- d, ok := a.ownedDeckFor(w, r, u)
+ d, ok := a.ownedDeckFor(w, r, u, a.mayShareDeck)
if !ok {
return
}
diff --git a/internal/slides/team_access.go b/internal/slides/team_access.go
index 0ab725b..d7907a0 100644
--- a/internal/slides/team_access.go
+++ b/internal/slides/team_access.go
@@ -173,38 +173,68 @@ func (a *app) withStanding(ctx context.Context, u User) User {
return u
}
+// streamDecision is what one stream delivery may do: deliver, hold (the
+// stream stays open and delivers nothing, because standing cannot be read
+// right now), or end (a definite "no").
+type streamDecision int
+
+const (
+ streamDelivers streamDecision = iota
+ streamHolds
+ streamEnds
+)
+
+// streamHoldRetry is how often a held stream re-asks: the roster's own
+// retry interval. A variable only so a test need not wait it out.
+var streamHoldRetry = roster.RetryAfter
+
// teamStreamAccess decides one deck-stream delivery afresh — session,
// user, roster, reach — and says how long a standing-backed answer may
// stand before it must be asked again: the Member lease's remaining
// time, or 0 when nothing expires on a timer (the answer rested on a
-// grant). Team mode only.
-func (a *app) teamStreamAccess(r *http.Request, deckID int64) (bool, time.Duration) {
+// grant). Unknown standing that a grant does not cover holds rather than
+// ends: nothing is delivered, and nothing is decided against the person
+// either. Team mode only.
+func (a *app) teamStreamAccess(r *http.Request, deckID int64) (streamDecision, time.Duration) {
s, ok := sessions.Current(r)
if !ok {
- return false, 0
+ return streamEnds, 0
}
u, subject, err := a.teamIdentify(r.Context(), s)
- if err != nil {
- return false, 0
+ switch {
+ case errors.Is(err, errTeamUnavailable):
+ return streamHolds, 0
+ case err != nil:
+ return streamEnds, 0
}
u.team = &teamAccess{Access: a.team.Access(r.Context(), subject)}
var n int64
- if err := a.visibleDecks(r.Context(), u).Where("decks.id = ?", deckID).Count(&n).Error; err != nil || n == 0 {
- return false, 0
+ if err := a.visibleDecks(r.Context(), u).Where("decks.id = ?", deckID).Count(&n).Error; err != nil {
+ return streamHolds, 0
}
// Asked after the reach, of the same Access: State latches, so a
// lease that lapsed (or was contended) after the query was built
// reads Unknown here, and then the deck may have been reached
// through the team rung that no longer stands. Without a lease only
// a grant holds, and nothing then expires on a timer.
- if u.team.state() != roster.Member {
- return a.grantedTo(r.Context(), u, Deck{ID: deckID}), 0
+ state := u.team.state()
+ if state != roster.Member {
+ switch {
+ case a.grantedTo(r.Context(), u, Deck{ID: deckID}):
+ return streamDelivers, 0
+ case state == roster.Unknown:
+ return streamHolds, 0
+ }
+ return streamEnds, 0
+ }
+ if n == 0 {
+ return streamEnds, 0
}
renew := u.team.Remaining()
if renew <= 0 {
renew = time.Second
}
- return true, renew
+ return streamDelivers, renew
}
// teamJobOwner is the jobs registry's owner key in team mode. A
diff --git a/internal/slides/team_guard_test.go b/internal/slides/team_guard_test.go
index babc890..834bdd2 100644
--- a/internal/slides/team_guard_test.go
+++ b/internal/slides/team_guard_test.go
@@ -4,8 +4,10 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
+ "encoding/json"
"errors"
"fmt"
+ "image/color"
"net/http"
"net/http/httptest"
"net/url"
@@ -23,7 +25,13 @@ import (
// lease inside the transaction, so the guard's after-check reads Unknown.
func lapsingGuard(t *testing.T, f *teamFixture) {
t.Helper()
- teamGuard = func(ctx context.Context, authorize func(roster.State) error, write func() error) error {
+ teamGuard = lapsing(f)
+ t.Cleanup(func() { teamGuard = teammode.Guard })
+}
+
+// lapsing is the guard lapsingGuard installs.
+func lapsing(f *teamFixture) func(context.Context, func(roster.State) error, func() error) error {
+ return func(ctx context.Context, authorize func(roster.State) error, write func() error) error {
return teammode.Guard(ctx, authorize, func() error {
err := write()
f.dir.SetDown(true)
@@ -31,7 +39,6 @@ func lapsingGuard(t *testing.T, f *teamFixture) {
return err
})
}
- t.Cleanup(func() { teamGuard = teammode.Guard })
}
// renewed brings the directory back and refreshes, so the next request
@@ -93,9 +100,10 @@ func (f *teamFixture) api(token, method, path, body string) *httptest.ResponseRe
// snapshot is what a refused write must leave exactly as it was.
type teamSnapshot struct {
- decks, updates, links, revoked, presentations, uploads int64
- title string
- seq int64
+ decks, updates, links, revoked, presentations int64
+ uploads, uploadsLanded, uploadsSpent, assets int64
+ title string
+ seq int64
}
func (f *teamFixture) snapshot(d Deck) teamSnapshot {
@@ -108,6 +116,9 @@ func (f *teamFixture) snapshot(d Deck) teamSnapshot {
g.Model(&ShareLink{}).Where("revoked_at IS NOT NULL").Count(&s.revoked)
g.Model(&Presentation{}).Count(&s.presentations)
g.Model(&AssetUpload{}).Count(&s.uploads)
+ g.Model(&AssetUpload{}).Where("object_key != ''").Count(&s.uploadsLanded)
+ g.Model(&AssetUpload{}).Where("consumed_at IS NOT NULL").Count(&s.uploadsSpent)
+ g.Model(&DeckAsset{}).Count(&s.assets)
var row Deck
if err := g.Take(&row, d.ID).Error; err != nil {
f.t.Fatalf("deck %d gone: %v", d.ID, err)
@@ -136,40 +147,74 @@ func TestTeamEveryWriteRouteRefusesALapseBeforeCommit(t *testing.T) {
}
lapsingGuard(t, f)
+ // The picture the upload routes carry, and its staging: signed (and
+ // for registration also landed) under the real guard, so only the
+ // route under test meets the lapse.
+ png := pngBytes(t, 4, 4, color.Black)
+ sum := sha256.Sum256(png)
+ signBody := fmt.Sprintf(`{"name":"a.png","size":%d,"type":"image/png","hash":%q}`, len(png), hex.EncodeToString(sum[:]))
+ var staged struct {
+ Ref string `json:"ref"`
+ URL string `json:"url"`
+ }
+ stage := func(land bool) {
+ teamGuard = teammode.Guard
+ defer func() { teamGuard = lapsing(f) }()
+ f.renewed()
+ got := f.do("POST", deckPath(plan)+"/uploads", signBody, "application/json", homeTestOrigin)
+ if got.Code != 200 || json.Unmarshal(got.Body.Bytes(), &staged) != nil {
+ t.Fatalf("staging an upload = %d %s", got.Code, got.Body.String())
+ }
+ if land {
+ if put := f.do("PUT", staged.URL, string(png), "image/png", homeTestOrigin); put.Code != http.StatusNoContent {
+ t.Fatalf("landing an upload = %d %s", put.Code, put.Body.String())
+ }
+ }
+ }
+
routes := []struct {
- name string
- do func() *httptest.ResponseRecorder
+ name string
+ setup func()
+ do func() *httptest.ResponseRecorder
}{
- {"create", func() *httptest.ResponseRecorder {
+ {"create", nil, func() *httptest.ResponseRecorder {
return f.post("/decks", url.Values{"title": {"New"}, "theme": {defaultTheme}})
}},
- {"live update", func() *httptest.ResponseRecorder {
+ {"live update", nil, func() *httptest.ResponseRecorder {
return f.do("POST", deckPath(plan)+"/updates", string(f.update(plan, "Typed")), "application/octet-stream", homeTestOrigin)
}},
- {"settings", func() *httptest.ResponseRecorder {
+ {"settings", nil, func() *httptest.ResponseRecorder {
return f.post(deckPath(plan)+"/settings", url.Values{"title": {"Renamed"}, "theme": {defaultTheme}, "rung": {rungPrivate}})
}},
- {"delete", func() *httptest.ResponseRecorder { return f.post(deckPath(plan)+"/delete", nil) }},
- {"share link", func() *httptest.ResponseRecorder { return f.post(deckPath(plan)+"/share", nil) }},
- {"share revoke", func() *httptest.ResponseRecorder {
+ {"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 {
return f.post(fmt.Sprintf("%s/share/%d/revoke", deckPath(plan), link.ID), nil)
}},
- {"present", func() *httptest.ResponseRecorder { return f.post(deckPath(plan)+"/present", nil) }},
- {"upload", func() *httptest.ResponseRecorder {
- sum := sha256.Sum256([]byte("png"))
- return f.do("POST", deckPath(plan)+"/uploads", fmt.Sprintf(`{"name":"a.png","size":3,"type":"image/png","hash":%q}`, hex.EncodeToString(sum[:])), "application/json", homeTestOrigin)
+ {"present", nil, func() *httptest.ResponseRecorder { return f.post(deckPath(plan)+"/present", nil) }},
+ {"upload", nil, func() *httptest.ResponseRecorder {
+ return f.do("POST", deckPath(plan)+"/uploads", signBody, "application/json", homeTestOrigin)
}},
- {"api create", func() *httptest.ResponseRecorder {
+ {"upload put", func() { stage(false) }, func() *httptest.ResponseRecorder {
+ return f.do("PUT", staged.URL, string(png), "image/png", homeTestOrigin)
+ }},
+ {"asset register", func() { stage(true) }, func() *httptest.ResponseRecorder {
+ return f.do("POST", deckPath(plan)+"/assets", fmt.Sprintf(`{"ref":%q,"name":"a.png","width":4,"height":4,"alt":"a dot"}`, staged.Ref), "application/json", homeTestOrigin)
+ }},
+ {"api create", nil, func() *httptest.ResponseRecorder {
return f.api(token, "POST", apiPrefix+"/decks", `{"title":"By agent"}`)
}},
- {"api ops", func() *httptest.ResponseRecorder {
+ {"api ops", nil, func() *httptest.ResponseRecorder {
return f.api(token, "POST", apiPrefix+"/decks/"+plan.Sqid+"/ops", `{"ops":[{"op":"set_meta","title":"Agent title"}]}`)
}},
- {"api present", func() *httptest.ResponseRecorder {
+ {"api present", nil, func() *httptest.ResponseRecorder {
return f.api(token, "POST", apiPrefix+"/decks/"+plan.Sqid+"/present", "")
}},
}
for _, route := range routes {
+ if route.setup != nil {
+ route.setup()
+ }
f.renewed()
before := f.snapshot(plan)
got := route.do()
diff --git a/internal/slides/team_owner.go b/internal/slides/team_owner.go
index 43f3563..0e599ba 100644
--- a/internal/slides/team_owner.go
+++ b/internal/slides/team_owner.go
@@ -1,25 +1,37 @@
package slides
-// Team mode's ownership, and the roster-owner rule — Paul's ruling for
-// Sheets (2026-10-28, oficina/sheets #52: team owners can share orphaned
-// sheets), applied to Slides' own ownership.
+// Team mode's ownership, and the roster-owner rule for orphaned decks —
+// RULED by Paul, 2026-10-30, on oficina/slides #33 ("share only, no
+// delete for now (may change his mind later)"; "team-visible decks
+// only"), after his Sheets ruling of 2026-10-28 on oficina/sheets #52.
//
-// A deck's owner is decks.owner_id: the one person who may change its
-// settings (title, theme, rung), delete it, and mint or revoke its share
-// links. In team mode that is the team rung's, as Docs' owner_id rule
-// is: the owner owns the deck only while the roster says Member. So
-// removing a deck's owner from the team leaves a team-rung deck the team
-// can still read, edit and present, and nobody can share, rename, move
-// back to private or delete. A roster owner therefore owns any deck they
-// can already read whose owner is definitely not on the team — the
-// roster says NotMember, which includes a local account with no Home
-// identity. An owner whose standing cannot be read right now is not
-// "gone". Nothing is written: the moment the departed owner is re-added,
-// the deck has a live owner again and this rule stops applying.
+// A deck's owner is decks.owner_id. In team mode that is the team rung's,
+// as Docs' owner_id rule is: the owner owns the deck only while the
+// roster says Member. Removing a deck's owner from the team therefore
+// leaves a team-rung deck the team can still read, edit and present, and
+// nobody can share. The rule: on an ORPHAN — a deck on the team rung
+// whose owner the roster definitely says is gone (NotMember, which
+// includes a local account with no Home identity, or an owner row that
+// no longer exists) — a roster owner may
//
-// What it does not reach: a removed member's PRIVATE decks. No roster
-// owner can read those (visibleDecks), and this rule never widens what
-// anybody can read, only who may change what they already can.
+// - share it: the share page and its links (mayShareDeck);
+// - change its title and theme (mayRetitleDeck);
+//
+// and may NOT
+//
+// - delete it (mayDeleteDeck), nor
+// - change its rung (mayChangeRung): making it private hides it from
+// everybody, the roster owner included, which Paul treats as a
+// soft-delete.
+//
+// Only the team rung: a departed member's private deck is no orphan,
+// even to a roster owner who holds a grant to read it. An owner whose
+// standing cannot be read right now is not "gone". Nothing is written:
+// the moment the departed owner is re-added, the deck has a live owner
+// again and the rule stops applying.
+//
+// Each power is its own predicate, so widening one later (Paul may
+// rule delete back in) is one line in one place.
import (
"context"
@@ -30,25 +42,40 @@ import (
"amadan.net/oficina/home/roster"
)
-// ownsDeck reports whether u owns d, which they have already been shown
-// (deckFor): the owner while Member, or a roster owner on an orphaned
-// deck. Outside team mode it is exactly d.OwnerID == u.ID.
-func (a *app) ownsDeck(ctx context.Context, u User, d Deck) bool {
- if a.team == nil {
- return d.OwnerID == u.ID
- }
- if u.team.state() != roster.Member {
- return false
- }
- return d.OwnerID == u.ID || a.orphanedForRosterOwner(ctx, u, d)
+// ownsDeck reports whether u is d's owner: d.OwnerID, while Member in
+// team mode. Outside team mode it is exactly d.OwnerID == u.ID.
+func (a *app) ownsDeck(u User, d Deck) bool {
+ return d.OwnerID == u.ID && a.member(u)
+}
+
+// mayShareDeck: the share page, minting and revoking share links. The
+// owner, or a roster owner on an orphan.
+func (a *app) mayShareDeck(ctx context.Context, u User, d Deck) bool {
+ return a.ownsDeck(u, d) || a.orphanedForRosterOwner(ctx, u, d)
+}
+
+// mayRetitleDeck: the settings page and its title and theme. The owner,
+// or a roster owner on an orphan.
+func (a *app) mayRetitleDeck(ctx context.Context, u User, d Deck) bool {
+ return a.ownsDeck(u, d) || a.orphanedForRosterOwner(ctx, u, d)
+}
+
+// mayChangeRung: who can open the deck. The owner alone.
+func (a *app) mayChangeRung(_ context.Context, u User, d Deck) bool {
+ return a.ownsDeck(u, d)
+}
+
+// mayDeleteDeck: the delete page and the delete. The owner alone.
+func (a *app) mayDeleteDeck(_ context.Context, u User, d Deck) bool {
+ return a.ownsDeck(u, d)
}
-// orphanedForRosterOwner reports whether u is a roster owner and d's
-// owner is definitely off the team. It asks the roster about the owner,
-// never under the SQLite writer: ownedDeckFor is not called inside a
-// transaction.
+// orphanedForRosterOwner reports whether u is a roster owner, now, and d
+// is an orphan: on the team rung, its owner definitely off the team. It
+// asks the roster about the owner, never under the SQLite writer: no
+// owner check runs inside a transaction. Always false outside team mode.
func (a *app) orphanedForRosterOwner(ctx context.Context, u User, d Deck) bool {
- if a.team == nil || !u.team.rosterOwner() || d.OwnerID == u.ID {
+ if a.team == nil || d.Rung != rungTeam || !u.team.rosterOwner() || d.OwnerID == u.ID {
return false
}
var owner User
diff --git a/internal/slides/team_review_test.go b/internal/slides/team_review_test.go
index e34dbc0..f630ec9 100644
--- a/internal/slides/team_review_test.go
+++ b/internal/slides/team_review_test.go
@@ -3,6 +3,7 @@ package slides
import (
"context"
"encoding/json"
+ "fmt"
"net/http"
"net/http/httptest"
"net/url"
@@ -64,11 +65,14 @@ func TestTeamProbeStatesAndNoAccountData(t *testing.T) {
}
}
-// Paul's ruling for Sheets, applied to Slides' owner_id: a roster owner
-// owns a deck they can already read whose owner is off the team. A
-// member does not; a live owner keeps it; and a removed member's private
-// deck stays out of everybody's reach.
-func TestTeamRosterOwnerOwnsOrphanedDecks(t *testing.T) {
+// Paul's ruling on #33 (2026-10-30): on an orphan — a team-rung deck
+// whose owner the roster says is gone — a roster owner may share it
+// (the share page, minting and revoking links) and change its title and
+// theme; may not delete it, nor narrow its rung (private hides it from
+// everybody: a soft-delete). A member may do none of it, a live owner's
+// deck is not an orphan, nor is a departed member's private deck, even
+// one the roster owner holds a read grant on.
+func TestTeamRosterOwnerSharesAndRetitlesOrphansOnly(t *testing.T) {
f := newTeamFixture(t)
departed := f.member(teamSubject('d'), "member")
orphan := f.deck(departed, "Departed's team deck", rungTeam)
@@ -76,53 +80,92 @@ func TestTeamRosterOwnerOwnsOrphanedDecks(t *testing.T) {
live := f.member(teamSubject('l'), "member")
kept := f.deck(live, "Live owner's deck", rungTeam)
f.member(teamSubject('m'), "member")
- f.member(teamSubject('o'), "owner")
-
+ rosterOwner := f.member(teamSubject('o'), "owner")
+ f.grant(private, rosterOwner, departed)
f.dir.Set(teamSubject('d'), "")
f.refreshed()
- // The roster owner: settings, share and delete on the orphan.
- if got := f.get(deckPath(orphan) + "/settings"); got.Code != 200 {
- t.Fatalf("roster owner's settings on an orphan = %d, want 200", got.Code)
- }
- if got := f.get(deckPath(orphan)); !strings.Contains(got.Body.String(), deckPath(orphan)+"/settings") {
- t.Fatal("the roster owner's viewer of an orphan offers no settings")
- }
+ // Share: the page, a link minted and revoked.
if got := f.get(deckPath(orphan) + "/share"); got.Code != 200 {
t.Fatalf("roster owner's share page on an orphan = %d, want 200", got.Code)
}
- if got := f.get(deckPath(kept) + "/settings"); got.Code != 404 {
- t.Fatalf("roster owner's settings on a live owner's deck = %d, want 404", got.Code)
+ if got := f.post(deckPath(orphan)+"/share", nil); got.Code != http.StatusSeeOther {
+ t.Fatalf("roster owner minting a link on an orphan = %d", got.Code)
}
- if got := f.get(deckPath(private)); got.Code != 404 {
- t.Fatalf("roster owner on a removed member's private deck = %d, want 404", got.Code)
+ var link ShareLink
+ if err := f.d.G.Where("deck_id = ?", orphan.ID).Take(&link).Error; err != nil {
+ t.Fatal("no link minted")
}
- if got := f.post(deckPath(orphan)+"/settings", url.Values{"title": {"Rescued"}, "theme": {defaultTheme}, "rung": {rungTeam}}); got.Code != http.StatusSeeOther {
- t.Fatalf("roster owner saving an orphan's settings = %d", got.Code)
+ if got := f.post(fmt.Sprintf("%s/share/%d/revoke", deckPath(orphan), link.ID), nil); got.Code != http.StatusSeeOther {
+ t.Fatalf("roster owner revoking a link on an orphan = %d", got.Code)
}
- if got := f.post(deckPath(orphan)+"/delete", nil); got.Code != http.StatusSeeOther {
- t.Fatalf("roster owner deleting an orphan = %d", got.Code)
+ // Title and theme: the settings page, with no rung and no delete.
+ page := f.get(deckPath(orphan) + "/settings")
+ if page.Code != 200 || strings.Contains(page.Body.String(), `name="rung"`) || strings.Contains(page.Body.String(), deckPath(orphan)+"/delete") {
+ t.Fatalf("roster owner's settings on an orphan = %d (rung or delete offered?)", page.Code)
+ }
+ if got := f.get(deckPath(orphan)); !strings.Contains(got.Body.String(), deckPath(orphan)+"/settings") || !strings.Contains(got.Body.String(), deckPath(orphan)+"/share") {
+ t.Fatal("the roster owner's viewer of an orphan offers no settings or share")
+ }
+ if got := f.post(deckPath(orphan)+"/settings", url.Values{"title": {"Rescued"}, "theme": {"ink"}}); got.Code != http.StatusSeeOther {
+ t.Fatalf("roster owner retitling an orphan = %d %s", got.Code, got.Body.String())
+ }
+ var row Deck
+ f.d.G.Take(&row, orphan.ID)
+ if row.Title != "Rescued" || row.Theme != "ink" || row.Rung != rungTeam {
+ t.Fatalf("orphan after retitling = %q %q %q", row.Title, row.Theme, row.Rung)
+ }
+ // Not the rung, not delete.
+ if got := f.post(deckPath(orphan)+"/settings", url.Values{"title": {"Hidden"}, "theme": {"ink"}, "rung": {rungPrivate}}); got.Code != http.StatusForbidden {
+ t.Fatalf("roster owner making an orphan private = %d, want 403", got.Code)
+ }
+ if got := f.get(deckPath(orphan) + "/delete"); got.Code != 404 {
+ t.Fatalf("roster owner's delete page on an orphan = %d, want 404", got.Code)
+ }
+ if got := f.post(deckPath(orphan)+"/delete", nil); got.Code != 404 {
+ t.Fatalf("roster owner deleting an orphan = %d, want 404", got.Code)
}
- var n int64
- f.d.G.Model(&Deck{}).Where("id = ?", orphan.ID).Count(&n)
- if n != 0 {
- t.Fatal("the orphan was not deleted")
+ f.d.G.Take(&row, orphan.ID)
+ if row.Rung != rungTeam || row.Title != "Rescued" {
+ t.Fatalf("a refused narrowing changed the orphan: %q %q", row.Title, row.Rung)
+ }
+ // A departed member's private deck, readable by grant: no owner powers.
+ if got := f.get(deckPath(private)); got.Code != 200 || strings.Contains(got.Body.String(), deckPath(private)+"/settings") {
+ t.Fatalf("roster owner's granted private orphan = %d (owner mode?)", got.Code)
+ }
+ for _, p := range []string{"/settings", "/share", "/delete"} {
+ if got := f.get(deckPath(private) + p); got.Code != 404 {
+ t.Fatalf("roster owner's %s on a private orphan = %d, want 404", p, got.Code)
+ }
+ }
+ if got := f.get(deckPath(kept) + "/settings"); got.Code != 404 {
+ t.Fatalf("roster owner's settings on a live owner's deck = %d, want 404", got.Code)
}
// A member is no owner of anything but their own.
- orphan2 := f.deck(departed, "Another orphan", rungTeam)
f.freshHomeSignIn(teamSubject('m'))
- if got := f.get(deckPath(orphan2) + "/settings"); got.Code != 404 {
- t.Fatalf("a member's settings on an orphan = %d, want 404", got.Code)
+ for _, p := range []string{"/settings", "/share"} {
+ if got := f.get(deckPath(orphan) + p); got.Code != 404 {
+ t.Fatalf("a member's %s on an orphan = %d, want 404", p, got.Code)
+ }
}
// The departed owner re-added: the deck has a live owner again.
f.dir.Set(teamSubject('d'), "member")
f.refreshed()
f.freshHomeSignIn(teamSubject('o'))
- if got := f.get(deckPath(orphan2) + "/settings"); got.Code != 404 {
+ if got := f.get(deckPath(orphan) + "/share"); got.Code != 404 {
t.Fatalf("roster owner after the owner's return = %d, want 404", got.Code)
}
+
+ // 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 {
+ t.Fatalf("the owner's own rung change = %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)
+ }
}
// The dashboard feed follows the roster: a member's team decks, a removed
diff --git a/internal/slides/team_stream_test.go b/internal/slides/team_stream_test.go
index 3f59889..b8bb8eb 100644
--- a/internal/slides/team_stream_test.go
+++ b/internal/slides/team_stream_test.go
@@ -3,6 +3,10 @@ package slides
import (
"bufio"
"context"
+ "strconv"
+
+ "amadan.net/oficina/home/roster"
+ "amadan.net/oficina/slides/internal/slides/present"
"errors"
"io"
"net/http"
@@ -76,23 +80,6 @@ func endsWithin(br *bufio.Reader, d time.Duration) (string, bool) {
}
}
-// A silent deck stream must not outlive the lease its standing rests on:
-// opened a second before the lease ends with the directory down, nothing
-// written to the deck, and it still ends.
-func TestTeamDeckStreamClosesAtLeaseExpiry(t *testing.T) {
- f := newTeamFixture(t)
- colleague := f.member(teamSubject('b'), "member")
- plan := f.deck(colleague, "Team plan", rungTeam)
- f.member(teamSubject('a'), "member")
- f.dir.SetDown(true)
- f.clock.Step(59 * time.Second)
- br := f.openStream(t, deckPath(plan)+"/stream", true)
- f.clock.Step(2 * time.Second)
- if _, ended := endsWithin(br, 5*time.Second); !ended {
- t.Fatal("a deck stream outlived the lease it stood on")
- }
-}
-
// Renewal: at the lease the stream asks again, and while the roster still
// says Member it carries on, and still delivers.
func TestTeamDeckStreamRenewsWhileStillAMember(t *testing.T) {
@@ -211,8 +198,84 @@ func TestTeamPresentationStandsOnThePresenter(t *testing.T) {
}
}
-// A silent projector stream ends at the presenter's lease.
-func TestTeamPresentationStreamClosesAtThePresentersLease(t *testing.T) {
+// lines feeds a stream's lines to a channel, closed when the body ends.
+func lines(br *bufio.Reader) <-chan string {
+ ch := make(chan string, 64)
+ go func() {
+ defer close(ch)
+ for {
+ l, err := br.ReadString('\n')
+ if err != nil {
+ return
+ }
+ ch <- l
+ }
+ }()
+ return ch
+}
+
+// within reads ch for d: the first line containing want (found), or
+// whether the stream ended, with every line seen.
+func within(ch <-chan string, want string, d time.Duration) (seen string, found, ended bool) {
+ deadline := time.After(d)
+ for {
+ select {
+ case l, ok := <-ch:
+ if !ok {
+ return seen, false, true
+ }
+ seen += l
+ if want != "" && strings.Contains(l, want) {
+ return seen, true, false
+ }
+ case <-deadline:
+ return seen, false, false
+ }
+ }
+}
+
+// shortHold makes a held stream re-ask every 100 ms instead of the
+// roster's 5 s.
+func shortHold(t *testing.T) {
+ streamHoldRetry = 100 * time.Millisecond
+ t.Cleanup(func() { streamHoldRetry = roster.RetryAfter })
+}
+
+// A deck stream whose Member lease runs out while the roster cannot be
+// read is held, not ended (Fable #33, note 1): it stays open and delivers
+// nothing about the deck, and the moment standing returns it is caught
+// up with the deck's current seq.
+func TestTeamDeckStreamHoldsWhileStandingIsUnknown(t *testing.T) {
+ shortHold(t)
+ f := newTeamFixture(t)
+ colleague := f.member(teamSubject('b'), "member")
+ plan := f.deck(colleague, "Team plan", rungTeam)
+ f.member(teamSubject('a'), "member")
+ f.dir.SetDown(true)
+ f.clock.Step(59 * time.Second)
+ feed := lines(f.openStream(t, deckPath(plan)+"/stream", true))
+ f.clock.Step(2 * time.Second)
+ time.Sleep(1500 * time.Millisecond) // past the stream's lease timer: held
+ if err := f.a.editDeck(context.Background(), &plan, actorFor(colleague), mustOps(t, "While held"), nil, nil); err != nil {
+ t.Fatal(err)
+ }
+ if seen, found, ended := within(feed, "event:", time.Second); found || ended {
+ t.Fatalf("a held deck stream delivered or ended: %q (ended %v)", seen, ended)
+ }
+ f.dir.SetDown(false)
+ f.refreshed()
+ seen, found, _ := within(feed, "data: "+strconv.FormatInt(plan.Seq, 10), 3*time.Second)
+ if !found || !strings.Contains(seen, "event: update") {
+ t.Fatalf("the held stream was not caught up to seq %d: %q", plan.Seq, seen)
+ }
+}
+
+// A projector stream whose presenter's lease runs out while the roster
+// cannot be read is held, delivering nothing; when it can be read again
+// the projector gets the talk's current state, never what was published
+// while held.
+func TestTeamPresentationStreamHoldsWhileThePresenterIsUnknown(t *testing.T) {
+ shortHold(t)
f := newTeamFixture(t)
colleague := f.member(teamSubject('b'), "member")
plan := f.deck(colleague, "Team plan", rungTeam)
@@ -220,9 +283,69 @@ func TestTeamPresentationStreamClosesAtThePresentersLease(t *testing.T) {
session := f.startTalk(t, plan)
f.dir.SetDown(true)
f.clock.Step(59 * time.Second)
- br := f.openStream(t, "/p/"+session+"/stream", false)
+ feed := lines(f.openStream(t, "/p/"+session+"/stream", false))
f.clock.Step(2 * time.Second)
- if _, ended := endsWithin(br, 5*time.Second); !ended {
- t.Fatal("a projector stream outlived its presenter's lease")
+ time.Sleep(1500 * time.Millisecond)
+ f.a.hub.Publish(session, present.Event{Slide: 9})
+ if seen, found, ended := within(feed, "event:", time.Second); found || ended {
+ t.Fatalf("a held projector stream delivered or ended: %q (ended %v)", seen, ended)
+ }
+ f.dir.SetDown(false)
+ f.refreshed()
+ seen, found, _ := within(feed, "event: slide", 3*time.Second)
+ if !found {
+ t.Fatalf("the held projector was not caught up: %q", seen)
+ }
+ if rest, _, _ := within(feed, "", 200*time.Millisecond); strings.Contains(seen+rest, `"slide":9`) {
+ t.Fatal("a held projector was sent what was published while it was held")
+ }
+}
+
+// A projector that connects while its presenter's standing is unknown is
+// not refused (an EventSource answered 503 fails for good): it is held,
+// and served once the roster can be read. The page itself is still the
+// retryable 503; a removed presenter's stream is the 410.
+func TestTeamProjectorConnectsWhileThePresenterIsUnknown(t *testing.T) {
+ shortHold(t)
+ f := newTeamFixture(t)
+ colleague := f.member(teamSubject('b'), "member")
+ plan := f.deck(colleague, "Team plan", rungTeam)
+ f.member(teamSubject('a'), "member")
+ session := f.startTalk(t, plan)
+ f.expired()
+ srv := httptest.NewServer(f.mux)
+ t.Cleanup(srv.Close)
+ ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
+ t.Cleanup(cancel)
+ req, _ := http.NewRequestWithContext(ctx, http.MethodGet, srv.URL+"/p/"+session+"/stream", nil)
+ req.Host = strings.TrimPrefix(homeTestOrigin, "https://")
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { resp.Body.Close() })
+ if resp.StatusCode != http.StatusOK {
+ t.Fatalf("projector stream under Unknown = %d, want a held 200", resp.StatusCode)
+ }
+ feed := lines(bufio.NewReader(resp.Body))
+ if seen, found, ended := within(feed, "event:", 500*time.Millisecond); found || ended {
+ t.Fatalf("a held projector delivered or ended: %q", seen)
+ }
+ f.dir.SetDown(false)
+ f.refreshed()
+ if seen, found, _ := within(feed, "event: slide", 3*time.Second); !found {
+ t.Fatalf("the projector was not served once the roster returned: %q", seen)
+ }
+ f.dir.Set(teamSubject('a'), "")
+ f.refreshed()
+ r2, _ := http.NewRequestWithContext(ctx, http.MethodGet, srv.URL+"/p/"+session+"/stream", nil)
+ r2.Host = req.Host
+ gone, err := http.DefaultClient.Do(r2)
+ if err != nil {
+ t.Fatal(err)
+ }
+ gone.Body.Close()
+ if gone.StatusCode != http.StatusGone {
+ t.Fatalf("projector stream for a removed presenter = %d, want 410", gone.StatusCode)
}
}
diff --git a/internal/slides/team_survivors_test.go b/internal/slides/team_survivors_test.go
index 4a8804a..d4fd998 100644
--- a/internal/slides/team_survivors_test.go
+++ b/internal/slides/team_survivors_test.go
@@ -1,7 +1,11 @@
package slides
import (
+ "bytes"
"context"
+ "log/slog"
+
+ "amadan.net/oficina/home/connect"
"database/sql"
"net/http"
"net/http/httptest"
@@ -97,8 +101,8 @@ func TestTeamTeamRungReachNeverStandsWithoutALease(t *testing.T) {
f.clock.SetTick(time.Millisecond)
var stands bool
if what == "deck stream" {
- ok, renew := f.a.teamStreamAccess(r, plan.ID)
- stands = ok && renew == 0
+ decision, renew := f.a.teamStreamAccess(r, plan.ID)
+ stands = decision == streamDelivers && renew == 0
} else {
reach, renew := f.a.presenterStanding(context.Background(), Presentation{Actor: actorFor(u), DeckID: plan.ID})
stands = reach == presenterReaches && renew == 0
@@ -212,3 +216,33 @@ func (f *teamFixture) linkHome(t *testing.T, subject string) {
t.Fatalf("link confirm = %d %s", c.Code, c.Body.String())
}
}
+
+// A first local sign-in on a team instance seeds no sample deck — the
+// account is a guest until it links — and so logs no failed seed
+// (Fable #33, note 3).
+func TestTeamFirstLocalSignInSeedsNothingAndLogsNothing(t *testing.T) {
+ var logged bytes.Buffer
+ key := teamKey(t)
+ cfg, _, _ := teamConfigFor(t, teamTestBindings(), key, "new@example.com")
+ cfg.Logger = slog.New(slog.NewTextHandler(&logged, nil))
+ d := testDB(t)
+ mux, a, err := New(d, cfg)
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { a.Close() })
+ f := &teamFixture{t: t, mux: mux, a: a, d: d, key: key, jar: map[string]*http.Cookie{}}
+ f.localSession("new@example.com")
+ if got := f.get(connect.LocalCompletePath); got.Code >= 500 {
+ t.Fatalf("local complete = %d", got.Code)
+ }
+ var users, decks int64
+ d.G.Model(&User{}).Count(&users)
+ d.G.Model(&Deck{}).Count(&decks)
+ if users != 1 || decks != 0 {
+ t.Fatalf("first local sign-in made users=%d decks=%d, want 1 and 0", users, decks)
+ }
+ if strings.Contains(logged.String(), "level=ERROR") {
+ t.Fatalf("a first local sign-in logged an error:\n%s", logged.String())
+ }
+}
diff --git a/internal/slides/templates/deck_settings.html b/internal/slides/templates/deck_settings.html
index 71225c8..fad4935 100644
--- a/internal/slides/templates/deck_settings.html
+++ b/internal/slides/templates/deck_settings.html
@@ -22,16 +22,16 @@
"ID" "theme" "Name" "theme" "Label" .ThemeLabel
"Options" .Themes "Required" true
"Error" (index .Errors "Theme")}}
- {{template "choice-field" dict
+ {{if .Rungs}}{{template "choice-field" dict
"Legend" .RungLegend "Name" "rung" "Options" .Rungs}}
{{template "form-error" (index .Errors "Rung")}}
- {{template "form-foot" dict
+ {{end}}{{template "form-foot" dict
"Submit" .Submit "CancelHref" .CancelHref "CancelLabel" .CancelLabel}}
</form>
</div>
-<div rst-box-head><h2>{{.DeleteLabel}}</h2></div>
+{{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>
</div>
-{{end}}
+{{end}}{{end}}
diff --git a/internal/slides/viewer.go b/internal/slides/viewer.go
index 5a9a074..afaaead 100644
--- a/internal/slides/viewer.go
+++ b/internal/slides/viewer.go
@@ -141,7 +141,7 @@ func (a *app) showDeck(w http.ResponseWriter, r *http.Request) {
return
}
mode := modeMember
- if a.ownsDeck(r.Context(), u, d) {
+ if a.mayShareDeck(r.Context(), u, d) {
mode = modeOwner
}
a.renderViewer(w, r, d, mode, "/d/"+d.Sqid, a.shellFor(r, u, titled(d.Title)))