oficina / sheets Public

Clone
git clone https://amadan.net/oficina/sheets

Plain git — no account needed to clone.

Download

Download this file

1package sheets
2
3import (
4 "context"
5 "net/http"
6 "strconv"
7)
8
9// noticeRevokedTeam is the code for a revoke that removed a grant and
10// did not remove anybody's access.
11//
12// Team standing reaches every sheet on the instance as an editor, by
13// design (spec §8.2), and an explicit grant sits on top of it. So
14// removing a teammate's grant takes the grant away and leaves the
15// person able to open the sheet. The screen used to report the first
16// half and stay silent about the second, which let an owner read
17// "Access removed", walk away, and believe they had shut somebody out
18// of a sealed sheet.
19//
20// RULED by Paul, 2026-09-01: the sentence is what changes here, not the
21// behaviour. Removing a restricting grant from a teammate still widens
22// their access from viewer to editor — see the issue filed against this
23// commit, which records that as a separate, open question rather than
24// letting it disappear behind a notice that now describes it politely.
25const noticeRevokedTeam = "revoked-team"
26
27// revokedTeamText is the sentence when we cannot name the person.
28//
29// Paul's wording, with the name generalised for the fallback below.
30const revokedTeamText = "The explicit permission is removed, but since they are " +
31 "on the team, they still have access."
32
33// stillReaches reports whether somebody can still open a sheet.
34//
35// Asked AFTER the revoke, and asked of roleFor rather than reasoned
36// about separately, so the notice reports what the gate actually says
37// instead of holding a second opinion that can drift from it.
38func (a *App) stillReaches(ctx context.Context, sheetID, memberID uint64) bool {
39 m, ok := a.memberByID(memberID)
40 if !ok {
41 // The grant is gone and we cannot tell what is left. The plain
42 // sentence is the one that claims less.
43 return false
44 }
45 _, still := a.roleFor(sheetID, a.withStanding(ctx, m))
46 return still
47}
48
49// revokedTeamNotice names the person the notice is about.
50//
51// Naming them is not decoration: revoking the grant also takes them off
52// the list below, so an unnamed sentence would refer to somebody the
53// owner can no longer see anywhere on the screen.
54//
55// The member ID travels in the query and the address does not, which is
56// the whole reason this reads the row back. An email address in a
57// request line lands in the platform edge's access logs — the same leak
58// the share-link token was moved out of one commit earlier — while an
59// id is already on this screen in every revoke form's hidden field.
60//
61// Checked rather than trusted: the id came from a URL, so the sentence
62// is personalised only for a member this sheet genuinely still admits.
63func (a *App) revokedTeamNotice(r *http.Request, sheetID uint64) string {
64 id, err := strconv.ParseUint(r.URL.Query().Get("who"), 10, 64)
65 if err != nil || id == 0 {
66 return revokedTeamText
67 }
68 m, ok := a.memberByID(id)
69 if ok {
70 m = a.withStanding(r.Context(), m) // for Label's Home-only ref
71 }
72 if !ok || !a.stillReaches(r.Context(), sheetID, m.ID) {
73 return revokedTeamText
74 }
75 return "The explicit permission is removed, but since " + m.Label() +
76 " is on the team, they still have access."
77}
78
79// noticeTone is the rastrillo callout tone for a notice code on the
80// share, comments and history pages (shared chrome spec §4). They were
81// all one neutral grey callout, so "Access removed." and "Unknown role."
82// looked the same.
83//
84// - positive: the thing asked for happened.
85// - negative: it did not, and the form needs something different.
86// - warning: it happened, and there is something to know about it.
87// - info: nothing happened, and nothing was wrong.
88func noticeTone(code string) string {
89 switch code {
90 case "shared", "revoked", "link-revoked", "added", "resolved", "restored", "undone":
91 return "positive"
92 case "bad-address", "bad-role", "last-owner", "bad-link-role", "empty", "no-cell", "gone":
93 return "negative"
94 case noticeRevokedTeam, "link":
95 return "warning"
96 }
97 return "info"
98}
99