List each email once when the recipient join returns it twice. The proposal, design and handover now say Emails exposes every saved email, including member verification codes and form submissions, not only password emails. The design names the single catch-all proxy, the later-SQL table sits after the 04 check, and the seed header says the release package is frozen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
4.6 KiB
4.6 KiB
Design
Context
- Storage:
service-email's/email/sendsaves the email (subject, body, recipients, status) before it publishes it for sending. Every email is inservice-email.email, with its recipients inrecipient, whether or not a provider delivered it. - Existing queries in service-email:
/email/findByPropertyAndPageabletakes{property, pageableRest}. The supported properties areid,sender,subject,recipient(a join, matched with like) andstartDate/endDate(dd-MM-yyyy, thesystem.dateformatin core-libs)./email/findById/{id}returns the email with its body and recipients, or an empty body when there is none.
- Who sends password emails: services-system's
resetAdminPassword(admin reset and admin forgot-password) and the member password paths. - Access model:
@AdminModuleon mobile-api handlers. A super admin (role id 1) passes every module check and sees every menu entry. The portal menu comes from themoduletable (url,icon_name). - Reference: babyboo's
AdminEmailTemplateController(/email-logs,/email-logs/{id}) andapp/email-templates/logs/[id], which renders the body in an<iframe sandbox srcDoc>.
Goals / Non-Goals
Goals:
- Read saved emails, including temporary passwords, without an email provider.
- No privilege escalation through super admin emails.
Non-Goals:
- Resend.
- Templates, SMS, attachments download, and choosing a provider.
Decisions
- mobile-api
AdminEmailController(@AdminModule("BO_EMAILS"),@AppAuth), backed byAdminEmailService.GET /api/admin/emails?recipient&subject&from&to&page&size- It calls
/email/findByPropertyAndPageablewith only the properties that were given, sorted bydatetimedescending. fromandtoarrive asyyyy-MM-ddand are converted to service-email'sdd-MM-yyyy.- Each row maps to
{id, datetime, recipients: [address], subject, status}. The body is dropped here and never leaves mobile-api in the list.
- It calls
GET /api/admin/emails/{id}- It calls
/email/findById/{id}. An empty body gives 404EMAIL_NOT_FOUND. - If the caller is not a super admin, it checks each recipient address with services-system
/user/findByEmail/{email}. Any recipient that is a type-Auser holding role 1 gives 403SUPER_ADMIN_REQUIRED. - On success it returns
{id, datetime, sender, subject, status, recipients: [{recipient, type}], body}, then logsemail <id> viewed by <username>. - Alternative considered: hide super admin emails from the list. Rejected, because filtering after the query breaks paging, and the subject and recipient carry no secret.
- It calls
- Portal:
/emailsis a list page following the Lead Listing pattern: filters, a paged table, and newest first. A row opens/emails/[id].- The detail page shows the metadata and the body in
<iframe sandbox="" srcDoc={body}>: no scripts and no same-origin access. The body is never put into the page's own DOM. - A 403 shows "Only a super admin can read this email."
- One read-only catch-all proxy,
app/api/emails/[[...path]]/route.ts, for the list and the detail. - Gated by
RequireModule pathname="/emails".
- Module row
40900000 BO_EMAILS(/emails, iconMail, parentBO_ROOT):- local seed: added to
local/seed/03-colite.sql; - real environments:
sql/01-email-module.sqlin this change. - No role grant.
- local seed: added to
- Handover:
docs/deployment.md:- section 3 lists the new SQL file as applied after the release package;
- section 10 says forgot-password and "Send password reset" emails can be read under Emails until a provider is configured.
Risks / Trade-offs
- Admins with
BO_EMAILScan read other users' temporary passwords. That is the purpose. It is limited by the module grant, the super-admin protection and the audit line. The user must still change the password at first sign-in. - Every saved email is readable, not only password emails. That includes member email-verification codes and public form submissions with personal data. Grant
BO_EMAILSnarrowly. - The recipient filter is a join in service-email, so an email with two matching recipients arrives twice. mobile-api lists it once, but the total can still count it twice.
- One
findByEmailcall per recipient on detail, only for non-super callers. Password emails have one recipient. - Bodies are HTML from our own templates. The sandbox stops scripts and styling leaks anyway.
Migration Plan
Run sql/01-email-module.sql on service-system, then deploy mobile-api and the portal. Rollback: the previous images. The extra module row is harmless.