| 1 | package mapa |
| 2 | |
| 3 | import ( |
| 4 | _ "embed" |
| 5 | "encoding/json" |
| 6 | "net/http" |
| 7 | |
| 8 | "amadan.net/oficina/estilo.git/credits" |
| 9 | ) |
| 10 | |
| 11 | // Help → Colophon: every open-source project Mapa ships, each with its |
| 12 | // own licence text, unaltered (Paul, 2026-10-26: every Oficina app has |
| 13 | // one, under Help). The list is not written here: scripts/credits.py |
| 14 | // reads it from the release build and the editor bundle into |
| 15 | // credits/notices.json, and make credits-check fails when it drifts. |
| 16 | // estilo's credits package draws it. |
| 17 | |
| 18 | // colophonPath is the suite's address for it, as in Slides, Calendar, |
| 19 | // Calls, Home and Memoria. |
| 20 | const colophonPath = "/help/open-source" |
| 21 | |
| 22 | // colophonTitle is the page's title and its Help label, Docs' word. |
| 23 | const colophonTitle = "Colophon" |
| 24 | |
| 25 | //go:embed credits/notices.json |
| 26 | var creditNotices []byte |
| 27 | |
| 28 | // creditInventory is notices.json: estilo's catalog.Inventory. |
| 29 | type creditInventory struct { |
| 30 | Components []credits.Component `json:"components"` |
| 31 | MissingNotices []string `json:"missing_notices"` |
| 32 | } |
| 33 | |
| 34 | // colophonCredits is decoded once, at start: a release whose inventory |
| 35 | // does not decode must not start. |
| 36 | var colophonCredits = func() creditInventory { |
| 37 | var inventory creditInventory |
| 38 | if err := json.Unmarshal(creditNotices, &inventory); err != nil { |
| 39 | panic("mapa: credits/notices.json: " + err.Error()) |
| 40 | } |
| 41 | return inventory |
| 42 | }() |
| 43 | |
| 44 | // colophonData is the page estilo's "estilo/credits" draws. |
| 45 | func colophonData() credits.PageData { |
| 46 | return credits.PageData{Title: colophonTitle, |
| 47 | MissingNoticeLabel: "No notice file is included in this release.", |
| 48 | Components: colophonCredits.Components} |
| 49 | } |
| 50 | |
| 51 | // colophonPublic is templates/colophon_public.html's data: the page |
| 52 | // signed out, in the door's plain column. |
| 53 | type colophonPublic struct { |
| 54 | Theme string |
| 55 | Signin string |
| 56 | Credits credits.PageData |
| 57 | } |
| 58 | |
| 59 | // colophon serves GET /help/open-source signed in and signed out: the |
| 60 | // sign-in door's footer links it, as every Oficina app's door does. |
| 61 | // Signed in, it goes through the same guard as every other screen and is |
| 62 | // drawn in Mapa's shell; otherwise in the door's column. It reads nothing |
| 63 | // but the embedded inventory, so it writes nothing either way. |
| 64 | // |
| 65 | // Referrer-Policy is strict-origin, as in Slides: no path or query goes |
| 66 | // to anyone, and each credit link carries its own no-referrer. |
| 67 | func (app *app) colophon(writer http.ResponseWriter, request *http.Request) { |
| 68 | writer.Header().Set("Referrer-Policy", "strict-origin") |
| 69 | if app.signedIn(request) { |
| 70 | app.requireSession(http.HandlerFunc(app.colophonInShell)). |
| 71 | ServeHTTP(writer, request) |
| 72 | return |
| 73 | } |
| 74 | writer.Header().Set("Cache-Control", "no-store") |
| 75 | render(writer, request, "colophon_public", colophonPublic{ |
| 76 | Theme: themeAttr(request), Signin: signinPath, |
| 77 | Credits: colophonData()}) |
| 78 | } |
| 79 | |
| 80 | func (app *app) colophonInShell(writer http.ResponseWriter, |
| 81 | request *http.Request) { |
| 82 | viewer, err := app.viewer(request) |
| 83 | if err != nil { |
| 84 | app.fail(writer, request, err) |
| 85 | return |
| 86 | } |
| 87 | app.show(writer, request, http.StatusOK, "colophon", view{ |
| 88 | Title: colophonTitle, Nav: nav(""), Viewer: viewer, |
| 89 | Data: colophonData()}) |
| 90 | } |
| 91 | |
| 92 | // signedIn reports whether the request carries a session the guard |
| 93 | // would let through: a live session for an address still admitted. |
| 94 | func (app *app) signedIn(request *http.Request) bool { |
| 95 | if app.allowUnauthenticated { |
| 96 | return true |
| 97 | } |
| 98 | if app.auth == nil { |
| 99 | return false |
| 100 | } |
| 101 | identity, ok := app.auth.SessionFrom(request) |
| 102 | return ok && app.Admit(normaliseAddress(identity.Address)) |
| 103 | } |
| 104 | |