Skip to content

add system account, evaluate limit per pool per account, add/fix tests#597

Open
mabiede wants to merge 7 commits intomainfrom
feature/2452-email-limitations
Open

add system account, evaluate limit per pool per account, add/fix tests#597
mabiede wants to merge 7 commits intomainfrom
feature/2452-email-limitations

Conversation

@mabiede
Copy link
Contributor

@mabiede mabiede commented Mar 13, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 13, 2026 15:25
@mabiede mabiede self-assigned this Mar 13, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces support for a dedicated SMTP system account and per-SMTP invitation capacity limiting, while also refactoring “message template labels” into a shared Pool_common.MessageTemplateLabel type used consistently across the web UI, queue payloads, email/text jobs, and message-template APIs.

Changes:

  • Add new SMTP account attributes (system_account, internal_regex, rate_limit, invitation_capacity) + DB migration, and update email dispatch to resolve a “system SMTP” for selected templates.
  • Add a new system setting + admin UI/handler command to configure which templates are sent using the SMTP system account.
  • Update matcher to compute invitation sending limits per tenant and per SMTP account, and update tests + APIs for the matcher and message-template label refactor.

Reviewed changes

Copilot reviewed 73 out of 73 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pool/web/view/page/page_admin_settings.ml Adds admin settings UI section for “system email templates”.
pool/web/view/page/page_admin_session.ml Switches session admin pages to Pool_common.MessageTemplateLabel APIs.
pool/web/view/page/page_admin_queue.ml Displays queue instance template using MessageTemplateLabel.to_human.
pool/web/view/page/page_admin_message_template.ml Updates template URLs/titles to use shared label type.
pool/web/view/page/page_admin_experiments.ml Updates experiment pages to use shared label type + filtering logic.
pool/web/view/page/page_admin_assignments.ml Updates assignment template label references.
pool/web/view/component/component_message_text_elements.ml Updates message-template help/hints to shared label module.
pool/web/view/component/button.ml Updates “Add template” button label rendering.
pool/web/utils/http_utils_url.ml Uses shared label serialization for admin message-template URLs.
pool/web/handler/admin_settings.ml Loads/saves system_email_templates setting via new command.
pool/web/handler/admin_session.ml Migrates label references + simplifies reminder routes to shared label type.
pool/web/handler/admin_message_templates.ml Changes template label parsing/types to shared label type.
pool/web/handler/admin_experiments_message_templates.ml Updates form context label type.
pool/web/handler/admin_experiments_assignments.ml Updates label usage when finding templates.
pool/web/handler/admin_experiments.ml Uses new customizable label list + shared labels.
pool/test/test_utils.ml Updates test fixture defaults for new shared label type.
pool/test/tenant_test.ml Extends SMTP test data with system/rate-limit/capacity fields.
pool/test/statistics_test.ml Updates matcher helper usage to new matcher API.
pool/test/smtp_test.ml Extends SMTP tests for new fields; asserts event payload contains new values.
pool/test/message_template_test.ml Migrates tests to shared label type.
pool/test/message_mapping.ml Migrates mapping assertions to shared label type.
pool/test/matcher_test.ml Updates matcher API usage; adds tests for different contact user states.
pool/test/integration.ml Adds new matcher-related integration test cases.
pool/test/contact_test.ml Updates email dispatch creation to pass label type (not string).
pool/test/assignment_test.ml Updates email dispatch creation to pass label type (not string).
pool/routes/routes.ml Updates route builders to use shared label module.
pool/pool_queue/repo_entity.ml Changes stored queue instance message_template type to shared label repo type.
pool/pool_queue/pool_queue.mli Updates queue public API to accept/return shared label type.
pool/pool_queue/entity.ml Updates queue instance entity type for message_template.
pool/pool_message/pool_message_error.ml Adds SmtpRecipientNotFound error variant.
pool/pool_message/field.mli Adds new SMTP-related field variants.
pool/pool_message/field.ml Adds new SMTP-related field variants + printers/serializers.
pool/matcher/matcher.mli Simplifies matcher APIs to single-tenant calls; updates return types.
pool/matcher/matcher.ml Implements per-tenant/per-SMTP capacity limiting + per-tenant scheduling.
pool/matcher/dune Adds email dependency + ppx_string for schedule naming.
pool/cqrs_command/smtp_command.ml Extends SMTP create/update commands + schemas with new fields.
pool/cqrs_command/settings_command.ml Adds UpdateSystemEmailTemplates command to persist new setting.
pool/cqrs_command/message_template_command.ml Changes create API to shared label type.
pool/command/command_matcher.ml Updates CLI matcher commands for new matcher API (single tenant).
pool/app/text_message/text_message.mli Changes message_template fields/args to shared label type.
pool/app/text_message/event.ml Changes serialized job message_template type to shared label type.
pool/app/settings/settings.mli Adds SystemEmailTemplates setting key/event + find API.
pool/app/settings/settings.ml Implements find_system_email_templates using repo + normalization.
pool/app/settings/repo/repo.ml Adds repo for SystemEmailTemplates; hardens JSON decode error handling.
pool/app/settings/event.ml Persists SystemEmailTemplatesUpdated via repo update.
pool/app/settings/entity.ml Defines SystemEmailTemplates type + normalize + action wiring.
pool/app/pool_database/tenant.ml Adds new tenant migrations to migration step list.
pool/app/pool_database/root.ml Adds new root migration to migration step list.
pool/app/pool_database/migrations/migration_202603131200.ml Seeds default system_email_templates system setting.
pool/app/pool_database/migrations/migration_202603061300.ml Adds SMTP columns: system_account/internal_regex/rate_limit/invitation_capacity.
pool/app/pool_common/repo.ml Adds caqti selector type for MessageTemplateLabel.
pool/app/pool_common/pool_common.mli Introduces shared MessageTemplateLabel type in public interface.
pool/app/pool_common/locales/locales_en.ml Adds new SMTP field strings + new error string.
pool/app/pool_common/locales/locales_de.ml Adds new SMTP field strings + new error string.
pool/app/pool_common/entity.ml Implements Pool_common.MessageTemplateLabel selector type + helpers.
pool/app/pool_common/dune Reorders/adds preprocessors for new shared label type.
pool/app/message_template/repo/repo_sql.ml Switches DB queries to typed label/uuid caqti parameters.
pool/app/message_template/repo/repo_entity.ml Switches repo entity label caqti type to shared label repo type.
pool/app/message_template/message_template.mli Removes Message_template.Label; uses shared label + exposes customizable labels.
pool/app/message_template/message_template.ml Uses shared label throughout + defines customizable labels list.
pool/app/message_template/entity.ml Uses shared label for template entity + URL/hint helpers.
pool/app/message_template/default/locales/default_en.ml Updates default templates to shared label type.
pool/app/message_template/default/locales/default_de.ml Updates default templates to shared label type.
pool/app/email/repo/repo_sql.ml Extends SMTP SQL + adds system/default lookup + invitation counting query.
pool/app/email/repo/repo_entity_smtp_auth.ml Extends SMTP caqti codecs for new SMTP fields.
pool/app/email/repo/repo.ml Exposes new repo functions (find_for_experiment, count_invitations_sent_since).
pool/app/email/event.ml Changes serialized dispatch message_template type to shared label type.
pool/app/email/entity_smtp.ml Adds SMTP fields + defaults + schemas for new SMTP properties.
pool/app/email/email_service.ml Adds system-template SMTP resolution + bounce handling improvements.
pool/app/email/email.mli Extends SMTP API + changes message_template types + exposes bounce helpers.
pool/app/email/email.ml Exposes Email.Contact helpers.
pool/app/contact/repo/repo.ml Re-exports smtp-bounce increment through contact repo.
pool/app/contact/dune Adds email dependency for contact repo integration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the messaging/email infrastructure by introducing a dedicated “system” SMTP account and a configurable list of “system email templates” that should use it, while also changing invitation matcher throttling to respect per-SMTP-account limits (per pool) and migrating message template labels to a shared Pool_common.MessageTemplateLabel type across the app.

