-
Notifications
You must be signed in to change notification settings - Fork 0
add invitation disabler #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a46c474
prevent invitations to being sent
microstudi e1c90f4
readme
microstudi 767f576
remove unnecessary require
microstudi 4bd02a5
fixes
microstudi c589b74
spec name
microstudi 186202e
fix spec
microstudi 9f51cfb
fix spec
microstudi 8d85e03
add specs
microstudi efa807c
rename spec
microstudi 1838f96
configure deface in an initializer
microstudi 7911914
load deface
microstudi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
19 changes: 19 additions & 0 deletions
19
app/mailers/decidim/pokecode/disable_invitations_mail_interceptor.rb
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Decidim | ||
| module Pokecode | ||
| # Email interceptor that prevents invitation emails from being sent. | ||
| # Disables all emails that contain the 'invitation-instructions' header. | ||
| class DisableInvitationsMailInterceptor | ||
| def self.delivering_email(message) | ||
| return unless Decidim::Pokecode.disable_invitations | ||
|
|
||
| # 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(", ")}" | ||
| message.perform_deliveries = false | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
app/views/decidim/pokecode/admin/_invitations_disabled_warning.html.erb
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <div class="callout alert"> | ||
| <p> | ||
| <strong><%= t("decidim.pokecode.invitations_disabled_warning.title") %></strong><br> | ||
| <%= t("decidim.pokecode.invitations_disabled_warning.message") %> | ||
| </p> | ||
| </div> |
File renamed without changes.
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "spec_helper" | ||
|
|
||
| module Decidim::Pokecode | ||
| describe DisableInvitationsMailInterceptor do | ||
| let(:message) do | ||
| instance_double( | ||
| Mail::Message, | ||
| to: ["user@example.com"], | ||
| perform_deliveries: true | ||
| ) | ||
| end | ||
|
|
||
| before do | ||
| allow(Rails.logger).to receive(:info) | ||
| allow(message).to receive(:perform_deliveries=) | ||
| allow(message).to receive(:[]).and_return(nil) | ||
| end | ||
|
|
||
| describe ".delivering_email" do | ||
| context "when disable_invitations is disabled" do | ||
| before do | ||
| allow(Decidim::Pokecode).to receive(:disable_invitations).and_return(false) | ||
| end | ||
|
|
||
| it "does not intercept any emails" do | ||
| allow(message).to receive(:[]).with("invitation-instructions").and_return("invite_private_user") | ||
| described_class.delivering_email(message) | ||
| expect(message).not_to have_received(:perform_deliveries=) | ||
| end | ||
| end | ||
|
|
||
| context "when disable_invitations is enabled" do | ||
| before do | ||
| allow(Decidim::Pokecode).to receive(:disable_invitations).and_return(true) | ||
| end | ||
|
|
||
| context "when the email has an invitation-instructions header" do | ||
| before do | ||
| allow(message).to receive(:[]).with("invitation-instructions").and_return("invite_private_user") | ||
| end | ||
|
|
||
| it "prevents the email from being delivered" do | ||
| described_class.delivering_email(message) | ||
| expect(message).to have_received(:perform_deliveries=).with(false) | ||
| end | ||
|
|
||
| it "logs the interception" do | ||
| described_class.delivering_email(message) | ||
| expect(Rails.logger).to have_received(:info).with( | ||
| include("[Decidim::Pokecode] Invitation email prevented") | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| context "when the email does not have an invitation-instructions header" do | ||
| before do | ||
| allow(message).to receive(:[]).with("invitation-instructions").and_return(nil) | ||
| end | ||
|
|
||
| it "allows the email to be delivered" do | ||
| described_class.delivering_email(message) | ||
| expect(message).not_to have_received(:perform_deliveries=) | ||
| end | ||
|
|
||
| it "does not log the interception" do | ||
| described_class.delivering_email(message) | ||
| expect(Rails.logger).not_to have_received(:info) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
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
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
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.
There was a problem hiding this comment.
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.