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
3// Team mode's roster-owner rule — RULED by Paul, 2026-10-28, on
4// oficina/sheets #52: team owners can share orphaned sheets.
5//
6// A sheet's ownership is its owner grants. In team mode the creator's own
7// grant counts only while the roster says Member (ownGrantIgnored), so
8// removing a sheet's sole owner from the team leaves a sheet the team can
9// still edit and nobody can share. A roster owner therefore holds
10// SheetOwner on any sheet with no live owner grant, where live means
11// given by somebody else (a share), or held by somebody the roster says
12// is a Member — or whose standing cannot be read right now, which is not
13// "gone". Nothing is written: the moment the roster owner gives somebody
14// an owner grant, or the departed owner is re-added, the sheet has a live
15// owner again and this rule stops applying.
16
17import (
18 "context"
19
20 "amadan.net/oficina/home/roster"
21)
22
23// orphanedForRosterOwner reports whether m is a roster owner and the sheet
24// has no live owner grant. Outside team mode it is always false. It asks
25// the roster about each owner grant holder, never under the SQLite writer:
26// roleFor is not called inside a transaction.
27func (a *App) orphanedForRosterOwner(sheetID uint64, m Member) bool {
28 if a.team == nil || a.teamRole(m) != TeamOwner {
29 return false
30 }
31 var owners []Grant
32 if err := a.db.Where("sheet_id = ? AND role = ?", sheetID, string(SheetOwner)).Find(&owners).Error; err != nil {
33 return false // cannot tell is not orphaned
34 }
35 for _, g := range owners {
36 if g.GrantedBy != g.MemberID {
37 return false // a share: live whatever the roster says
38 }
39 holder, ok := a.memberByID(g.MemberID)
40 if !ok {
41 return false
42 }
43 if a.withStanding(context.Background(), holder).team.state() != roster.NotMember {
44 return false // a current Member, or standing unknown
45 }
46 }
47 return true
48}
49