Conversation
microstudi
commented
Feb 3, 2026
- prevent invitations to being sent
- readme
There was a problem hiding this comment.
Pull request overview
This PR introduces a configurable mail interceptor to prevent invitation emails from being sent, and aligns the existing “allowed recipients” interceptor and documentation with this behavior.
Changes:
- Add
Decidim::Pokecode::DisableInvitationsMailInterceptorplus specs to conditionally block emails with theinvitation-instructionsheader whenDISABLE_INVITATIONSis enabled. - Expose a new
disable_invitationsconfiguration option wired to theDISABLE_INVITATIONSenvironment variable and register both mail interceptors in the engine initializer. - Rename the existing mail interceptor to
AllowedRecipientsMailInterceptorand update README documentation around email-related configuration.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| app/mailers/decidim/pokecode/disable_invitations_mail_interceptor.rb | Adds the interceptor that checks Decidim::Pokecode.disable_invitations and blocks invitation emails based on the invitation-instructions header. |
| spec/mailers/disable_invitations_mail_interceptor_spec.rb | Introduces unit tests covering behavior when invitations are disabled/enabled and when the invitation header is present/absent. |
| app/mailers/decidim/pokecode/allowed_recipients_mail_interceptor.rb | Renames the mail interceptor class to AllowedRecipientsMailInterceptor while keeping the allowed-recipients filtering behavior. |
| lib/decidim/pokecode/engine.rb | Changes the mail interceptor initializer to register the new and renamed interceptors via ActionMailer::Base.register_interceptor based on configuration flags. |
| lib/decidim/pokecode/configuration.rb | Adds the disable_invitations config accessor backed by the DISABLE_INVITATIONS environment variable. |
| README.md | Documents the new DISABLE_INVITATIONS flag and its effect on invitation email delivery. |
Comments suppressed due to low confidence (1)
app/mailers/decidim/pokecode/allowed_recipients_mail_interceptor.rb:7
- Renaming the class from
MailInterceptortoAllowedRecipientsMailInterceptorhere breaks existing references that still use the old constant and require path (e.g.,spec/mailers/mail_interceptor_spec.rbdescribesMailInterceptorandlib/decidim/pokecode.rbrequires"decidim/pokecode/mail_interceptor"). To keep things working, either update all callers/tests and require paths to the new name or provide a backwards-compatible alias so both the old and new constant names resolve correctly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # Check if this is an invitation email | ||
| if message["invitation-instructions"].present? | ||
| Rails.logger.info "[Decidim::Pokecode] Invitation email prevented. Instructions: #{message["invitation-instructions"]}, To: #{message.to.join(", ")}" |
There was a problem hiding this comment.
The string interpolation in this log line uses double quotes both for the surrounding string and inside the #{...} block (message["invitation-instructions"]), which will cause a Ruby syntax error and prevent the file from loading. Please change the interpolation to avoid nested unescaped double quotes (for example by using a local variable or single-quoted key access) so the interceptor class is syntactically valid.
| Rails.logger.info "[Decidim::Pokecode] Invitation email prevented. Instructions: #{message["invitation-instructions"]}, To: #{message.to.join(", ")}" | |
| Rails.logger.info "[Decidim::Pokecode] Invitation email prevented. Instructions: #{message['invitation-instructions']}, To: #{message.to.join(", ")}" |
| initializer "pokecode.mail_interceptor" do | ||
| if Decidim::Pokecode.allowed_recipients_list.any? | ||
| config.action_mailer.interceptors ||= [] | ||
| config.action_mailer.interceptors << "Decidim::Pokecode::MailInterceptor" | ||
| Rails.logger.info "[Decidim::Pokecode] Email interceptor enabled. Allowed recipients: #{Decidim::Pokecode.allowed_recipients_list.join(", ")}" | ||
| else | ||
| Rails.logger.info "[Decidim::Pokecode] Email interceptor disabled." | ||
| Rails.application.config.to_prepare do | ||
| if Decidim::Pokecode.allowed_recipients_list.any? | ||
| ActionMailer::Base.register_interceptor(Decidim::Pokecode::AllowedRecipientsMailInterceptor) | ||
| Rails.logger.info "[Decidim::Pokecode] Allowed recipients mail interceptor enabled. Allowed recipients: #{Decidim::Pokecode.allowed_recipients_list.join(", ")}" | ||
| else | ||
| Rails.logger.info "[Decidim::Pokecode] Allowed recipients mail interceptor disabled." | ||
| end | ||
|
|
||
| if Decidim::Pokecode.disable_invitations | ||
| ActionMailer::Base.register_interceptor(Decidim::Pokecode::DisableInvitationsMailInterceptor) | ||
| Rails.logger.info "[Decidim::Pokecode] Invitations disabled via mail interceptor." | ||
| else | ||
| Rails.logger.info "[Decidim::Pokecode] Invitations not disabled via mail interceptor." | ||
| end |
There was a problem hiding this comment.
Because this logic is wrapped in Rails.application.config.to_prepare, ActionMailer::Base.register_interceptor will be called on every code reload in development/test, causing the same interceptor classes to be registered multiple times and their delivering_email hooks to run repeatedly for a single email. Consider guarding registration (e.g., only registering if not already present or clearing/rebuilding the interceptor list) so the interceptor chain remains idempotent across reloads.