Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/added-18395-attendee-email-settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Settings, Meeting attendee now shows Betty's email address with everyone's calendar emails and proof status, lets each user add, prove and remove their own calendar emails, lists mailed-in files waiting for approval, and lets the owner turn calendar invites and mail-in files on or off.
2 changes: 1 addition & 1 deletion src/docs/api-reference/knowledge.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f
| `POST` | `/api/meetings/actions/{aid}/approve` | Owner or read-write | Create the draft (issue or RFC on GitHub, Spek session through the Inbox `spek_rfc` destination, knowledge note in the `meetings` vault) and report the result to the meeting. Returns the draft, `done` with `result_url` or `failed` with `error`. 409 when it is not pending or failed, or action requests are off. Audited as `meeting_action_approve` | `pkg/dashboard/api_meetings_actions.go:73` |
| `POST` | `/api/meetings/actions/{aid}/reject` | Owner or read-write | Reject a pending or failed draft; nothing is created. Audited as `meeting_action_reject` | `pkg/dashboard/api_meetings_actions.go:74` |
| `GET` | `/api/meetings/persona` | Owner or read-write | Settings, Meeting attendee: `{effective, presets, overridden, voices, voice_types, restart_required, running, tts_configured, email}`. `effective` is the resolved persona (fields resolved as if on, `enabled` separately) with the rendered `intro` and `voice_on_address`; `presets` lists the built-in personas, the default first; `overridden` maps each `meetings.persona` key not taken from the preset or defaults to `config` or `env`; `voices` are the Kokoro voices with language, accent and voice type; `restart_required` is true when the saved persona differs from the one the hive booted with; `email` is the attendee address (`hive@<dashboard host>`), the access list with registered calendar emails and proof status, the approval queue and the email-in switches (`available: false` until email-in is enabled). See [Meeting attendee settings](../meetings.md#meeting-attendee-settings) | `pkg/dashboard/api_meetings_persona.go:164` |
| `PUT` | `/api/meetings/persona` | Owner or read-write | Save `meetings.persona` to `hive.yaml`: `{enabled?, preset?, clear_overrides?, name?, display_name?, aliases?, pronouns?, language?, voice?, voice_type?, accent?, intro_template?, leave_phrases?, humor?, unprompted?: {per_10m?, min_gap_s?, per_meeting?, answer_wait_s?, min_confidence?, queue_depth?, stale_s?}, voice_on_address?}`. An absent field is unchanged, an empty one (or 0 for a cap) clears the override, a value equal to the preset's is stored as no override, and `clear_overrides` drops every field override first. Validated as if the persona were on; returns the GET body. 400 invalid. Audited as `meetings_persona` | `pkg/dashboard/api_meetings_persona.go:165` |
| `PUT` | `/api/meetings/persona` | Owner or read-write | Save `meetings.persona` to `hive.yaml`: `{enabled?, preset?, clear_overrides?, name?, display_name?, aliases?, pronouns?, language?, voice?, voice_type?, accent?, intro_template?, leave_phrases?, humor?, unprompted?: {per_10m?, min_gap_s?, per_meeting?, answer_wait_s?, min_confidence?, queue_depth?, stale_s?}, voice_on_address?}`. An absent field is unchanged, an empty one (or 0 for a cap) clears the override, a value equal to the preset's is stored as no override, and `clear_overrides` drops every field override first. Validated as if the persona were on; returns the GET body. 400 invalid. Audited as `meetings_persona`. An optional `email: {calendar_invites?, mail_in_files?}` sets `meetings.email.invites_enabled` / `files_enabled` (owner only, else 403; [#18395](https://github.com/hivecommons/hive/issues/18395)) | `pkg/dashboard/api_meetings_persona.go:165` |
| `POST` | `/api/meetings/persona/sample` | Owner or read-write | Speak a short line through the meetings TTS service (Kokoro `POST /v1/audio/speech`) and return the audio (`audio/mpeg`, at most 2 MiB, `Cache-Control: no-store`). Optional `{voice?, language?, display_name?, text?}` (unsaved form values; `text` at most 200 characters, default the persona's sample line in its language). 503 "TTS not configured" until `meetings.tts_url` is set, 400 invalid, 502 the TTS service failed | `pkg/dashboard/api_meetings_persona.go:166` |
| `GET` | `/api/meetings/persona/sample` | Owner or read-write | The same sample with `voice`, `language`, `display_name` and `text` as query parameters, for the dashboard's `<audio>` element (the dashboard CSP has no `media-src`, so audio must come from the dashboard origin) | `pkg/dashboard/api_meetings_persona.go:169` |
| `POST` | `/api/meetings/invites` | Hub relay signature | Calendar invites hive-mx received for `hive@<host>` ([#18395](https://github.com/hivecommons/hive/issues/18395)), relayed by the hub with `X-Hive-Relay-Timestamp`, `X-Hive-Relay-Signature-256` and `X-Hive-Relay-Delivery` (5-minute skew, replay-protected). An invite is scheduled at once when the sender is its organizer, passed DMARC alignment and is on the calendar email allowlist, otherwise it awaits approval; a change or CANCEL for a meeting already on the calendar applies only when authenticated as its organizer. `200 {results[]}`; `409` invites or meetings off; `422` nothing schedulable; `401` bad relay signature. See [Inviting Betty by email](../meetings.md#inviting-betty-by-email) | `pkg/dashboard/api_meetings_email.go:60` |
Expand Down
2 changes: 1 addition & 1 deletion src/docs/meetings.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Settings, **Meeting attendee** edits all of this from the dashboard ([#18396](ht

- **Persona.** Preset cards show each persona's flag, language, accent, voice type and voice id. Picking one fills the form; Save stores it. A value equal to the preset's is stored as no override, so the persona keeps following the preset. The voice list shows the Kokoro voices for the chosen language, and changing the language picks a voice of the same type. The intro has a live preview. **Play sample** speaks a short line in the persona's language through the meetings TTS service (the browser plays it from `GET /api/meetings/persona/sample`, using the form's unsaved voice, language and name); until that service is configured (`meetings.tts_url` and its token, phase B) the button is disabled and the API answers "TTS not configured".
- **Behaviour.** The unprompted caps above (`per_10m`, `min_gap_s`, `per_meeting`, `answer_wait_s`, `min_confidence`, `queue_depth`, `stale_s`; 0 restores a default) and whether hive may speak aloud when addressed (`meetings.voice_on_address`).
- **Email.** The attendee address, `hive@<dashboard host>`, with a copy button, the people with access to this hive (owner, read-write and read) with their registered calendar emails and proof status, the invites and files waiting for approval, and switches for calendar invites and mailed-in files. Until email-in is enabled ([#18395](https://github.com/hivecommons/hive/issues/18395)) the section is shown with its controls disabled.
- **Email.** The attendee address, `hive@<dashboard host>`, with a copy button, the people with access to this hive (owner, read-write and read) with their registered calendar emails and proof status, the mailed-in files waiting for approval (invites waiting for approval are in the **Calendar**), **My calendar emails** where each user adds, proves and removes their own addresses (see [Proving calendar emails](#proving-calendar-emails)), and the owner's switches for calendar invites and mailed-in files (`meetings.email.*`, saved with **Save**; a read-write user sees them read-only). The section is live once the hive's calendar email allowlist is wired ([#18395](https://github.com/hivecommons/hive/issues/18395)); before that its controls are disabled.

The presets use only voices the self-hosted Kokoro TTS ([Kokoro-FastAPI](https://github.com/remsky/Kokoro-FastAPI) v0.10.0) ships. Leave phrases stay in Latin script because the leave matcher uses ASCII word boundaries, and every preset keeps "hive" as an alias and "hive leave" as a leave phrase.

Expand Down
10 changes: 9 additions & 1 deletion src/pkg/dashboard/api_meetings_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@ func (s *Server) registerMeetingsEmailRoutes() {
}

// SetMailAllowlist installs the email allowlist store (nil removes it).
func (s *Server) SetMailAllowlist(st *mailallow.Store) { s.mailAllow.Store(st) }
// It also feeds Settings, Meeting attendee its Email section.
func (s *Server) SetMailAllowlist(st *mailallow.Store) {
s.mailAllow.Store(st)
if st == nil {
s.SetMeetingsAttendeeEmail(nil)
return
}
s.SetMeetingsAttendeeEmail(mailAttendeeEmail{s: s})
}

func (s *Server) mailAllowlist() *mailallow.Store { return s.mailAllow.Load() }

Expand Down
69 changes: 69 additions & 0 deletions src/pkg/dashboard/api_meetings_email_attendee.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dashboard

import (
"context"
"time"

"github.com/hivecommons/hive/pkg/inbox"
)

// mailAttendeeEmail feeds Settings, Meeting attendee (#18396) its Email
// section from the email-in state (#18395): the proven and pending calendar
// emails per user, the mail-in files waiting for the owner, and the
// meetings.email switches. Invites waiting for approval stay in the
// Calendar, where they are approved.
type mailAttendeeEmail struct{ s *Server }

// Calendar email proof states the tab shows.
const (
mailProofVerified = "verified"
mailProofPending = "pending"
// mailApprovalKindFile is the kind of a mail-in file in the queue.
mailApprovalKindFile = "file"
)

// Snapshot implements MeetingsAttendeeEmail.
func (m mailAttendeeEmail) Snapshot(ctx context.Context) (MeetingsAttendeeEmailSnapshot, error) {
snap := MeetingsAttendeeEmailSnapshot{Emails: map[string][]MeetingsCalendarEmail{}, Approvals: []MeetingsEmailApproval{}}
if st := m.s.mailAllowlist(); st != nil {
for _, e := range st.All() {
ce := MeetingsCalendarEmail{Address: e.Email, Proof: mailProofPending}
if e.Proven() {
ce.Proof, ce.VerifiedAt = mailProofVerified, e.ProvenAt.UTC().Format(time.RFC3339)
}
snap.Emails[e.Login] = append(snap.Emails[e.Login], ce)
}
}
if m.s.deps != nil && m.s.deps.Inbox != nil {
if src := m.s.deps.Inbox.Email(); src != nil {
items, err := src.List(ctx)
if err != nil {
return snap, err
}
for _, it := range items {
if !it.AwaitingApproval {
continue
}
snap.Approvals = append(snap.Approvals, mailApproval(it))
}
}
}
em := m.s.meetingsEmailConfig()
snap.CalendarInvites, snap.MailInFiles = em.InvitesOn(), em.FilesOn()
return snap, nil
}

func mailApproval(it inbox.Item) MeetingsEmailApproval {
a := MeetingsEmailApproval{ID: it.ID, Kind: mailApprovalKindFile, From: it.Sender, Subject: it.Title}
if !it.RecordedAt.IsZero() {
a.ReceivedAt = it.RecordedAt.UTC().Format(time.RFC3339)
}
return a
}

// meetingsEmailRequest is the optional email block of PUT
// /api/meetings/persona: the meetings.email switches (owner only).
type meetingsEmailRequest struct {
CalendarInvites *bool `json:"calendar_invites,omitempty"`
MailInFiles *bool `json:"mail_in_files,omitempty"`
}
93 changes: 93 additions & 0 deletions src/pkg/dashboard/api_meetings_email_attendee_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package dashboard

import (
"encoding/json"
"net/http"
"testing"

"github.com/hivecommons/hive/pkg/mailin/wire"
)

// TestMeetingAttendeeEmailSnapshot: once the allowlist is wired, the
// Settings tab's Email section is available and shows each user's calendar
// emails with proof status and the mail-in files waiting for the owner.
func TestMeetingAttendeeEmailSnapshot(t *testing.T) {
s, src := mailFilesServer(t) // bob@example.com proven for bob
if _, err := s.mailAllowlist().Add("alice", "alice@example.com"); err != nil {
t.Fatal(err)
}
if _, err := src.Add(filesDelivery("stranger@example.org", false, wire.Attachment{Name: "x.md", Kind: wire.AttachMarkdown, Data: []byte("# x")}), false); err != nil {
t.Fatal(err)
}
if _, err := src.Add(filesDelivery("bob@example.com", true, wire.Attachment{Name: "y.md", Kind: wire.AttachMarkdown, Data: []byte("# y")}), true); err != nil {
t.Fatal(err)
}
got := personaGet(t, s).Email
if !got.Available || !got.CalendarInvites || !got.MailInFiles {
t.Fatalf("email view %+v", got)
}
byLogin := map[string][]MeetingsCalendarEmail{}
for _, p := range got.Inviters {
byLogin[p.Login] = p.Emails
}
if b := byLogin["bob"]; len(b) != 1 || b[0].Proof != mailProofVerified || b[0].VerifiedAt == "" {
t.Fatalf("bob %+v", b)
}
if a := byLogin["alice"]; len(a) != 1 || a[0].Proof != mailProofPending {
t.Fatalf("alice %+v", a)
}
if len(got.Approvals) != 1 || got.Approvals[0].From != "stranger@example.org" || got.Approvals[0].Kind != mailApprovalKindFile || got.Approvals[0].ReceivedAt == "" {
t.Fatalf("approvals %+v", got.Approvals)
}

// Without an allowlist the section is pending again.
s.SetMailAllowlist(nil)
if personaGet(t, s).Email.Available {
t.Fatal("email available without the allowlist")
}
}

func TestMeetingAttendeeEmailSnapshotWithoutInbox(t *testing.T) {
s, _ := mailServer(t)
snap, err := (mailAttendeeEmail{s: s}).Snapshot(t.Context())
if err != nil || len(snap.Approvals) != 0 {
t.Fatalf("snapshot %+v %v", snap, err)
}
s.SetMailAllowlist(nil)
if snap, _ := (mailAttendeeEmail{s: s}).Snapshot(t.Context()); len(snap.Emails) != 0 {
t.Fatal("emails without a store")
}
}

// TestMeetingAttendeeEmailSwitches: the owner turns invites and mail-in
// files off from Settings; a read-write user cannot.
func TestMeetingAttendeeEmailSwitches(t *testing.T) {
t.Setenv("HIVE_MEETINGS_EMAIL_INVITES_ENABLED", "")
t.Setenv("HIVE_MEETINGS_EMAIL_FILES_ENABLED", "")
s, _ := mailServer(t)
body := `{"email":{"calendar_invites":false,"mail_in_files":false}}`
if rec := personaReq(s, http.MethodPut, "/api/meetings/persona", body, "read-write", false); rec.Code != http.StatusForbidden {
t.Fatalf("read-write switch: %d", rec.Code)
}
rec := personaReq(s, http.MethodPut, "/api/meetings/persona", body, "owner", true)
if rec.Code != http.StatusOK {
t.Fatalf("owner switch: %d %s", rec.Code, rec.Body)
}
var got MeetingsPersonaSettings
_ = json.Unmarshal(rec.Body.Bytes(), &got)
if got.Email.CalendarInvites || got.Email.MailInFiles {
t.Fatalf("switches not saved: %+v", got.Email)
}
if s.meetingsEmailConfig().InvitesOn() || s.meetingsEmailConfig().FilesOn() {
t.Fatal("config not updated")
}
// A persona save without the email block leaves them alone.
personaPut(t, s, `{"name":"Betty"}`, http.StatusOK)
if s.meetingsEmailConfig().InvitesOn() {
t.Fatal("persona save reset the switches")
}
personaReq(s, http.MethodPut, "/api/meetings/persona", `{"email":{"calendar_invites":true}}`, "owner", true)
if !s.meetingsEmailConfig().InvitesOn() || s.meetingsEmailConfig().FilesOn() {
t.Fatal("a partial email block changes only what it names")
}
}
17 changes: 17 additions & 0 deletions src/pkg/dashboard/api_meetings_persona.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ type meetingsPersonaRequest struct {
Unprompted *meetingsPersonaUnpromptedRequest `json:"unprompted,omitempty"`
// VoiceOnAddress sets meetings.voice_on_address.
VoiceOnAddress *bool `json:"voice_on_address,omitempty"`
// Email sets meetings.email.invites_enabled and files_enabled (owner
// only, #18395).
Email *meetingsEmailRequest `json:"email,omitempty"`
}

// applyMeetingsPersonaRequest returns p with req applied.
Expand Down Expand Up @@ -504,6 +507,20 @@ func (s *Server) handleMeetingsPersonaPut(w http.ResponseWriter, r *http.Request
jsonError(w, err.Error(), http.StatusBadRequest)
return
}
if req.Email != nil {
if !isOwnerRole(r.Header.Get("X-Hive-Role")) {
jsonError(w, "only the owner changes which email this hive accepts", http.StatusForbidden)
return
}
if v := req.Email.CalendarInvites; v != nil {
b := *v
s.deps.Config.Meetings.Email.InvitesEnabled = &b
}
if v := req.Email.MailInFiles; v != nil {
b := *v
s.deps.Config.Meetings.Email.FilesEnabled = &b
}
}
s.deps.Config.Meetings.Persona = next
if req.VoiceOnAddress != nil {
v := *req.VoiceOnAddress
Expand Down
21 changes: 17 additions & 4 deletions src/pkg/dashboard/meeting_attendee_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ func TestMeetingAttendeeTabBehaviour(t *testing.T) {
"const yamlHint = p => '<code>' + p + '</code>';",
"const document = { getElementById: () => null, querySelector: () => null };",
"let _maState = null;",
"let _owner = true; const viewerIsOwner = () => _owner;",
}
for _, c := range []string{"MA_LANGUAGE_LABELS", "MA_FLAG_BASE", "MA_PERSONA_FIELDS", "MA_LIST_FIELDS", "MA_CAP_FIELDS"} {
parts = append(parts, jsConstBlock(t, html, c))
}
for _, f := range []string{"maLanguageLabel", "maFlag", "maRenderIntro", "renderGovMeetingAttendee", "maSetData", "maPreset",
"maOverrideNote", "maPresetCardHtml", "maField", "maTextInput", "maVoiceOptions", "maLanguageOptions", "maVoiceTypeOptions",
"maPersonaHtml", "maBehaviourHtml", "maEmailHtml", "maRender", "maRefreshPreview", "maInput", "maCapInput",
"maLanguageChanged", "maPickPreset", "maRequestBody", "maSampleSrc"} {
"maLanguageChanged", "maPickPreset", "maRequestBody", "maSampleSrc", "maMyEmailsHtml", "maEmailToggle"} {
parts = append(parts, jsFunc(t, html, f))
}
parts = append(parts,
Expand Down Expand Up @@ -103,12 +104,24 @@ func TestMeetingAttendeeTabBehaviour(t *testing.T) {
`assert.strictEqual(body.preset, 'melie'); assert.strictEqual(body.enabled, false); assert.ok('voice_on_address' in body);`,
`let email = maEmailHtml();`,
`assert.ok(email.includes('Available once email-in is enabled'), 'pending note');`,
`assert.ok(email.includes('data-ma-email="calendar_invites" disabled>'), 'toggles disabled until email-in');`,
`_maState.data.email = { available: true, address: 'hive@h.example', calendar_invites: true, inviters: [{login: 'bob', role: 'read-write', display_name: 'Bob', emails: [{address: 'bob@example.com', proof: 'verified'}]}], approvals: [{kind: 'invite', from: 'x@y', subject: 'Sync'}] };`,
`assert.ok(email.includes('data-arg0="calendar_invites" data-arg-types="s,c" disabled>'), 'toggles disabled until email-in');`,
`assert.ok(!email.includes('My calendar emails'), 'no own-email list until email-in');`,
`maSetData(Object.assign({}, _maState.data, { email: { available: true, address: 'hive@h.example', calendar_invites: true, inviters: [{login: 'bob', role: 'read-write', display_name: 'Bob', emails: [{address: 'bob@example.com', proof: 'verified'}]}], approvals: [{kind: 'invite', from: 'x@y', subject: 'Sync'}] } }));`,
`email = maEmailHtml();`,
`assert.ok(!email.includes('Available once email-in'), 'no pending note once available');`,
`assert.ok(email.includes('data-ma-email="calendar_invites" checked>'), 'toggle enabled');`,
`assert.ok(email.includes('data-arg0="calendar_invites" data-arg-types="s,c" checked>'), 'toggle enabled for the owner');`,
`assert.ok(email.includes('bob@example.com') && email.includes('ma-verified') && email.includes('invite from x@y'), email);`,
`assert.ok(email.includes('My calendar emails') && email.includes('Loading'), 'own list loading');`,
`_maState.mine = { address: 'hive@h.example', emails: [{ email: 'me@x.org', proven: false, code: 'hive-proof-aaaaaaaaaaaa', active: true, last_error: 'the proof mail came from a different address' }, { email: 'old@x.org', proven: true, active: false }] };`,
`email = maEmailHtml();`,
`assert.ok(email.includes('hive-proof-aaaaaaaaaaaa') && email.includes('data-action="maRemoveMyEmail" data-arg0="me@x.org"') && email.includes('different address') && email.includes('not on the allowlist'), email);`,
`_maState.mine = { emails: [] }; assert.ok(maEmailHtml().includes('not added a calendar email'));`,
`_maState.mine = { error: 'boom' }; assert.ok(maEmailHtml().includes('boom'));`,
`_maState.mine = { address: 'a', emails: [{ email: 'e@x.org', proven: false }] }; assert.ok(maEmailHtml().includes('code expired'));`,
`assert.ok(!('email' in maRequestBody()), 'untouched switches are not sent');`,
`maEmailToggle('mail_in_files', true); assert.deepStrictEqual(maRequestBody().email, { calendar_invites: true, mail_in_files: true });`,
`_owner = false; email = maEmailHtml(); assert.ok(email.includes('Only the owner') && email.includes('data-arg-types="s,c" checked disabled>'), 'switches are owner-only');`,
`_maState.form.email = null; maEmailToggle('x', true); _owner = true;`,
`_maState.data.overridden = { name: 'env', pronouns: 'config' };`,
`assert.ok(maOverrideNote('name').includes('env') && maOverrideNote('pronouns').includes('custom') && maOverrideNote('voice') === '');`,
`assert.ok(maBehaviourHtml(_maState.form).includes('data-ma-cap="answer_wait_s"'));`,
Expand Down
Loading
Loading