| 1 | package slides |
| 2 | |
| 3 | // Team mode's answers: the retryable 503 for Unknown standing, the |
| 4 | // partial list, the member-only gate and the probe. Each is a no-op |
| 5 | // outside team mode. |
| 6 | |
| 7 | import ( |
| 8 | "net/http" |
| 9 | "strconv" |
| 10 | "time" |
| 11 | |
| 12 | "amadan.net/oficina/home/roster" |
| 13 | "amadan.net/oficina/home/teammode" |
| 14 | ) |
| 15 | |
| 16 | // The drive API's two team-mode error ids, beside api.go's own. |
| 17 | const ( |
| 18 | errForbidden = "forbidden" |
| 19 | errUnavailable = "unavailable" |
| 20 | ) |
| 21 | |
| 22 | // teamUnavailable is the retryable answer for Unknown standing: the app's |
| 23 | // own 503 page (or the plain status for a fetch), never cached, with |
| 24 | // Retry-After. A 404 would tell a team member their deck is gone because |
| 25 | // Home was slow. |
| 26 | func (a *app) teamUnavailable(w http.ResponseWriter, r *http.Request) { |
| 27 | w.Header().Set("Cache-Control", "no-store") |
| 28 | w.Header().Set("Retry-After", strconv.Itoa(int(roster.RetryAfter/time.Second))) |
| 29 | a.errorPage(w, r, http.StatusServiceUnavailable, kindStatus, "") |
| 30 | } |
| 31 | |
| 32 | // teamUnavailableJSON is the drive API's: the same status and headers in |
| 33 | // the API's own error shape. |
| 34 | func teamUnavailableJSON(w http.ResponseWriter) { |
| 35 | w.Header().Set("Cache-Control", "no-store") |
| 36 | w.Header().Set("Retry-After", strconv.Itoa(int(roster.RetryAfter/time.Second))) |
| 37 | apiFail(w, http.StatusServiceUnavailable, errUnavailable) |
| 38 | } |
| 39 | |
| 40 | // teamUnknown reports whether u's standing could not be decided. Always |
| 41 | // false outside team mode. |
| 42 | func (a *app) teamUnknown(u User) bool { |
| 43 | return a.team != nil && u.team.state() == roster.Unknown |
| 44 | } |
| 45 | |
| 46 | // teamPartial reports whether a list built for u is incomplete because |
| 47 | // their standing is Unknown: Paul's ruling (2026-10-28, Home |
| 48 | // implementation/teammode-package.md §4) is a partial list with a |
| 49 | // notice, not a 503. visibleDecks has already withheld the team rung, so |
| 50 | // the list holds the decks granted to them and nothing more. Ask it after |
| 51 | // building the list, of the same Access the list was built with: State |
| 52 | // latches, so a lease that lapsed while listing marks the page partial. |
| 53 | // NotMember is never partial: a guest's grants are their whole list. |
| 54 | // Always false outside team mode. |
| 55 | func (a *app) teamPartial(u User) bool { |
| 56 | if a.team == nil { |
| 57 | return false |
| 58 | } |
| 59 | return u.team == nil || u.team.Partial() |
| 60 | } |
| 61 | |
| 62 | // teamMemberOnly gates what makes something new on the instance (a deck, |
| 63 | // by hand or by an agent): team members only, as Docs' and Sheets' |
| 64 | // create. A guest gets 403, Unknown a retryable 503. Outside team mode it |
| 65 | // lets everybody through, as before. |
| 66 | func (a *app) teamMemberOnly(w http.ResponseWriter, r *http.Request, u User) bool { |
| 67 | if a.team == nil { |
| 68 | return true |
| 69 | } |
| 70 | switch u.team.state() { |
| 71 | case roster.Member: |
| 72 | return true |
| 73 | case roster.NotMember: |
| 74 | a.errorPage(w, r, http.StatusForbidden, kindStatus, "") |
| 75 | default: |
| 76 | a.teamUnavailable(w, r) |
| 77 | } |
| 78 | return false |
| 79 | } |
| 80 | |
| 81 | // teamMemberOnlyJSON is teamMemberOnly for the drive API. |
| 82 | func (a *app) teamMemberOnlyJSON(w http.ResponseWriter, u User) bool { |
| 83 | if a.team == nil { |
| 84 | return true |
| 85 | } |
| 86 | switch u.team.state() { |
| 87 | case roster.Member: |
| 88 | return true |
| 89 | case roster.NotMember: |
| 90 | apiFail(w, http.StatusForbidden, errForbidden) |
| 91 | default: |
| 92 | teamUnavailableJSON(w) |
| 93 | } |
| 94 | return false |
| 95 | } |
| 96 | |
| 97 | // presignTTLFor is how long a presigned GET minted for u may live. Off |
| 98 | // team mode, presignTTL. In team mode no longer than the standing it was |
| 99 | // minted on: the Member lease's remaining time, and never beyond the |
| 100 | // roster's own 60 s otherwise (Home implementation/teammode-package.md |
| 101 | // §7.1: a URL must not outlive a removal). Team instances have no store |
| 102 | // today, so nothing presigns there yet; this is what will hold when one |
| 103 | // is bound. |
| 104 | func (a *app) presignTTLFor(u User) time.Duration { |
| 105 | if a.team == nil { |
| 106 | return presignTTL |
| 107 | } |
| 108 | ttl := roster.MaximumAge |
| 109 | if u.team.state() == roster.Member { |
| 110 | if left := u.team.Remaining(); left > 0 && left < ttl { |
| 111 | ttl = left |
| 112 | } |
| 113 | } |
| 114 | return ttl |
| 115 | } |
| 116 | |
| 117 | // teamProbe is GET /api/team, the readiness probe Alta polls at |
| 118 | // provisioning step 11 before it activates this instance in Home's |
| 119 | // directory: teammode's Probe, unauthenticated, no-store, |
| 120 | // {team_mode, consumer, roster} and no account data, and |
| 121 | // {"team_mode":false} with team mode off. |
| 122 | func (a *app) teamProbe(w http.ResponseWriter, r *http.Request) { |
| 123 | var rt *teammode.Runtime |
| 124 | if a.team != nil { |
| 125 | rt = a.team.Runtime |
| 126 | } |
| 127 | teammode.Probe(rt).ServeHTTP(w, r) |
| 128 | } |
| 129 | |