Send new action notification email after create Proposal
After create a proposal send email to proposal's author with information text and new actions available.
This commit is contained in:
@@ -5,4 +5,9 @@ class Dashboard::Mailer < ApplicationMailer
|
||||
@proposal = proposal
|
||||
mail to: proposal.author.email, subject: proposal.title
|
||||
end
|
||||
|
||||
def new_actions_notification_on_create(proposal)
|
||||
@proposal = proposal
|
||||
mail to: proposal.author.email, subject: I18n.t("mailers.new_actions_notification_on_create.subject")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,6 +55,8 @@ class Proposal < ActiveRecord::Base
|
||||
|
||||
before_save :calculate_hot_score, :calculate_confidence_score
|
||||
|
||||
after_create :send_new_actions_notification_on_create
|
||||
|
||||
scope :for_render, -> { includes(:tags) }
|
||||
scope :sort_by_hot_score, -> { reorder(hot_score: :desc) }
|
||||
scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc) }
|
||||
@@ -236,6 +238,14 @@ class Proposal < ActiveRecord::Base
|
||||
Setting["feature.user.skip_verification"].present?
|
||||
end
|
||||
|
||||
def send_new_actions_notification_on_create
|
||||
new_actions = Dashboard::Action.detect_new_actions(self)
|
||||
|
||||
if new_actions.present?
|
||||
Dashboard::Mailer.new_actions_notification_on_create(self).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def set_responsible_name
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<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_create.hi", name: @proposal.author.name) %></p>
|
||||
<p><%= t("mailers.new_actions_notification_on_create.introduction", title: @proposal.title) %></p>
|
||||
<p>
|
||||
<%= t("mailers.new_actions_notification_on_create.text_1") %>
|
||||
<br>
|
||||
<%= t("mailers.new_actions_notification_on_create.text_2", link: proposal_dashboard_url(@proposal)).html_safe %>
|
||||
</p>
|
||||
<p><%= t("mailers.new_actions_notification_on_create.text_3") %></p>
|
||||
<p><%= t("mailers.new_actions_notification_on_create.text_4") %></p>
|
||||
<ul>
|
||||
<li><%= t("mailers.new_actions_notification_on_create.list_1") %></li>
|
||||
<li><%= t("mailers.new_actions_notification_on_create.list_2") %></li>
|
||||
<li><%= t("mailers.new_actions_notification_on_create.list_3") %></li>
|
||||
<li>
|
||||
<%= t("mailers.new_actions_notification_on_create.list_4",
|
||||
max_month: Setting["months_to_archive_proposals"],
|
||||
max_votes: Setting["votes_for_proposal_success"]) %>
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
<p>
|
||||
<%= t("mailers.new_actions_notification_on_create.text_5") %>
|
||||
<br>
|
||||
<%= t("mailers.new_actions_notification_on_create.text_6") %>
|
||||
</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_create.dashboard_button") %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
@@ -77,3 +77,18 @@ en:
|
||||
hi: "Dear user,"
|
||||
thanks: "Thank you again for participating."
|
||||
sincerely: "Sincererly"
|
||||
new_actions_notification_on_create:
|
||||
subject: "Your draft citizen proposal in Decide Madrid is created"
|
||||
hi: "Hi %{name}!"
|
||||
introduction: "Your %{title} proposal has been successfully created."
|
||||
text_1: "Take advantage that your proposal is not public yet and get ready to contact a lot of people."
|
||||
text_2: "When you are ready publish your citizen proposal from this <a href='%{link}'>link</a>."
|
||||
text_3: "We know that creating a proposal with a hook and getting the necessary support can seem complicated. But dont worry because we are going to help you!"
|
||||
text_4: "You have a tool that will be your new best ally: The Citizen Proposals panel."
|
||||
list_1: "Enter every day in the panel of your proposal to use the tips and resources that we will share with you."
|
||||
list_2: "These tips, actions and resources will give you ideas and also practical solutions to get more support and a wider community. Dont forget them!"
|
||||
list_3: "As you gain more support, you will unlock new and better resources. At the moment, you have an e-mail template to send massively to all your contacts, a poster to print, among other features and rewards that you will discover. Dont stop adding support and we will not stop rewarding and helping you!"
|
||||
list_4: "You have %{max_month} months since you publish the proposal to get %{max_votes} support and your proposal can become a reality. But the first days are the most important. It is a challenge. Get ready!"
|
||||
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!"
|
||||
|
||||
@@ -77,3 +77,18 @@ es:
|
||||
hi: "Estimado/a usuario/a"
|
||||
thanks: "Gracias de nuevo por tu participación."
|
||||
sincerely: "Atentamente"
|
||||
new_actions_notification_on_create:
|
||||
subject: "Tu borrador de propuesta ciudadana en Decide Madrid está creado"
|
||||
hi: "Hola %{name}!"
|
||||
introduction: "Tu propuesta %{title} ha sido creada con éxito."
|
||||
text_1: "Aprovecha que tu propuesta aún no es pública y prepárate para contactar a mucha gente."
|
||||
text_2: "Cuando estés preparado/a publica tu propuesta ciudadana desde este <a href='%{link}'>enlace</a>."
|
||||
text_3: "Sabemos que crear una propuesta con gancho y conseguir los apoyos necesarios, puede parecerte complicado. Pero no te preocupes porque ¡vamos a ayudarte!"
|
||||
text_4: "Tienes una herramienta que será tu nuevo mejor aliado: El panel de Propuestas Ciudadanas."
|
||||
list_1: "Entra cada día en el panel de tu propuesta para utilizar los consejos y recursos que te iremos compartiendo."
|
||||
list_2: "Estos consejos, acciones y recursos te darán ideas y también soluciones prácticas para lograr más apoyos y contar con una comunidad más amplia. ¡No te olvides de ellos!"
|
||||
list_3: "A medida que logres más apoyos, desbloquearás nuevos y mejores recursos. De momento, cuentas con una plantilla de e-mail para enviar masivamente a todos tus contactos, un cartel para imprimir, entre otras funcionalidades y recompensas que irás descubriendo ¡No dejes de sumar apoyos y nosotros no dejaremos de premiarte y ayudarte!"
|
||||
list_4: "Tienes %{max_month} meses desde que publiques la propuesta para conseguir %{max_votes} apoyos y que tu propuesta pueda hacerse realidad. Pero los primeros días son los más importantes. Es un reto ¡prepárate!"
|
||||
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!"
|
||||
|
||||
44
spec/mailers/dashboard/mailer_spec.rb
Normal file
44
spec/mailers/dashboard/mailer_spec.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Dashboard::Mailer do
|
||||
|
||||
describe "#new_actions_notification_on_create" do
|
||||
|
||||
before do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
let!(:proposal) { build(:proposal, :draft) }
|
||||
let!(:action) { create(:dashboard_action, :proposed_action, :active,
|
||||
day_offset: 0,
|
||||
published_proposal: true) }
|
||||
let!(:resource) { create(:dashboard_action, :resource, :active,
|
||||
day_offset: 0,
|
||||
published_proposal: true) }
|
||||
|
||||
it "sends emails when detect new actions when create a proposal" do
|
||||
action.update(published_proposal: false)
|
||||
resource.update(published_proposal: false)
|
||||
proposal.save
|
||||
|
||||
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 draft citizen proposal in Decide Madrid is created")
|
||||
expect(email).to have_body_text("Hi #{proposal.author.name}!")
|
||||
expect(email).to have_body_text("Your #{proposal.title} proposal has been successfully created.")
|
||||
expect(email).to have_body_text("Take advantage that your proposal is not public yet and get ready to contact a lot of people.")
|
||||
expect(email).to have_body_text(I18n.t("mailers.new_actions_notification_on_create.text_2", link: proposal_dashboard_url(proposal)).html_safe)
|
||||
expect(email).to have_body_text("We know that creating a proposal with a hook and getting the necessary support can seem complicated. But dont worry because we are going to help you!")
|
||||
expect(email).to have_body_text("You have a tool that will be your new best ally: The Citizen Proposals panel.")
|
||||
expect(email).to have_body_text("Enter every day in the panel of your proposal to use the tips and resources that we will share with you.")
|
||||
expect(email).to have_body_text("These tips, actions and resources will give you ideas and also practical solutions to get more support and a wider community. Dont forget them!")
|
||||
expect(email).to have_body_text("As you gain more support, you will unlock new and better resources. At the moment, you have an e-mail template to send massively to all your contacts, a poster to print, among other features and rewards that you will discover. Dont stop adding support and we will not stop rewarding and helping you!")
|
||||
expect(email).to have_body_text("You have #{Setting['months_to_archive_proposals']} months since you publish the proposal to get #{Setting['votes_for_proposal_success']} support and your proposal can become a reality. But the first days are the most important. It is a challenge. Get ready!")
|
||||
expect(email).to have_body_text("And for you to start with all the motivation,")
|
||||
expect(email).to have_body_text("here you have several resources and a whole list of tips that will come to you every day to prepare the broadcast!")
|
||||
expect(email).to have_body_text("Go ahead, discover them!")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,4 +3,10 @@ class DashboardMailerPreview < ActionMailer::Preview
|
||||
proposal = Proposal.first
|
||||
Dashboard::Mailer.forward(proposal)
|
||||
end
|
||||
|
||||
# http://localhost:3000/rails/mailers/dashboard_mailer/new_actions_notification_on_create
|
||||
def new_actions_notification_on_create
|
||||
proposal = Proposal.first
|
||||
Dashboard::Mailer.new_actions_notification_on_create(proposal)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -992,4 +992,30 @@ describe Proposal do
|
||||
|
||||
end
|
||||
|
||||
describe "#send_new_actions_notification_on_create" do
|
||||
|
||||
before do
|
||||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
it "send notification after create when there are new actived actions" do
|
||||
create(:dashboard_action, :proposed_action, :active, day_offset: 0, published_proposal: false)
|
||||
create(:dashboard_action, :resource, :active, day_offset: 0, published_proposal: false)
|
||||
|
||||
create(:proposal, :draft)
|
||||
|
||||
expect(ActionMailer::Base.deliveries.count).to eq(1)
|
||||
end
|
||||
|
||||
it "Not send notification after create when there are not new actived actions" do
|
||||
create(:dashboard_action, :proposed_action, :active, day_offset: 1, published_proposal: false)
|
||||
create(:dashboard_action, :resource, :active, day_offset: 1, published_proposal: false)
|
||||
|
||||
create(:proposal, :draft)
|
||||
|
||||
expect(ActionMailer::Base.deliveries.count).to eq(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user