A reader gets no formatting chrome
No inspector or strip, no Format and no undo/redo pair, in the bar or the strip, for a reader (!CanWrite): they cannot format, and a dead panel pushed their sheet left; with no inspector it is plainly centred. They keep the stacked bar's menus and the document. The slab under the header loses its rule when it holds only the font notes. Reverses this branch's deviation 5 (review on #106). TestAReaderGetsNoFormattingChrome, seen to fail before the change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+61
−13
internal/docs/handlers.go+17 −10internal/docs/i2_test.go+34 −0internal/docs/views/show.html+10 −3
CI passed — run details
diff --git a/internal/docs/handlers.go b/internal/docs/handlers.go| index ee2e830..a44e270 100644 |
| --- a/internal/docs/handlers.go |
| +++ b/internal/docs/handlers.go |
| @@ -717,24 +717,31 @@ func (h *handlers) show(w http.ResponseWriter, r *http.Request) { |
| // cookie's, rendered here and onto the inspector, so the first paint |
| // is the final one; estilo renders it disabled, and brand/ |
| // inspector.js enables it. |
| + // |
| + // A reader gets the menus and none of the formatting chrome: no |
| + // undo/redo, no Format and (show.html) no inspector or strip. They |
| + // cannot format, and a dead panel pushed their sheet left (review on |
| + // #106). |
| var err2 error |
| - if chromeFor.menubar, err2 = h.render.fragment("show", "docs-menubar", data.Menu); err2 == nil { |
| - chromeFor.lead, err2 = h.render.fragment("show", "docs-history", data.Toolbar.history(true)) |
| - } |
| var formatIcon template.HTML |
| - if err2 == nil { |
| - formatIcon, err2 = h.render.fragment("show", "docs-icon-format", nil) |
| + chromeFor.menubar, err2 = h.render.fragment("show", "docs-menubar", data.Menu) |
| + if err2 == nil && data.CanWrite { |
| + if chromeFor.lead, err2 = h.render.fragment("show", "docs-history", data.Toolbar.history(true)); err2 == nil { |
| + formatIcon, err2 = h.render.fragment("show", "docs-icon-format", nil) |
| + } |
| } |
| if err2 != nil { |
| h.logger.Error("docs: render the editor's bar", "err", err2) |
| h.fail(w, r, h.internalFailureStatus(), failStatus) |
| return |
| } |
| - chromeFor.actions = []chrome.Action{{ |
| - Item: estilomenu.Item{Controls: inspectorID, Expanded: data.Inspector == InspectorOpen, Label: rastrillo.T(r, "docs.editor.inspector.toggle")}, |
| - WideOnly: true, |
| - Icon: formatIcon, |
| - }} |
| + if data.CanWrite { |
| + chromeFor.actions = []chrome.Action{{ |
| + Item: estilomenu.Item{Controls: inspectorID, Expanded: data.Inspector == InspectorOpen, Label: rastrillo.T(r, "docs.editor.inspector.toggle")}, |
| + WideOnly: true, |
| + Icon: formatIcon, |
| + }} |
| + } |
| // An imported document keeps its report one click away, for anybody |
| // who can read the document; it shows itself once on arrival. |
| if h.store.hasImportReport(r.Context(), doc.ID) { |
diff --git a/internal/docs/i2_test.go b/internal/docs/i2_test.go| index 86db7bd..fbc08d1 100644 |
| --- a/internal/docs/i2_test.go |
| +++ b/internal/docs/i2_test.go |
| @@ -137,3 +137,37 @@ func TestTheInspectorSectionsAreNamedGroups(t *testing.T) { |
| t.Errorf("%d toolbars, want one at every width", n) |
| } |
| } |
| + |
| +// A reader cannot format (review on #106): no inspector, no strip, no |
| +// Format toggle and no undo/redo, in the bar or the strip. A dead panel |
| +// pushed their sheet left; with no inspector the sheet is plainly |
| +// centred. The writer and the owner keep all of it. |
| +func TestAReaderGetsNoFormattingChrome(t *testing.T) { |
| + app, _ := docs.NewForTest(t) |
| + alice := signInCookies(t, app, "alice@example.com") |
| + sqid := createDoc(t, app, alice, "Minutes") |
| + bob := signInCookies(t, app, "bob@example.com") |
| + post(t, app, alice, "/d/"+sqid+"/share", "address=bob@example.com&role=reader") |
| + carol := signInCookies(t, app, "carol@example.com") |
| + post(t, app, alice, "/d/"+sqid+"/share", "address=carol@example.com&role=writer") |
| + |
| + formatting := []string{"<aside docs-inspector", "<div docs-toolbar ", "<div docs-bar>", "data-estilo-toggle", "<div docs-history", "<div estilo-bar-lead>", "/static/brand/inspector"} |
| + reader := get(t, app, bob, "/d/"+sqid).Body.String() |
| + for _, banned := range formatting { |
| + if strings.Contains(reader, banned) { |
| + t.Errorf("a reader's page has %q", banned) |
| + } |
| + } |
| + // Still the stacked bar with its menus, and the document. |
| + if !strings.Contains(reader, `<header estilo-bar="sticky stacked">`) || !strings.Contains(reader, "<nav estilo-menubar") || !strings.Contains(reader, "Minutes") { |
| + t.Error("a reader lost the bar's menus or the document") |
| + } |
| + for who, cookies := range map[string][]*http.Cookie{"writer": carol, "owner": alice} { |
| + body := get(t, app, cookies, "/d/"+sqid).Body.String() |
| + for _, needed := range formatting { |
| + if !strings.Contains(body, needed) { |
| + t.Errorf("the %s's page lacks %q", who, needed) |
| + } |
| + } |
| + } |
| +} |
diff --git a/internal/docs/views/show.html b/internal/docs/views/show.html| index 3641e78..c89419d 100644 |
| --- a/internal/docs/views/show.html |
| +++ b/internal/docs/views/show.html |
| @@ -797,6 +797,11 @@ |
| background: var(--rst-surface); |
| border-block-end: 1px solid var(--rst-line); |
| } |
| + /* A reader's slab holds only the font notes: no rule of its own under |
| + the header's. */ |
| + [docs-chrome]:not(:has([docs-bar])) { |
| + border-block-end: 0; |
| + } |
| [docs-bar] { |
| display: flex; |
| flex-wrap: wrap; |
| @@ -1679,7 +1684,9 @@ |
| Both rules were correct. Neither had an element. */}} |
| <div docs-chrome> |
| -<div docs-bar> |
| +{{/* A reader cannot format: no strip, no inspector, no undo/redo (review |
| + on #106). The editor bundle, which drives them, is the writer's too. */}} |
| +{{if .CanWrite}}<div docs-bar> |
| {{/* The formatting bar (fixtures/toolbar.mjs). Rendered server-side, |
| with every label resolved from the catalog (render.go's |
| docs.editor.toolbar.*) — the bundle carries no copy of its own, |
| @@ -1814,7 +1821,7 @@ |
| </div> |
| </div> |
| </aside> |
| -</div> |
| +</div>{{end}} |
| {{/* What the page says about its fonts, just under the bars: a font |
| is loading, a change was refused while it did, a font could not be |
| loaded, or substitutes are shown (fixtures/font-status.mjs). The |
| @@ -1924,6 +1931,6 @@ |
| {{/* The Format toggle (brand/inspector.js): enables the bar's button, |
| shows and hides the inspector and remembers it in the cookie. Without |
| it the button stays disabled and the inspector open. */}} |
| -<script defer src="{{asset "static/brand/inspector.js"}}"></script> |
| +{{if .CanWrite}}<script defer src="{{asset "static/brand/inspector.js"}}"></script>{{end}} |
| {{template "docs-jumpto" .}} |
| {{end}} |