* feat(teams): invite members by email + seed Forschung & Entwicklung team Team onboarding gets a full email-invite flow, unified on the existing placeholder-claim mechanism (one path, no parallel invitation table): - Invite by name + email on the team page (super admin): registered staff are added directly and notified; unknown addresses get a placeholder account with the membership plus a claim link (14d, single-use) by email (POST /api/admin/teams/[id]/invitations) - Placeholder "Einladen" can now send the claim link by email (optional address field) instead of clipboard-only delivery - Claim page prefills the email field from the delivery address - Direct member-add notifies the person by email (self-join stays silent) - New templates teamClaimInvite / teamMemberAdded (Swiss German, escaped) - Migration 132 seeds the Forschung & Entwicklung team with Georgy as lead - Docs: EMAILS.md trigger table gains the Teams rows Tests: 18 new (templates + schemas); typecheck, lint, lint:umlauts clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN * fix(ci): repair inherited E2E breakage — seed columns + moved admin route Both failures predate this branch (main's last five CI runs fail the same two jobs): - e2e-seed.ts still wrote technician_profiles.is_verified / verification_date, dropped in migration 122 (identity moved to user_profiles in 121). Seed now sets the verified flag on user_profiles, keeping the "verified technician" premise. - inventory-routes.ts pointed at /admin/repairer-applications — the one hardcoded path in the list, which drifted when the section moved. Now uses ROUTES.admin.hrApplications (config-driven like every other row). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN * fix(db): recreate ensure_seller_profile() without dropped display_name Migration 122 dropped seller_profiles.display_name but the trigger function from 031 still inserted it, so the first listing insert of any user without a seller_profiles row errored — surfaced by the E2E seed, and a live bug for new P2P sellers. Migration 133 recreates the function inserting only user_id (identity lives on user_profiles since 121). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN * fix(e2e): first() on assertions whose text legitimately renders twice Timecard submit ("Zur Prüfung gesendet" in status banner + summary line), tasks empty state, and blog body/excerpt all resolve to two elements, tripping Playwright strict mode — timecard failed every retry, the other two were flaky. Assert on .first(); either occurrence being visible is what the journeys actually verify. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN * fix(timecards): race-safe draft creation + stale E2E heading assertion Two concurrent first-hits of GET /api/timecards for the same user+period both passed the existence check and raced the UNIQUE(user_id, period_start, period_end) insert — the loser 500'd ("Zeitkarte konnte nicht geladen werden"). Insert now uses ON CONFLICT DO NOTHING and serves the row the winner created. The timecard journey also asserted a "Zeitkarten" heading on /admin/zeiterfassung — that page's H1 is "Zeiterfassung" (the Zeitkarten approval queue moved to its own page). Assert the real heading. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Akm86ZwqhiSM2BfdKH96cN --------- Co-authored-by: Claude <noreply@anthropic.com>
8.0 KiB
Emails & Notifications — SSOT
What gets an email/notification, when, and to whom. Keep this in sync when you add or change any createNotification / notifyUsers / notifyAllStaff / sendCustomEmail call.
Last updated: 2026-07-15.
How it works — two dispatch paths
Path A — Notification system (src/lib/services/notifications.ts)
createNotification(userId, payload, opts?) · notifyUsers(userIds, payload) · notifyAllStaff(payload, excludeUserId?) each write an in-app notification row (the bell) and send an email via trySendEmail to every recipient whose user_profiles.email_notifications !== false (default true).
- Email body:
getEmailContent(payload)uses a dedicated template fordecision_*,it_hilfe_*(whenmetadata.requestUrlset), andcontent_submission_status(whenmetadata.actionset); everything else falls back to the genericnotificationEmail(title, content). opts.skipEmail: true→ in-app row only, no email. Use when a dedicated styled email is already sent for the event via Path B (avoids a second generic email, and still gives a bell entry that survives email-deliverability drops).
Path B — Direct email (sendCustomEmail / sendEmail)
Inline from routes. No in-app row, always a dedicated template. Used by marketplace orders, listing publish/question, appointments, workshops, HR, IT-Hilfe admin alerts.
Central dispatcher for workflow events (timecards, time-off, permissions): src/lib/lifecycle/dispatch.ts.
Recipient resolution helpers: getTimecardApproverIds(excludeUserId?) (staff with timecards/* permission or super-admin), notifyAllStaff, resolveEligibleUserIds (decisions).
Deliverability caveat (READ THIS)
Prod sends via Brevo. If the revampit.ch sending domain isn't SPF/DKIM-authenticated, Brevo accepts + queues the mail but Gmail/consumer mailboxes silently drop it. So an email being "sent" ≠ delivered.
- Most at risk — external recipients: IT-Hilfe requesters + community technicians, marketplace buyers + P2P sellers, job applicants, workshop registrants, service-appointment customers, paying members.
- Lower risk — internal
@revamp-it.ch: all staff-facing notifications (timecards, time-off, decisions, tasks, admin alerts). - Mitigation in code: prefer an in-app notification (Path A, bell) for anything the user must not miss, so it lands regardless of email. The DNS fix (authenticate
revampit.chin Brevo + SPF/DKIM/DMARC records) is a separate ops task and is the real fix for external delivery.
Trigger table
Legend: A = notification system (in-app + maybe email) · B = direct email only · A(skipEmail) = in-app only.
| Event | Path | Recipients | Emails? |
|---|---|---|---|
| Decisions | |||
| Voting opens | A | eligible voters − opener | ✓ |
| Decision closed (manual / cron) | A | creator / all staff | ✓ |
| Voting deadline ~24h | A | non-voters | ✓ |
| Protocols | |||
| Protocol finalized | A | attendees | ✓ (generic) |
| IT-Hilfe | |||
| Request created → requester | A | requester | ✓ |
| Request created → admin alert | B | shared inbox | ✓ |
| Request created → preferred / matching techs | A | preferred + skill-matched active techs | ✓ |
| New offer | A | request owner | ✓ |
| Offer accepted / rejected / declined | A | the helper(s) | ✓ |
| Request completed / review received | A | requester / reviewed helper | ✓ |
| Marketplace | |||
| Order placed → buyer | B | buyer | ✓ |
| Order placed → seller | B + A(skipEmail) | seller (styled email + bell entry) | ✓ |
| Cart paid (webhook) | B | buyer + seller | ✓ |
| Listing published | B | seller | ✓ |
| Question / receipt-confirmed / review | A + B | seller (⚠ double email, see follow-ups) | ✓✓ |
| Membership | |||
| Payment recorded | A | the member | ✓ (generic) |
| Workshops | |||
| Free registration | B + A | registrant (email) + all staff (in-app) | ✓ |
| Proposal approved | A | proposer | ✓ |
| Service appointments | |||
| Booking → admins | A + B | all staff + shared inbox (if unassigned) | ✓ |
| Booking → assigned repairer | A | the repairer | ✓ |
| Booking → customer | A | the customer (in-app + generic email) | ✓ |
| Quote/accept/reject/start/complete | B | customer / repairer | ✓ |
| Completed → staff | A | all staff − actor | ✓ |
| Timecards | |||
| Submitted → other approvers | A | approvers − submitter | ✓ |
| Submitted → submitter | A (timecard_submit_confirmed) |
the submitter (also "you can approve it yourself" when sole approver) | ✓ |
| Approved / rejected / reopened / edited | A | card owner | ✓ |
| Time-off | |||
| Submitted → approvers | A | approvers | ✓ |
| Reviewed → requester | A | requester | ✓ |
| Permissions | |||
| Access requested / reviewed | A | super admins / requester | ✓ |
| HR | |||
| Application → staff / applicant | A + B | all staff (in-app) + applicant (email) | ✓ |
| Status changed | A/B | applicant | ✓ |
| Blog | |||
| Status change | A + B | submitter | ✓ |
| Tasks | |||
| Assigned / requested / completed / accepted / recurring | A | assignee / requester / creator / staff | ✓ |
| Teams | |||
| Invited by email (new person / placeholder) | B (teamClaimInvite) |
the invitee's real address (claim link, 14d) | ✓ |
| Added to a team by an admin | B (teamMemberAdded) |
the added member (self-join stays silent) | ✓ |
Fixed 2026-07-09 (commit trail in git)
- Timecard submitted → submitter now gets a confirmation (
timecard_submit_confirmed), and when the submitter is the sole approver it also tells them they can approve it themselves. Previously the submitter got nothing, and a sole-super-admin approver submitting their own card notified nobody (getTimecardApproverIdsexcludes the submitter). —src/lib/services/timecards.ts - Order placed → seller now gets an in-app bell entry (
listing_sold,skipEmailso no duplicate of the styled email). Robust against email drops. NewRELATED_TYPES.ORDER→/dashboard/orders/. —src/app/api/marketplace/orders/route.ts - Service booking → customer now acknowledged (in-app + generic email) at booking time. Previously only admins + the assigned repairer were notified. —
src/app/api/appointments/route.ts createNotificationgainedopts.skipEmailfor in-app-only notifications.
Known follow-ups (NOT yet done)
- Paid workshop registration (webhook) sends no confirmation —
src/lib/services/payment-webhook.ts:451only logs. Fix: sendworkshopRegistrationConfirmationon payment success. (Deferred: the Payrexx-paid path isn't live/testable yet.) - Paid service appointment (webhook) sends no confirmation —
payment-webhook.ts:457only logs. Same deferral. - ✅ DONE — Marketplace double emails fixed: the seller
createNotificationin the question (listings/[id]/questions), confirm-receipt and review routes now pass{ skipEmail: true }, so only the dedicated styled email is sent (the bell entry stays). - ✅ DONE — Time-off requester acknowledgement added:
createTimeOffRequestnow sends the requester an in-apptime_off_requestedconfirmation (→/admin/zeiterfassung) at submit time, mirroring the timecard-submit confirmation. - ✅ DONE — SSOT drift fixed: added
NOTIFICATION_TYPES.TASK_ASSIGNEDand both task routes use the constant (the stalenotifications_type_checkDB constraint note in the config was also corrected — it was dropped in migration 110). - ✅ DONE — Dead notification types pruned: removed
message,vacancy_published,marketing,task_broadcastfromNOTIFICATION_TYPES(verified zero producers — nocreateNotification/notifyUsersemits them, and they appear in no label/icon/href map). Keptappointment/marketplace/system(all have producers). - Deliverability: authenticate
revampit.chin Brevo (SPF/DKIM/DMARC) so external emails actually land.