Changes:

  • Add SMTP fields (system_account, internal_regex, rate_limit, invitation_capacity) and update matcher to compute invitation limits per pool and per SMTP account based on recent sending volume.
  • Add “System email templates” setting in admin settings; dispatch uses system SMTP for selected templates (fallback to default SMTP).
  • Migrate message template labels from Message_template.Label to Pool_common.MessageTemplateLabel across web/UI, queue, email, SMS, repos, and tests.

Reviewed changes

Copilot reviewed 84 out of 85 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pool/cqrs_command/smtp_command.ml Extends SMTP create/update schemas for new SMTP fields.
pool/app/email/email_service.ml Resolves system SMTP for selected templates; adds bounce tracking behavior.
pool/matcher/matcher.ml / pool/matcher/matcher.mli Refactors matcher API and implements per-pool/per-SMTP throttling logic.
pool/app/pool_database/migrations/migration_202603061300.ml Adds new SMTP columns for system account + throttling configuration.
pool/app/pool_database/migrations/migration_202603131200.ml Seeds new system setting for system email templates.
pool/web/view/page/page_admin_settings.ml Adds UI for selecting system email templates.
pool/web/view/page/page_admin_settings_smtp.ml Adds UI fields for system SMTP flag + rate limiting configuration.
pool/app/pool_common/entity.ml and related usages Introduces/uses shared Pool_common.MessageTemplateLabel throughout.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

let%lwt () =
increment_smtp_bounce label (Pool_user.EmailAddress.of_string recipient)
in
Lwt.return_error (Pool_message.Error.SmtpRecipientNotFound recipient)
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.

2 participants