fix: address the email-listing branch review
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
This commit is contained in:
1 parent
b3c5395cfc
commit
4b090083fb
6 files changed
+22
-6
No files matched your search
+3
-3
@@ -69,14 +69,14 @@ The Service names matter:
|
|||||||
read -rs PW; printf '%s' "$PW" | docker run --rm -i httpd:2.4-alpine htpasswd -inBC 10 "" | tr -d ':\n'; unset PW
|
read -rs PW; printf '%s' "$PW" | docker run --rm -i httpd:2.4-alpine htpasswd -inBC 10 "" | tr -d ':\n'; unset PW
|
||||||
```
|
```
|
||||||
|
|
||||||
|
After running `04`, `SELECT LENGTH(password) FROM \`service-system\`.\`user\` WHERE id = 1;` must return 60. The administrator signs in as `admin` and must set a new password before anything else.
|
||||||
|
|
||||||
**Later SQL, after the package, in this order:**
|
**Later SQL, after the package, in this order:**
|
||||||
|
|
||||||
| File | What it does |
|
| File | What it does |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `openspec/changes/archive/2026-11-30-add-admin-email-listing/sql/01-email-module.sql` | Adds the Emails back-office module (`BO_EMAILS`). |
|
| `openspec/changes/archive/2026-11-30-add-admin-email-listing/sql/01-email-module.sql` | Adds the Emails back-office module (`BO_EMAILS`). |
|
||||||
|
|
||||||
After running `04`, `SELECT LENGTH(password) FROM \`service-system\`.\`user\` WHERE id = 1;` must return 60. The administrator signs in as `admin` and must set a new password before anything else.
|
|
||||||
|
|
||||||
**Database user:**
|
**Database user:**
|
||||||
- Create one user with `SELECT, INSERT, UPDATE, DELETE, EXECUTE` on the five schemas. EXECUTE is needed: service-member calls a stored function.
|
- Create one user with `SELECT, INSERT, UPDATE, DELETE, EXECUTE` on the five schemas. EXECUTE is needed: service-member calls a stored function.
|
||||||
- Every Java service reads the same variables (section 6): `MYSQLHOST`, `MYSQLPORT`, `MYSQLUSER`, `MYSQLPWD`.
|
- Every Java service reads the same variables (section 6): `MYSQLHOST`, `MYSQLPORT`, `MYSQLUSER`, `MYSQLPWD`.
|
||||||
@@ -263,7 +263,7 @@ data:
|
|||||||
|
|
||||||
## 10. Known gaps at go-live
|
## 10. Known gaps at go-live
|
||||||
|
|
||||||
- **No email provider yet.** Staff onboarding does not need one: the admin types each new user's first password, and "Set temporary password" on a user's page unlocks a user who forgot theirs. Both force a password change at the next sign-in. Forgot-password and "Send password reset" still create an email with a temporary password. Nobody receives it, but `service-email` saves every email first, so a super admin (or a role granted Emails) can read it under **Emails** and pass the password on in person. The user must change it at the next sign-in. Grant Emails narrowly: it shows every saved email, including other users' temporary passwords.
|
- **No email provider yet.** Staff onboarding does not need one: the admin types each new user's first password, and "Set temporary password" on a user's page unlocks a user who forgot theirs. Both force a password change at the next sign-in. Forgot-password and "Send password reset" still create an email with a temporary password. Nobody receives it, but `service-email` saves every email first, so a super admin (or a role granted Emails) can read it under **Emails** and pass the password on in person. The user must change it at the next sign-in. Grant Emails narrowly: it shows every saved email, including other users' temporary passwords, member email-verification codes, and contact or distributor form submissions with the sender's personal data.
|
||||||
- **Reference data from Tastefully.** It still holds some Tastefully business text (message templates with a phone number, bank account and form links; a public image bucket URL; Tastefully usernames in audit columns). Review it before go-live.
|
- **Reference data from Tastefully.** It still holds some Tastefully business text (message templates with a phone number, bank account and form links; a public image bucket URL; Tastefully usernames in audit columns). Review it before go-live.
|
||||||
- **Other Tastefully defaults.** The sender addresses in `service-email` and the `CUSTOMER_PORTAL_BASE_URL` fallback point at Tastefully. Override them as described in section 6.
|
- **Other Tastefully defaults.** The sender addresses in `service-email` and the `CUSTOMER_PORTAL_BASE_URL` fallback point at Tastefully. Override them as described in section 6.
|
||||||
- **Leaked SMS key.** An SMS360 API key from Tastefully was in `service-email`'s config and is in git history. It has been removed from the config, but it must be rotated with SMS360 before go-live, by whoever owns that Tastefully account.
|
- **Leaked SMS key.** An SMS360 API key from Tastefully was in `service-email`'s config and is in git history. It has been removed from the config, but it must be rotated with SMS360 before go-live, by whoever owns that Tastefully account.
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
-- Local dev only. Applies the change SQL (company, BO modules) and creates one admin login.
|
-- Local dev only. Applies the change SQL (company, BO modules) and creates one admin login.
|
||||||
-- Admin login: admin / colite-dev-admin (dev password, documented in local/README.md).
|
-- Admin login: admin / colite-dev-admin (dev password, documented in local/README.md).
|
||||||
-- Keep the statements below in step with openspec/changes/*/sql/ (and the archive once archived).
|
-- Keep the statements below in step with openspec/changes/*/sql/ (and the archive once archived).
|
||||||
|
-- The release package (add-release-ci-packaging/sql/03-colite.sql) is frozen; this seed equals that
|
||||||
|
-- package plus the later change SQL listed in docs/deployment.md section 3, plus the dev admin login.
|
||||||
USE `service-system`;
|
USE `service-system`;
|
||||||
|
|
||||||
-- add-admin-auth-users-roles/sql/01-company.sql
|
-- add-admin-auth-users-roles/sql/01-company.sql
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
- `/emails` is a list page following the Lead Listing pattern: filters, a paged table, and newest first. A row opens `/emails/[id]`.
|
- `/emails` is 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.
|
- 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."
|
- A 403 shows "Only a super admin can read this email."
|
||||||
- Proxy routes `app/api/emails/route.ts` and `app/api/emails/[id]/route.ts`.
|
- One read-only catch-all proxy, `app/api/emails/[[...path]]/route.ts`, for the list and the detail.
|
||||||
- Gated by `RequireModule pathname="/emails"`.
|
- Gated by `RequireModule pathname="/emails"`.
|
||||||
3. **Module row** `40900000 BO_EMAILS` (`/emails`, icon `Mail`, parent `BO_ROOT`):
|
3. **Module row** `40900000 BO_EMAILS` (`/emails`, icon `Mail`, parent `BO_ROOT`):
|
||||||
- local seed: added to `local/seed/03-colite.sql`;
|
- local seed: added to `local/seed/03-colite.sql`;
|
||||||
@@ -49,7 +49,8 @@
|
|||||||
## Risks / Trade-offs
|
## Risks / Trade-offs
|
||||||
|
|
||||||
- **Admins with `BO_EMAILS` can 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.
|
- **Admins with `BO_EMAILS` can 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.
|
||||||
- **Member emails** (customer portal) are readable too. They are in the same table and there is no member app yet. Grant `BO_EMAILS` narrowly.
|
- **Every saved email is readable**, not only password emails. That includes member email-verification codes and public form submissions with personal data. Grant `BO_EMAILS` narrowly.
|
||||||
|
- **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 `findByEmail` call per recipient** on detail, only for non-super callers. Password emails have one recipient.
|
- **One `findByEmail` call 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.
|
- **Bodies are HTML from our own templates.** The sandbox stops scripts and styling leaks anyway.
|
||||||
|
|
||||||
|
|||||||
@@ -33,4 +33,5 @@ None.
|
|||||||
- **`solvway-admin-portal`:** the `/emails` list and `/emails/[id]` detail pages, proxy routes, a service and i18n keys.
|
- **`solvway-admin-portal`:** the `/emails` list and `/emails/[id]` detail pages, proxy routes, a service and i18n keys.
|
||||||
- **Database:** one new `module` row, `BO_EMAILS`, in `service-system`. It is added to the local seed (`local/seed/03-colite.sql`), and `sql/01-email-module.sql` in this change gives it to the DBA.
|
- **Database:** one new `module` row, `BO_EMAILS`, in `service-system`. It is added to the local seed (`local/seed/03-colite.sql`), and `sql/01-email-module.sql` in this change gives it to the DBA.
|
||||||
- **Docs:** `docs/deployment.md` lists the new SQL file, and section 10 explains the workaround.
|
- **Docs:** `docs/deployment.md` lists the new SQL file, and section 10 explains the workaround.
|
||||||
|
- **Exposure:** Emails shows every email `service-email` has saved, not only password emails. That includes member email-verification codes and public contact or distributor form submissions with personal data. The module is therefore ungranted by default.
|
||||||
- No new dependency, and no change to service-email.
|
- No new dependency, and no change to service-email.
|
||||||
+5
-1
@@ -16,9 +16,11 @@ import org.springframework.util.StringUtils;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read-only view of the emails service-email has saved, so a temporary password can be passed on while no
|
* Read-only view of the emails service-email has saved, so a temporary password can be passed on while no
|
||||||
@@ -52,7 +54,9 @@ public class AdminEmailService {
|
|||||||
Map<String, Object> out = new LinkedHashMap<>(result == null ? Map.of() : result);
|
Map<String, Object> out = new LinkedHashMap<>(result == null ? Map.of() : result);
|
||||||
List<Map<String, Object>> rows = new ArrayList<>();
|
List<Map<String, Object>> rows = new ArrayList<>();
|
||||||
if (out.get("content") instanceof List<?> content) {
|
if (out.get("content") instanceof List<?> content) {
|
||||||
for (Object item : content) if (item instanceof Map<?, ?> row) rows.add(listRow(row));
|
// service-email's recipient filter is a join, so an email with two matching recipients arrives twice.
|
||||||
|
Set<Object> seen = new HashSet<>();
|
||||||
|
for (Object item : content) if (item instanceof Map<?, ?> row && seen.add(row.get("id"))) rows.add(listRow(row));
|
||||||
}
|
}
|
||||||
out.put("content", rows);
|
out.put("content", rows);
|
||||||
return out;
|
return out;
|
||||||
|
|||||||
+8
@@ -222,4 +222,12 @@ class AdminEmailServiceTest {
|
|||||||
verify(rest).postForEntity(eq(PAGE), any(ParameterizedTypeReference.class), body.capture());
|
verify(rest).postForEntity(eq(PAGE), any(ParameterizedTypeReference.class), body.capture());
|
||||||
assertThat((Map<String, Object>) ((Map<String, Object>) body.getValue()).get("pageableRest")).containsEntry("size", 100);
|
assertThat((Map<String, Object>) ((Map<String, Object>) body.getValue()).get("pageableRest")).containsEntry("size", 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void list_sameEmailTwiceFromTheRecipientJoin_isListedOnce() {
|
||||||
|
when(rest.postForEntity(eq(PAGE), any(ParameterizedTypeReference.class), any()))
|
||||||
|
.thenReturn(ResponseEntity.ok(Map.of("content", List.of(emailRow(7, "a@example.com"), emailRow(7, "a@example.com"), emailRow(6, "b@example.com")))));
|
||||||
|
List<Map<String, Object>> rows = (List<Map<String, Object>>) service.list("example.com", null, null, null, 0, 20).get("content");
|
||||||
|
assertThat(rows).extracting(r -> r.get("id")).containsExactly(7L, 6L);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user