oficina / calendar Public

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

Plain git — no account needed to clone.

Download

Download this file

1package calendar
2
3// Home sign-in for a roster member with no account here: connect's three
4// team-mode hooks (Admit, HomeOnly, Unlinked) over Calendar's people
5// table. 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 newHome 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 (Home's design keeps
19// no address at rest for them). Their people row's address column holds a
20// random "home-only:" placeholder, because the column is NOT NULL and
21// UNIQUE and migrations are additive-only; nothing mails it or shows it.
22// What that costs them, said once here and in the spec (§team mode):
23//
24// - no email reminders: none is made by default, adding one is refused,
25// and the drain sends none (team_jobs.go);
26// - no published booking page: the booker's invitation names the host by
27// address, and the host's own booking mail has nowhere to go;
28// - no local sign-in: they sign in through Oficina only.
29//
30// Storing an address they type for reminders would be a new address
31// column in this app, which needs its own privacy review (Fable on
32// oficina/home #98); it is not in this branch. The options are Paul's.
33
34import (
35 "context"
36 "database/sql"
37 "errors"
38
39 "amadan.net/oficina/home/connect"
40 "amadan.net/oficina/home/teammode"
41
42 "amadan.net/oficina/calendar/internal/calendar/teamstate"
43)
44
45// ErrNoAddress is a Home-only person asking for something that needs an
46// address: a reminder, or publishing a booking page. Team mode only.
47var ErrNoAddress = errors.New("calendar: this needs an email address, and this account has none here")
48
49// teamAdmit is connect's Admit, the roster decision taken first (Home spec
50// 2026-11-14-oficina-id-native.md §8) for a subject with neither a link
51// nor a Home-only person: Runtime.AdmitUnlinked, which allocates nothing
52// and never asks whether Calendar has local accounts. A Member is asked to
53// choose (connect's choose page: connect an existing email account, or
54// "I'm new here", which then reaches teamUnlinked); a stranger is
55// connect's "unknown"; an undecidable roster is a 503.
56func (a *App) teamAdmit(ctx context.Context, issuer, subject string) error {
57 if a.team == nil {
58 return errTeamUnavailable
59 }
60 switch err := a.team.AdmitUnlinked(ctx, issuer, subject); {
61 case err == nil:
62 return nil
63 case errors.Is(err, teammode.ErrNotMember):
64 return connect.ErrNoPerson
65 }
66 return errTeamUnavailable
67}
68
69// teamHomeOnly is connect's HomeOnly: the addressless person Unlinked gave
70// a subject, read and never created.
71func (a *App) teamHomeOnly(d *sql.DB) func(context.Context, string, string) (connect.Person, error) {
72 return func(ctx context.Context, issuer, subject string) (connect.Person, error) {
73 id, err := teamstate.HomePerson(ctx, d, issuer, subject)
74 switch {
75 case err == nil:
76 return connect.Person{ID: id}, nil
77 case errors.Is(err, teamstate.ErrRefused):
78 return connect.Person{}, connect.ErrNoPerson
79 }
80 return connect.Person{}, errTeamUnavailable
81 }
82}
83
84// teamUnlinked is connect's Unlinked, asked only after a Member chose "I'm
85// new here" with nobody signed in, for a subject with neither a link nor a
86// Home-only person (connect rechecks teamAdmit first): an
87// addressless person for a subject the roster says is a Member now, with
88// the lease on that answer still valid (Runtime.AdmitUnlinked). A stranger
89// is connect's "unknown"; an undecidable roster is a 503. Their calendars
90// are made on their first page (teamRequirePerson), as a local person's
91// are.
92func (a *App) teamUnlinked(d *sql.DB) func(context.Context, string, string) (connect.Person, error) {
93 return func(ctx context.Context, issuer, subject string) (connect.Person, error) {
94 if a.team == nil {
95 return connect.Person{}, errTeamUnavailable
96 }
97 if err := a.team.AdmitUnlinked(ctx, issuer, subject); err != nil {
98 if errors.Is(err, teammode.ErrNotMember) {
99 return connect.Person{}, connect.ErrNoPerson
100 }
101 return connect.Person{}, errTeamUnavailable
102 }
103 id, _, err := teamstate.EnsureHomePerson(ctx, d, issuer, subject, teamstate.Defaults{
104 Zone: defaultZone, WeekStart: WeekStartMonday, ReminderMin: DefaultReminderMin, AllDayMin: DefaultAllDayMin,
105 })
106 switch {
107 case err == nil:
108 return connect.Person{ID: id}, nil
109 case errors.Is(err, teamstate.ErrRefused):
110 // Linked to a local account in the meantime: that person
111 // signs in as that account, not as a new one.
112 return connect.Person{}, connect.ErrNoPerson
113 }
114 return connect.Person{}, errTeamUnavailable
115 }
116}
117
118// refuseAddressless is ErrNoAddress for a Home-only person in team mode,
119// nil for everybody else and always nil outside team mode.
120func (s *Store) refuseAddressless(ctx context.Context, personID int64) error {
121 if !s.team {
122 return nil
123 }
124 var p Person
125 if err := s.g.WithContext(ctx).Select("id", "address").First(&p, personID).Error; err != nil {
126 return err
127 }
128 if teamstate.Addressless(p.Address) {
129 return ErrNoAddress
130 }
131 return nil
132}
133
134// noAddress reports whether p is a Home-only person in team mode, for the
135// pages that say what that costs them. Always false outside team mode.
136func (h *handlers) noAddress(p Person) bool {
137 return h.team != nil && p.homeOnly != ""
138}
139