Skip to content

add invitation disabler#20

Merged
microstudi merged 11 commits intomainfrom
add-invitation-disabler
Feb 3, 2026
Merged

add invitation disabler#20
microstudi merged 11 commits intomainfrom
add-invitation-disabler

Conversation

@microstudi
Copy link
Member

  • prevent invitations to being sent
  • readme

Copilot AI review requested due to automatic review settings February 3, 2026 14:14
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 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::DisableInvitationsMailInterceptor plus specs to conditionally block emails with the invitation-instructions header when DISABLE_INVITATIONS is enabled.
  • Expose a new disable_invitations configuration option wired to the DISABLE_INVITATIONS environment variable and register both mail interceptors in the engine initializer.
  • Rename the existing mail interceptor to AllowedRecipientsMailInterceptor and 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 MailInterceptor to AllowedRecipientsMailInterceptor here breaks existing references that still use the old constant and require path (e.g., spec/mailers/mail_interceptor_spec.rb describes MailInterceptor and lib/decidim/pokecode.rb requires "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(", ")}"
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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(", ")}"

Copilot uses AI. Check for mistakes.
Comment on lines 178 to +192
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
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@microstudi microstudi merged commit f122304 into main Feb 3, 2026
9 checks passed
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