oficina / meet Public

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

Plain git — no account needed to clone.

Download

Download this file

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