Send new notification email after publish Proposal
After publish a proposal send email to proposal's author with information text and new actions available.
This commit is contained in:
@@ -23,8 +23,14 @@ class Dashboard::Mailer < ApplicationMailer
|
||||
mail to: proposal.author.email, subject: I18n.t("mailers.new_actions_notification_on_create.subject")
|
||||
end
|
||||
|
||||
def new_actions_notification_on_published(proposal, new_actions_ids)
|
||||
@proposal = proposal
|
||||
@new_actions = get_new_actions(new_actions_ids)
|
||||
mail to: proposal.author.email, subject: I18n.t("mailers.new_actions_notification_on_published.subject")
|
||||
end
|
||||
|
||||
private
|
||||
def get_new_actions(new_actions_ids)
|
||||
Dashboard::Action.where(id: new_actions_ids)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -86,6 +86,7 @@ class Proposal < ActiveRecord::Base
|
||||
|
||||
def publish
|
||||
update(published_at: Time.now)
|
||||
send_new_actions_notification_on_published
|
||||
end
|
||||
|
||||
def published?
|
||||
@@ -246,6 +247,14 @@ class Proposal < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def send_new_actions_notification_on_published
|
||||
new_actions_ids = Dashboard::Action.detect_new_actions(self)
|
||||
|
||||
if new_actions_ids.present?
|
||||
Dashboard::Mailer.new_actions_notification_on_published(self, new_actions_ids).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_responsible_name
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<td style="padding-bottom: 20px;padding-left: 10px;font-size: 14px;font-weight: normal;
|
||||
font-family:'Open Sans',arial,sans-serif;line-height: 24px; text-align: justify;">
|
||||
|
||||
<p>
|
||||
<%= t("mailers.new_actions_notification_on_published.hi",
|
||||
name: @proposal.author.name,
|
||||
title: @proposal.title) %>
|
||||
</p>
|
||||
<p>
|
||||
<%= t("mailers.new_actions_notification_on_published.text_1") %>
|
||||
<br>
|
||||
<%= t("mailers.new_actions_notification_on_published.text_2") %>
|
||||
</p>
|
||||
<p><%= t("mailers.new_actions_notification_on_published.text_3") %></p>
|
||||
<p><%= t("mailers.new_actions_notification_on_published.text_4") %></p>
|
||||
<p><%= t("mailers.new_actions_notification_on_published.text_5") %></p>
|
||||
<p><%= t("mailers.new_actions_notification_on_published.text_6") %></p>
|
||||
<ul>
|
||||
<li><%= t("mailers.new_actions_notification_on_published.list_1") %></li>
|
||||
<li><%= t("mailers.new_actions_notification_on_published.list_2") %></li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<p><%= t("mailers.new_actions_notification_on_published.text_7") %></p>
|
||||
<% first_resource = @new_actions.resources.first %>
|
||||
<% if first_resource.present? %>
|
||||
<p><%= t("mailers.new_actions_notification_on_published.text_8") %></p>
|
||||
<ul>
|
||||
<li><%= first_resource.title %></li>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
<% first_proposed_action = @new_actions.proposed_actions.first %>
|
||||
<% if first_proposed_action.present? %>
|
||||
<p><%= t("mailers.new_actions_notification_on_published.text_9") %></p>
|
||||
<ul>
|
||||
<li><%= first_proposed_action.title %></li>
|
||||
<% if first_proposed_action.short_description.present? %>
|
||||
<p><%= first_proposed_action.short_description.html_safe %></p>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
<br>
|
||||
|
||||
<p><%= t("mailers.new_actions_notification_on_published.text_10") %></p>
|
||||
|
||||
<table style="width: 100%;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="padding-bottom: 12px; padding-top: 24px; text-align: center;">
|
||||
<%= link_to progress_proposal_dashboard_url(@proposal),
|
||||
style: "font-family: 'Open Sans',arial,sans-serif; background: #3700fd;
|
||||
border-radius: 6px; color: #fff !important; font-weight: bold;
|
||||
padding: 17px 20px; text-align: center; text-decoration: none;
|
||||
font-size: 20px; min-width: 200px; display: inline-block;",
|
||||
target: "_blank" do %>
|
||||
<%= t("mailers.new_actions_notification_on_published.dashboard_button") %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
@@ -116,3 +116,19 @@ en:
|
||||
text_5: "And for you to start with all the motivation,"
|
||||
text_6: "here you have several resources and a whole list of tips that will come to you every day to prepare the broadcast!"
|
||||
dashboard_button: "Go ahead, discover them!"
|
||||
new_actions_notification_on_published:
|
||||
subject: "Your citizen proposal is already published Dont stop spreading!"
|
||||
hi: "Congratulations %{name}! Your proposal %{title} has been created successfully."
|
||||
text_1: "And now, go for your first 100 supports!"
|
||||
text_2: "Why 100?"
|
||||
text_3: "Our experience tells us that the first day is fundamental. Because in addition to having the energy to launch something new, being a newly published proposal, you will have the important visibility of being among the new proposals highlighted in Decide Madrid."
|
||||
text_4: "Get 100 supports on the first day, and you will have a first community to back you up."
|
||||
text_5: "That is why we challenge you to get it, but not without a lot of help!"
|
||||
text_6: "Remember that in your Proposal Panel you have new resources available and recommendations for dissemination actions."
|
||||
list_1: "Come in every day to see your progress and use the tips and resources we will share with you. They are ideas and also practical solutions to get the support you need."
|
||||
list_2: "As you get more support, you will unlock new and better resources. Do not stop adding support and we will not stop rewarding and helping you!"
|
||||
text_7: "And for you to start at full speed..."
|
||||
text_8: "Here is a great resource at your disposal!"
|
||||
text_9: "You will also find this new recommended dissemination action..."
|
||||
text_10: "You sure have more resources to use!"
|
||||
dashboard_button: "Go ahead, discover them!"
|
||||
|
||||
@@ -116,3 +116,19 @@ es:
|
||||
text_5: "Y para que empieces con toda la motivación,"
|
||||
text_6: "¡aquí tienes varios recursos y toda una lista de consejos que te irán llegando cada día para preparar la difusión!"
|
||||
dashboard_button: "Adelante, ¡descúbrelos!"
|
||||
new_actions_notification_on_published:
|
||||
subject: "Tu propuesta ciudadana ya está publicada ¡No pares de difundir!"
|
||||
hi: "¡Enhorabuena %{name}! Tu propuesta %{title} ha sido creado con éxito."
|
||||
text_1: "Y ahora, ¡a por tus primeros 100 apoyos! "
|
||||
text_2: "¿Por qué 100?"
|
||||
text_3: "Nuestra experiencia nos dice que el primer día es fundamental. Porque además de tener la energía de lanzar algo nuevo, al ser una propuesta recién publicada, contarás con la importante visibilidad de estar entre las nuevas propuestas destacadas en Decide Madrid."
|
||||
text_4: "Logra 100 apoyos en el primer día, y tendrás una primera comunidad en la que respaldarte."
|
||||
text_5: "Por eso, te retamos a que lo consigas, ¡pero no sin una gran ayuda!"
|
||||
text_6: "Recuerda que en tu Panel de propuestas tienes nuevos recursos disponibles y recomendaciones de acciones de difusión."
|
||||
list_1: "Entra cada día para ver tu progreso y utilizar los consejos y recursos que te iremos compartiendo. Son ideas y también soluciones prácticas para lograr los apoyos que necesitas."
|
||||
list_2: "A medida que logres más apoyos, desbloquearás nuevos y mejores recursos. ¡No dejes de sumar apoyos y nosotros no dejaremos de premiarte y ayudarte!"
|
||||
text_7: "Y para que empieces a toda máquina..."
|
||||
text_8: "¡aquí tienes un gran recurso a tu total disposición!"
|
||||
text_9: "También encontrarás esta nueva acción de difusión recomendada…"
|
||||
text_10: "¡Seguro que tienes más recursos pendientes de usar!"
|
||||
dashboard_button: "Adelante, ¡descúbrelos!"
|
||||
|
||||
@@ -112,4 +112,40 @@ describe Dashboard::Mailer do
|
||||
expect(email).to have_body_text("Go ahead, discover them!")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#new_actions_notification_on_published" do
|
||||
|
||||
before do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
let!(:proposal) { build(:proposal, :draft) }
|
||||
let!(:resource) { create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: true) }
|
||||
let!(:proposed_action) { create(:dashboard_action, :proposed_action, :active, day_offset: 0, published_proposal: true) }
|
||||
|
||||
it "sends emails when detect new actions when publish a proposal" do
|
||||
proposal.save
|
||||
proposal.publish
|
||||
|
||||
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("Your citizen proposal is already published Dont stop spreading!")
|
||||
expect(email).to have_body_text("Congratulations #{proposal.author.name}! Your proposal #{proposal.title} has been created successfully.")
|
||||
expect(email).to have_body_text("And now, go for your first 100 supports!")
|
||||
expect(email).to have_body_text("Why 100?")
|
||||
expect(email).to have_body_text("Our experience tells us that the first day is fundamental. Because in addition to having the energy to launch something new, being a newly published proposal, you will have the important visibility of being among the new proposals highlighted in Decide Madrid.")
|
||||
expect(email).to have_body_text("Get 100 supports on the first day, and you will have a first community to back you up.")
|
||||
expect(email).to have_body_text("That is why we challenge you to get it, but not without a lot of help!")
|
||||
expect(email).to have_body_text("Remember that in your Proposal Panel you have new resources available and recommendations for dissemination actions.")
|
||||
expect(email).to have_body_text("Come in every day to see your progress and use the tips and resources we will share with you. They are ideas and also practical solutions to get the support you need.")
|
||||
expect(email).to have_body_text("As you get more support, you will unlock new and better resources. Do not stop adding support and we will not stop rewarding and helping you!")
|
||||
expect(email).to have_body_text("And for you to start at full speed...")
|
||||
expect(email).to have_body_text("Here is a great resource at your disposal!")
|
||||
expect(email).to have_body_text("You will also find this new recommended dissemination action...")
|
||||
expect(email).to have_body_text("You sure have more resources to use!")
|
||||
expect(email).to have_body_text("Go ahead, discover them!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,4 +23,11 @@ class DashboardMailerPreview < ActionMailer::Preview
|
||||
proposal = Proposal.first
|
||||
Dashboard::Mailer.new_actions_notification_on_create(proposal)
|
||||
end
|
||||
|
||||
# http://localhost:3000/rails/mailers/dashboard_mailer/new_actions_notification_on_published
|
||||
def new_actions_notification_on_published
|
||||
proposal = Proposal.first
|
||||
new_actions = Dashboard::Action.all
|
||||
Dashboard::Mailer.new_actions_notification_on_published(proposal, new_actions)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1018,4 +1018,32 @@ describe Proposal do
|
||||
|
||||
end
|
||||
|
||||
describe "#send_new_actions_notification_on_published" do
|
||||
|
||||
before do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
it "send notification after published when there are new actived actions" do
|
||||
create(:dashboard_action, :proposed_action, :active, day_offset: 0, published_proposal: true)
|
||||
create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: true)
|
||||
|
||||
proposal = create(:proposal, :draft)
|
||||
proposal.publish
|
||||
|
||||
expect(ActionMailer::Base.deliveries.count).to eq(1)
|
||||
end
|
||||
|
||||
it "Not send notification after published when there are not new actived actions" do
|
||||
create(:dashboard_action, :proposed_action, :active, day_offset: 1, published_proposal: true)
|
||||
create(:dashboard_action, :resource, :active, day_offset: 1, published_proposal: true)
|
||||
|
||||
proposal = create(:proposal, :draft)
|
||||
proposal.publish
|
||||
|
||||
expect(ActionMailer::Base.deliveries.count).to eq(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user