Skip to content

feat(openregister): build send-at-on-the-messaging-leaf (sweep audit, e-mail channel) - #10534

Open
rubenvdlinde wants to merge 2 commits into
mainfrom
build/send-at-on-the-messaging-leaf-3
Open

rubenvdlinde wants to merge 2 commits into
mainfrom
build/send-at-on-the-messaging-leaf-3

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

Summary

Third pass of openspec/changes/send-at-on-the-messaging-leaf. The first two passes are merged, the second in #10455.

  • Finishes 2.2. The scheduled sweep now writes a send entry and a fail entry on the object a scheduled message is bound to.
  • Builds the OpenRegister side of the e-mail channel (1.1). smtp-mail is an allowed source, and POST /api/integrations/email/send sends now or at sendAt. Every message gets a minted Message-ID, which is returned and later stored by the sweep.

Changes

  • lib/Notifications/Service/Notification/ScheduledMessageAudit.php (new) writes two audit entries:

    • message.sent, with the Message-ID;
    • message.failed, with the cause, the attempt number and whether the message is now parked.

    The sweep runs without a user, so the object is read by uuid with RBAC and multitenancy off. Whether to write an entry is decided only by the stored row: nothing reaches a response. A message with no bound object writes nothing. If the object is gone or the write fails, it is logged and never fails the sweep.

  • ScheduledMessageSweep calls the audit after each send and each failure. The audit is a nullable last constructor argument, so existing construction is unchanged. A sent message now stores the Message-ID the channel answered with, falling back to the stored one.

  • MessageDispatchProvider:

    • adds smtp-mail to ALLOWED_SOURCES;
    • answers a sent message with the Message-ID header it left with (messageId);
    • leaves results unchanged for SMS, WhatsApp and failed sends.
  • lib/Service/Integration/Providers/MessageIdMinter.php (new) mints <128 random bits as hex@host>. It drops a port, and falls back to openregister.invalid for anything that is not a host name, so a crafted Host header cannot inject header text.

  • MessageDispatchController::emailSend() and its route POST /api/integrations/email/send (#[NoAdminRequired], like the SMS and WhatsApp sends):

    • takes {to, subject, text, html?, replyTo?}, plus the optional path, sendAt and object;
    • to is one address or a list, each validated;
    • answers 400 naming the field that is missing or malformed;
    • answers 503 with details.cause for a degraded source;
    • a scheduled e-mail answers 202 with its messageId and stores the header;
    • scheduleSend() can now take a composed message instead of reading body and headers from the request.
  • tasks.md: 2.2 is ticked. 1.1 and 3.2 get notes on what is built and what is left.

  • scripts/component-map.csv: one row per new lib file.

Not in this PR:

  • Seeding the smtp-mail source itself. It is a register fragment in integriq, where cmcom-sms and the other sources are seeded.
  • 3.1 (Playwright) and Newman for the routes, which need a running instance.

Test Coverage

  • tests/Unit/Controller/MessageDispatchEmailTest.php (14 tests):
    • send through smtp-mail with a minted Message-ID that is returned;
    • every message gets its own Message-ID;
    • several recipients and a path;
    • eight malformed inputs (400, nothing sent or scheduled);
    • 503 with its cause;
    • a scheduled e-mail stores the header and answers with it;
    • a past sendAt is refused.
  • tests/Unit/Service/Integration/Providers/MessageIdMinterTest.php (8 tests): format, port dropped, uniqueness, and fallback for an empty host, an IPv6 literal, header injection, a space and a leading dash.
  • tests/Unit/Notifications/Service/Notification/ScheduledMessageAuditTest.php (5 tests):
    • a sent entry, with the object read without a user;
    • a failure entry, both still pending and parked;
    • an unbound message writes nothing;
    • a gone object and a failed write are logged.
  • ScheduledMessageSweepTest (+2): a sent message is audited with the channel's Message-ID, and failures are audited with their outcome.
  • MessageDispatchProviderTest (+2, and the pinned source list now includes smtp-mail): a sent e-mail answers with its Message-ID; an SMS without one, or an e-mail that did not leave, answers as before.
  • Break checks: with one line broken in MessageIdMinter, 6 of 8 tests fail. Reading the object with RBAC on in ScheduledMessageAudit fails its test.

Runs (phpunit-unit-local.xml, main against this branch):

Folder main this branch
Controller 10192 tests, 12 errors 10206 tests, the same 12 errors
Notifications 634 tests, 9 failures 641 tests, the same 9 failures
Service/Integration 724 OK 734 OK
BackgroundJob 815 OK 815 OK

Contract, Service/Rules and Settings are OK on both. The existing errors and failures come from this environment (no Nextcloud server) and match main by name.

Not run: tests/Unit/Architecture, which does not finish here within 280 s, and the whole suite.

Quality checklist

  • composer check:strict was not run as a whole. On the changed lib files:
    • phpcs: no errors.
    • phpstan: no new findings. The one left, an unused REQUIRED_APP constant in the provider, is already on main.
  • Hydra gates: not run.
  • New lib/**/*.php classes have a matching test (MessageIdMinterTest, ScheduledMessageAuditTest).
  • Burn-down PR: n/a.

Generated by Claude Code

Tasks 2.2 (finished) and 1.1 / 3.2 (the OpenRegister side).

- The sweep writes the send and fail entries on a scheduled message's
  bound object (ScheduledMessageAudit): message.sent with the Message-ID,
  message.failed with the cause, the attempt and whether it is parked. The
  object is read by uuid without a user; an unbound message writes nothing,
  and a gone object or a failed write is logged, never failing the sweep.
- E-mail channel: smtp-mail joins the allowed sources and
  POST /api/integrations/email/send takes {to, subject, text, html?,
  replyTo?} (plus path, sendAt, object), sends now or schedules, answers
  400 for a malformed field and 503 with details.cause for a degraded
  source. Every message gets a Message-ID (MessageIdMinter), sent as its
  header and returned; the provider answers a sent message with it and the
  sweep stores the channel's own Message-ID.

Seeding the smtp-mail source is integriq's (where the other sources are
seeded); 3.1 (e2e) and Newman are left.

Assisted-by: ClaudeCode:claude-opus-5-5
Task 1.1 is complete: the smtp-mail source seed is in integriq
(ConductionNL/integriq#3632).

Assisted-by: ClaudeCode:claude-opus-5-5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant