| 1 | package calendar |
| 2 | |
| 3 | // Team mode's reach: which grants a scoped read may join through. |
| 4 | // |
| 5 | // Calendar has no shares. Every grant is made by EnsurePersonSetup for the |
| 6 | // person themselves — editor on the team calendar, owner of their own — |
| 7 | // so every grant is the team rung, and in team mode counts only while the |
| 8 | // roster says Member (Docs' owner rule, Sheets' "self-grants count only |
| 9 | // while Member"). Somebody whose standing is anything else reaches |
| 10 | // nothing: NotMember is signed out before any read (team_access.go), and |
| 11 | // under Unknown a view is the empty partial list with its notice. |
| 12 | // |
| 13 | // The standing is read from the context, once, BEFORE the query is built |
| 14 | // (Sheets' stream-order lesson, oficina/slides #33 and oficina/sheets |
| 15 | // #54): a read never decides reach and then asks standing. A view asks |
| 16 | // Partial again after it is built, of the same Access, because State |
| 17 | // latches (requestUnknown). |
| 18 | // |
| 19 | // Outside team mode reaches is always true and every join is exactly the |
| 20 | // one it has always been. |
| 21 | |
| 22 | import ( |
| 23 | "context" |
| 24 | |
| 25 | "amadan.net/oficina/home/roster" |
| 26 | "amadan.net/oficina/home/teammode" |
| 27 | ) |
| 28 | |
| 29 | // reaches reports whether a read on ctx may join through the team rung: |
| 30 | // always outside team mode, and inside it only while the Access ctx |
| 31 | // carries says Member. A context with none (a path that forgot to carry |
| 32 | // one) reaches nothing: the closed answer is the one that cannot leak. |
| 33 | func (s *Store) reaches(ctx context.Context) bool { |
| 34 | if !s.team { |
| 35 | return true |
| 36 | } |
| 37 | return teammode.Standing(ctx) == roster.Member |
| 38 | } |
| 39 | |
| 40 | // grantJoin is the join every scoped read goes through: the viewer's grant |
| 41 | // on the calendar named by on, decided by rung (reaches, asked once per |
| 42 | // read). A read that does not reach keeps the join and matches nothing, |
| 43 | // so its shape — and every caller's handling of "not found" — is the |
| 44 | // same. |
| 45 | func grantJoin(on string, rung bool) string { |
| 46 | join := "JOIN grants ON grants.calendar_id = " + on + " AND grants.person_id = ?" |
| 47 | if !rung { |
| 48 | join += " AND 0" |
| 49 | } |
| 50 | return join |
| 51 | } |
| 52 | |