oficina / memoria Public

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

Plain git — no account needed to clone.

Download

Download this file

1package memoria
2
3// Home sign-in for a roster member with no account here: connect's three
4// team-mode hooks (Admit, HomeOnly, Unlinked) over Memoria's Home identity
5// rows; since connect's member choice, a Member with no link is first asked
6// to choose between connecting an existing email account and "I'm new
7// here", which makes the Home-only person. connect completes an
8// ordinary Home sign-in only for a subject with an account link, and
9// refuses the rest as "unknown" — right for an owners-list instance,
10// where nobody may enter on a Home identity alone. In team mode a roster
11// member who has never had a local account must be able to, so WireHome
12// gives connect these, and connect's own completion does the rest (its
13// cookie checks, the same-person rule, the link flow).
14//
15// The person Unlinked creates is identity, never standing: every request
16// after this one asks the roster again (team_access.go). It holds no
17// address: an addressless memoria_home_local_identities row and the
18// subject it belongs to (teamstate).
19
20import (
21 "context"
22 "database/sql"
23 "errors"
24
25 "amadan.net/oficina/home/connect"
26 "amadan.net/oficina/home/teammode"
27
28 "amadan.net/oficina/memoria/internal/memoria/teamstate"
29)
30
31// teamAdmit is connect's Admit, the roster decision taken first (Home spec
32// 2026-11-14-oficina-id-native.md §8) for a subject with neither a link
33// nor a Home-only person: Runtime.AdmitUnlinked, which allocates nothing
34// and never asks whether Memoria has local accounts. A Member is asked to
35// choose (connect's choose page: connect an existing email account, or
36// "I'm new here", which then reaches teamUnlinked); a stranger is
37// connect's "unknown"; an undecidable roster is a 503.
38func (a *app) teamAdmit(ctx context.Context, issuer, subject string) error {
39 if a.team == nil {
40 return errTeamUnavailable
41 }
42 switch err := a.team.AdmitUnlinked(ctx, issuer, subject); {
43 case err == nil:
44 return nil
45 case errors.Is(err, teammode.ErrNotMember):
46 return connect.ErrNoPerson
47 }
48 return errTeamUnavailable
49}
50
51// teamHomeOnly is connect's HomeOnly: the addressless person Unlinked
52// gave a subject, read and never created.
53func (a *app) teamHomeOnly(d *sql.DB) func(context.Context, string, string) (connect.Person, error) {
54 return func(ctx context.Context, issuer, subject string) (connect.Person, error) {
55 id, err := teamstate.HomeMember(ctx, d, issuer, subject)
56 switch {
57 case err == nil:
58 return connect.Person{ID: id}, nil
59 case errors.Is(err, teamstate.ErrRefused):
60 return connect.Person{}, connect.ErrNoPerson
61 }
62 return connect.Person{}, errTeamUnavailable
63 }
64}
65
66// teamUnlinked is connect's Unlinked, asked only after a Member chose "I'm
67// new here" with nobody signed in, for a subject with neither a link nor
68// a Home-only person (connect rechecks teamAdmit first): an
69// addressless person for a subject the roster says is a Member now, with
70// the lease on that answer still valid (Runtime.AdmitUnlinked). A
71// stranger is connect's "unknown"; an undecidable roster is a 503.
72func (a *app) teamUnlinked(d *sql.DB) func(context.Context, string, string) (connect.Person, error) {
73 return func(ctx context.Context, issuer, subject string) (connect.Person, error) {
74 if a.team == nil {
75 return connect.Person{}, errTeamUnavailable
76 }
77 if err := a.team.AdmitUnlinked(ctx, issuer, subject); err != nil {
78 if errors.Is(err, teammode.ErrNotMember) {
79 return connect.Person{}, connect.ErrNoPerson
80 }
81 return connect.Person{}, errTeamUnavailable
82 }
83 id, err := teamstate.EnsureHomeMember(ctx, d, issuer, subject)
84 switch {
85 case err == nil:
86 return connect.Person{ID: id}, nil
87 case errors.Is(err, teamstate.ErrRefused):
88 // Linked to a local account in the meantime: that person signs
89 // in as that account, not as a new one.
90 return connect.Person{}, connect.ErrNoPerson
91 }
92 return connect.Person{}, errTeamUnavailable
93 }
94}
95