Disable dashboard email deliveries
We have to doble check all emails deliveries from the dashboard. Using a setting to skip all dashboard email deliveries for now. Note that a rake task to activated the `Setting["dashboard.emails"]` will need to be addded when we want to activate deliveries of these emails.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
class Dashboard::Mailer < ApplicationMailer
|
class Dashboard::Mailer < ApplicationMailer
|
||||||
layout "mailer"
|
layout "mailer"
|
||||||
|
after_action :check_deliverability
|
||||||
|
|
||||||
def forward(proposal)
|
def forward(proposal)
|
||||||
@proposal = proposal
|
@proposal = proposal
|
||||||
@@ -38,4 +39,9 @@ class Dashboard::Mailer < ApplicationMailer
|
|||||||
def get_new_actions(new_actions_ids)
|
def get_new_actions(new_actions_ids)
|
||||||
Dashboard::Action.where(id: new_actions_ids)
|
Dashboard::Action.where(id: new_actions_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_deliverability
|
||||||
|
mail.perform_deliveries = false unless Setting["dashboard.emails"]
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -82,4 +82,6 @@ section "Creating Settings" do
|
|||||||
Setting.create(key: "proposals.poll_link", value: nil)
|
Setting.create(key: "proposals.poll_link", value: nil)
|
||||||
Setting.create(key: "proposals.email_short_title", value: nil)
|
Setting.create(key: "proposals.email_short_title", value: nil)
|
||||||
Setting.create(key: "proposals.email_description", value: nil)
|
Setting.create(key: "proposals.email_description", value: nil)
|
||||||
|
|
||||||
|
Setting.create(key: "dashboard.emails", value: nil)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -139,5 +139,8 @@ Setting["proposals.email_description"] = nil
|
|||||||
Setting["proposals.poster_short_title"] = nil
|
Setting["proposals.poster_short_title"] = nil
|
||||||
Setting["proposals.poster_description"] = nil
|
Setting["proposals.poster_description"] = nil
|
||||||
|
|
||||||
|
# Dashboard
|
||||||
|
Setting["dashboard.emails"] = nil
|
||||||
|
|
||||||
# Default custom pages
|
# Default custom pages
|
||||||
load Rails.root.join("db", "pages.rb")
|
load Rails.root.join("db", "pages.rb")
|
||||||
|
|||||||
@@ -9,6 +9,44 @@ describe Dashboard::Mailer do
|
|||||||
day_offset: 0,
|
day_offset: 0,
|
||||||
published_proposal: true) }
|
published_proposal: true) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Setting["dashboard.emails"] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
Setting["dashboard.emails"] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#forward" do
|
||||||
|
let!(:proposal) { create(:proposal) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
ActionMailer::Base.deliveries.clear
|
||||||
|
end
|
||||||
|
|
||||||
|
it "Disables email delivery using setting" do
|
||||||
|
Setting["dashboard.emails"] = nil
|
||||||
|
|
||||||
|
Dashboard::Mailer.forward(proposal).deliver_now
|
||||||
|
|
||||||
|
expect(ActionMailer::Base.deliveries.count).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "sends forward email" do
|
||||||
|
Dashboard::Mailer.forward(proposal).deliver_now
|
||||||
|
|
||||||
|
email = open_last_email
|
||||||
|
|
||||||
|
expect(email).to deliver_from("CONSUL <noreply@consul.dev>")
|
||||||
|
expect(email).to deliver_to(proposal.author)
|
||||||
|
expect(email).to have_subject(proposal.title)
|
||||||
|
expect(email).to have_body_text("Support this proposal")
|
||||||
|
expect(email).to have_body_text("Share in")
|
||||||
|
expect(email).to have_body_text(proposal_path(proposal))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
describe "#new_actions_notification rake task" do
|
describe "#new_actions_notification rake task" do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@@ -25,6 +63,16 @@ describe Dashboard::Mailer do
|
|||||||
describe "#new_actions_notification_rake_created" do
|
describe "#new_actions_notification_rake_created" do
|
||||||
let!(:proposal) { create(:proposal, :draft) }
|
let!(:proposal) { create(:proposal, :draft) }
|
||||||
|
|
||||||
|
it "Disables email delivery using setting" do
|
||||||
|
Setting["dashboard.emails"] = nil
|
||||||
|
|
||||||
|
action.update(published_proposal: false)
|
||||||
|
resource.update(published_proposal: false)
|
||||||
|
run_rake_task
|
||||||
|
|
||||||
|
expect(ActionMailer::Base.deliveries.count).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
it "sends emails when detect new actions for draft proposal" do
|
it "sends emails when detect new actions for draft proposal" do
|
||||||
action.update(published_proposal: false)
|
action.update(published_proposal: false)
|
||||||
resource.update(published_proposal: false)
|
resource.update(published_proposal: false)
|
||||||
@@ -60,6 +108,15 @@ describe Dashboard::Mailer do
|
|||||||
describe "#new_actions_notification_rake_published" do
|
describe "#new_actions_notification_rake_published" do
|
||||||
let!(:proposal) { create(:proposal) }
|
let!(:proposal) { create(:proposal) }
|
||||||
|
|
||||||
|
it "Disables email delivery using setting" do
|
||||||
|
Setting["dashboard.emails"] = nil
|
||||||
|
ActionMailer::Base.deliveries.clear
|
||||||
|
|
||||||
|
run_rake_task
|
||||||
|
|
||||||
|
expect(ActionMailer::Base.deliveries.count).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
it "sends emails when detect new actions for proposal" do
|
it "sends emails when detect new actions for proposal" do
|
||||||
run_rake_task
|
run_rake_task
|
||||||
|
|
||||||
@@ -104,7 +161,17 @@ describe Dashboard::Mailer do
|
|||||||
|
|
||||||
let!(:proposal) { build(:proposal, :draft) }
|
let!(:proposal) { build(:proposal, :draft) }
|
||||||
|
|
||||||
it "sends emails when detect new actions when create a proposal" do
|
it "Disables email delivery using setting" do
|
||||||
|
Setting["dashboard.emails"] = nil
|
||||||
|
|
||||||
|
action.update(published_proposal: false)
|
||||||
|
resource.update(published_proposal: false)
|
||||||
|
proposal.save
|
||||||
|
|
||||||
|
expect(ActionMailer::Base.deliveries.count).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "sends emails if new actions detected when creating a proposal" do
|
||||||
action.update(published_proposal: false)
|
action.update(published_proposal: false)
|
||||||
resource.update(published_proposal: false)
|
resource.update(published_proposal: false)
|
||||||
proposal.save
|
proposal.save
|
||||||
@@ -162,6 +229,15 @@ describe Dashboard::Mailer do
|
|||||||
let!(:proposed_action) { create(:dashboard_action, :proposed_action, :active, day_offset: 0,
|
let!(:proposed_action) { create(:dashboard_action, :proposed_action, :active, day_offset: 0,
|
||||||
published_proposal: true) }
|
published_proposal: true) }
|
||||||
|
|
||||||
|
it "Disables email delivery using setting" do
|
||||||
|
Setting["dashboard.emails"] = nil
|
||||||
|
|
||||||
|
proposal.save
|
||||||
|
proposal.publish
|
||||||
|
|
||||||
|
expect(ActionMailer::Base.deliveries.count).to eq(0)
|
||||||
|
end
|
||||||
|
|
||||||
it "sends emails when detect new actions when publish a proposal" do
|
it "sends emails when detect new actions when publish a proposal" do
|
||||||
proposal.save
|
proposal.save
|
||||||
proposal.publish
|
proposal.publish
|
||||||
@@ -202,4 +278,5 @@ describe Dashboard::Mailer do
|
|||||||
expect(email).to have_body_text("Go ahead, discover them!")
|
expect(email).to have_body_text("Go ahead, discover them!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user