Add rate limit mail interceptor with Redis-backed quota tracking#25
Draft
Copilot wants to merge 3 commits into
Draft
Add rate limit mail interceptor with Redis-backed quota tracking#25Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
7 tasks
Agent-Logs-Url: https://github.com/openpoke/decidim-module-pokecode/sessions/822fb58c-dc0b-489e-91f8-937b0dcf12f5 Co-authored-by: microstudi <1401520+microstudi@users.noreply.github.com>
Agent-Logs-Url: https://github.com/openpoke/decidim-module-pokecode/sessions/822fb58c-dc0b-489e-91f8-937b0dcf12f5 Co-authored-by: microstudi <1401520+microstudi@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add rate limit interceptor for emails
Add rate limit mail interceptor with Redis-backed quota tracking
May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds daily and monthly email sending quotas enforced via an ActionMailer interceptor, with quota state stored in Redis and an event hook for subscribers.
Configuration
Two new ENV vars control the limits (either or both can be set):
ACTION_MAILER_MAX_EMAILS_PER_DAYACTION_MAILER_MAX_EMAILS_PER_MONTHThe interceptor is only registered when at least one limit is configured.
New components
RateLimitMailInterceptor— checks Redis quota before each delivery; blocks the email (perform_deliveries = false), logs aWARN, and publishes anActiveSupport::Notificationsevent when a limit is hit:MailQuota— Redis model wrapping the quota counters. Keys are scoped by date (decidim:pokecode:mail_quota:daily:YYYY-MM-DD) and month (…:monthly:YYYY-MM) withEXPIREATset to end-of-period so they self-clean. Exposesdaily_count,monthly_count, andincrement!(atomic viaMULTI). Uses a class-level shared Redis connection fromREDIS_URL.Behavior
Daily limit is checked first; if clear, monthly is checked. Quota is only incremented when delivery proceeds.