oficina / slides Public

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

Plain git — no account needed to clone.

Download

Download this file

1package slides
2
3// Team mode's ownership, and the roster-owner rule for orphaned decks —
4// RULED by Paul, 2026-10-30, on oficina/slides #33 ("share only, no
5// delete for now (may change his mind later)"; "team-visible decks
6// only"), after his Sheets ruling of 2026-10-28 on oficina/sheets #52.
7//
8// A deck's owner is decks.owner_id. In team mode that is the team rung's,
9// as Docs' owner_id rule is: the owner owns the deck only while the
10// roster says Member. Removing a deck's owner from the team therefore
11// leaves a team-rung deck the team can still read, edit and present, and
12// nobody can share. The rule: on an ORPHAN — a deck on the team rung
13// whose owner the roster definitely says is gone (NotMember, which
14// includes a local account with no Home identity, or an owner row that
15// no longer exists) — a roster owner may
16//
17// - share it: the share page and its links (mayShareDeck);
18// - change its title and theme (mayRetitleDeck);
19//
20// and may NOT
21//
22// - delete it (mayDeleteDeck), nor
23// - change its rung (mayChangeRung): making it private hides it from
24// everybody, the roster owner included, which Paul treats as a
25// soft-delete.
26//
27// Only the team rung: a departed member's private deck is no orphan,
28// even to a roster owner who holds a grant to read it. An owner whose
29// standing cannot be read right now is not "gone". Nothing is written:
30// the moment the departed owner is re-added, the deck has a live owner
31// again and the rule stops applying.
32//
33// Each power is its own predicate, so widening one later (Paul may
34// rule delete back in) is one line in one place.
35
36import (
37 "context"
38 "errors"
39
40 "gorm.io/gorm"
41
42 "amadan.net/oficina/home/roster"
43)
44
45// ownsDeck reports whether u is d's owner: d.OwnerID, while Member in
46// team mode. Outside team mode it is exactly d.OwnerID == u.ID.
47func (a *app) ownsDeck(u User, d Deck) bool {
48 return d.OwnerID == u.ID && a.member(u)
49}
50
51// mayShareDeck: the share page, minting and revoking share links. The
52// owner, or a roster owner on an orphan.
53func (a *app) mayShareDeck(ctx context.Context, u User, d Deck) bool {
54 return a.ownsDeck(u, d) || a.orphanedForRosterOwner(ctx, u, d)
55}
56
57// mayRetitleDeck: the settings page and its title and theme. The owner,
58// or a roster owner on an orphan.
59func (a *app) mayRetitleDeck(ctx context.Context, u User, d Deck) bool {
60 return a.ownsDeck(u, d) || a.orphanedForRosterOwner(ctx, u, d)
61}
62
63// mayChangeRung: who can open the deck. The owner alone.
64func (a *app) mayChangeRung(_ context.Context, u User, d Deck) bool {
65 return a.ownsDeck(u, d)
66}
67
68// mayDeleteDeck: the delete page and the delete. The owner alone.
69func (a *app) mayDeleteDeck(_ context.Context, u User, d Deck) bool {
70 return a.ownsDeck(u, d)
71}
72
73// orphanedForRosterOwner reports whether u is a roster owner, now, and d
74// is an orphan: on the team rung, its owner definitely off the team. It
75// asks the roster about the owner, never under the SQLite writer: no
76// owner check runs inside a transaction. Always false outside team mode.
77func (a *app) orphanedForRosterOwner(ctx context.Context, u User, d Deck) bool {
78 if a.team == nil || d.Rung != rungTeam || !u.team.rosterOwner() || d.OwnerID == u.ID {
79 return false
80 }
81 var owner User
82 err := a.db.G.WithContext(ctx).Take(&owner, d.OwnerID).Error
83 switch {
84 case errors.Is(err, gorm.ErrRecordNotFound):
85 return true // nobody owns it at all: the one repair path there is
86 case err != nil:
87 return false // cannot tell is not orphaned
88 }
89 return a.withStanding(ctx, owner).team.state() == roster.NotMember
90}
91