diff --git a/app/mailers/dashboard/mailer.rb b/app/mailers/dashboard/mailer.rb index 669e51815..cff05c52c 100644 --- a/app/mailers/dashboard/mailer.rb +++ b/app/mailers/dashboard/mailer.rb @@ -7,20 +7,6 @@ class Dashboard::Mailer < ApplicationMailer mail to: proposal.author.email, subject: proposal.title end - def new_actions_notification_rake_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_rake_published.subject") - end - - def new_actions_notification_rake_created(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_rake_created.subject") - end - def new_actions_notification_on_create(proposal) @proposal = proposal mail to: proposal.author.email, diff --git a/app/views/dashboard/mailer/new_actions_notification_rake_created.html.erb b/app/views/dashboard/mailer/new_actions_notification_rake_created.html.erb deleted file mode 100644 index f43c1600a..000000000 --- a/app/views/dashboard/mailer/new_actions_notification_rake_created.html.erb +++ /dev/null @@ -1,73 +0,0 @@ - - -

<%= t("mailers.new_actions_notification_rake_created.hi", name: @proposal.author.name) %>

- -

- <%= t("mailers.new_actions_notification_rake_created.introduction", - created_at_day: @proposal.created_at.day, - created_at_month: @proposal.created_at.strftime("%B"), - title: @proposal.title) %> -

-

- <%= sanitize(t("mailers.new_actions_notification_rake_created.text_1", - link_to_published: link_to(proposal_dashboard_url(@proposal), - proposal_dashboard_url(@proposal)))) %> -

-

<%= t("mailers.new_actions_notification_rake_created.text_2") %>

-
-

<%= t("mailers.new_actions_notification_rake_created.text_3") %>

- -
- - <% first_resource = @new_actions.resources.first %> - <% if first_resource.present? %> - <%= t("mailers.new_actions_notification_rake_created.new_resource") %> - -
- <% end %> - - <% first_proposed_action = @new_actions.proposed_actions.first %> - <% if first_proposed_action.present? %> -

<%= t("mailers.new_actions_notification_rake_created.text_4") %>

- -
- <% end %> - - <% if @new_actions.proposed_actions.count > 1 %> - <% second_proposed_action = @new_actions.proposed_actions.second %> -

<%= t("mailers.new_actions_notification_rake_created.text_5") %>

- -
- <% end %> - -

<%= t("mailers.new_actions_notification_rake_created.footer_text") %>

- -
- - - - - - -
- <%= link_to 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_rake_created.dashboard_button") %> - <% end %> -
- - diff --git a/app/views/dashboard/mailer/new_actions_notification_rake_published.html.erb b/app/views/dashboard/mailer/new_actions_notification_rake_published.html.erb deleted file mode 100644 index f120ab1bc..000000000 --- a/app/views/dashboard/mailer/new_actions_notification_rake_published.html.erb +++ /dev/null @@ -1,74 +0,0 @@ - - -

<%= t("mailers.new_actions_notification_rake_published.hi", name: @proposal.author.name) %>

-

- <%= t("mailers.new_actions_notification_rake_published.introduction", - published_at_day: @proposal.published_at.day, - published_at_month: @proposal.published_at.strftime("%B"), - title: @proposal.title) %> -

-
- <% first_resource = @new_actions.resources.first %> - <% if first_resource.present? %> -

<%= t("mailers.new_actions_notification_rake_published.text_1", votes_count: @proposal.cached_votes_up) %>

-
-

<%= t("mailers.new_actions_notification_rake_published.text_2") %>

-
-

<%= t("mailers.new_actions_notification_rake_published.new_resource") %>

- -
- <% end %> - - <% limit_to_archive_proposal = @proposal.created_at.to_date + - Setting["months_to_archive_proposals"].to_i.months %> -

- <%= t("mailers.new_actions_notification_rake_published.text_3", - days_count: (limit_to_archive_proposal - Date.current).to_i, - max_votes_count: Setting["votes_for_proposal_success"]) %> -

- - <% first_proposed_action = @new_actions.proposed_actions.first %> - <% if first_proposed_action.present? %> -

<%= t("mailers.new_actions_notification_rake_published.text_4") %>

- -
- <% end %> - - <% if @new_actions.proposed_actions.count > 1 %> - <% second_proposed_action = @new_actions.proposed_actions.second %> -

<%= t("mailers.new_actions_notification_rake_published.text_5") %>

- -
- <% end %> - -

<%= t("mailers.new_actions_notification_rake_published.footer_text") %>

- -
- - - - - - -
- <%= link_to 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_rake_published.dashboard_button") %> - <% end %> -
- - diff --git a/config/locales/en/mailers.yml b/config/locales/en/mailers.yml index a11aff0cb..4854f7408 100644 --- a/config/locales/en/mailers.yml +++ b/config/locales/en/mailers.yml @@ -96,30 +96,6 @@ en: subject: "Machine Learning - Content has been generated successfully" text: "Content has been generated successfully." title: "Machine Learning script" - new_actions_notification_rake_created: - subject: "More news about your citizen proposal" - hi: "Hello %{name}," - new_resource: "NEW UNLOCKED RESOURCE" - introduction: "As you know, on the %{created_at_day} day of the %{created_at_month} you created the proposal in draft mode %{title}." - text_1: "Whenever you want you can publish on this link: %{link_to_published}. If you're still not sure..." - text_2: "Seize this moment! Learn, add other people with the same interests and prepare the diffusion that you will need when you publish your proposal definitively." - text_3: "And to accompany you in this challenge, here are the news..." - text_4: "Take a look at this NEW recommended ACTION:" - text_5: "The next action we recommend is:" - footer_text: "As always, enter the Proposals Panel and we will tell you in detail how to use these resources and how to get the most out of it." - dashboard_button: "Go ahead, discover them!" - new_actions_notification_rake_published: - subject: "More news about your citizen proposal" - hi: "Hello %{name}," - new_resource: "NEW UNLOCKED RESOURCE" - introduction: "As you know, on the %{published_at_day} day of the %{published_at_month} you published the proposal %{title}." - text_1: "Well, you've got %{votes_count} support so far Congratulations!" - text_2: "And so, you have a new resource available to help you keep moving forward." - text_3: "You are missing %{days_count} days before your proposal gets the %{max_votes_count} supports and goes to referendum. Cheer up and keep spreading. Are you short of ideas?" - text_4: "NEW RECOMMENDED DIFFUSION ACTION" - text_5: "There's more yet, see the following action:" - footer_text: "As always, enter the Proposals Panel and we will tell you in detail how to use these resources and how to get the most out of it." - dashboard_button: "Go ahead, discover them!" new_actions_notification_on_create: subject: "Your draft citizen proposal is created" hi: "Hi %{name}!" diff --git a/config/locales/es/mailers.yml b/config/locales/es/mailers.yml index b8f4d73fb..45b1f7129 100644 --- a/config/locales/es/mailers.yml +++ b/config/locales/es/mailers.yml @@ -96,30 +96,6 @@ es: subject: "Machine learning - Contenido generado correctamente" text: "El contenido ha sido generado correctamente." title: "Script Machine Learning" - new_actions_notification_rake_created: - subject: "Más novedades de tu propuesta ciudadana" - hi: "Hola %{name}," - new_resource: "NUEVO RECURSO DESBLOQUEADO" - introduction: "Como sabes, el día %{created_at_day} del %{created_at_month} creaste la propuesta en modo borrador %{title}." - text_1: "Cuando quieras puedes publicar en este enlace: %{link_to_published}. Si aún no lo tienes claro…" - text_2: "¡aprovecha este momento! Aprende, suma a otras personas con los mismos intereses y prepara la difusión que necesitarás al publicar tu propuesta definitivamente." - text_3: "Y para acompañarte en este reto, aquí van las novedades..." - text_4: "Échale un vistazo a esta NUEVA ACCIÓN recomendada:" - text_5: "La siguiente acción que te recomendamos es:" - footer_text: "Como siempre, entra en el Panel de propuestas y te contamos detalladamente cómo utilizar estos recursos y cómo sacarle el máximo partido." - dashboard_button: "Adelante, ¡descúbrelos!" - new_actions_notification_rake_published: - subject: "Más novedades de tu propuesta ciudadana" - hi: "Hola %{name}," - new_resource: "NUEVO RECURSO DESBLOQUEADO" - introduction: "Como sabes, el día %{published_at_day} del %{published_at_month} publicaste la propuesta %{title}." - text_1: "Pues bien, has conseguido %{votes_count} apoyos hasta este momento ¡Felicidades!" - text_2: "Y por eso, tienes disponible un nuevo recurso para ayudarte a seguir avanzando." - text_3: "Te faltan %{days_count} días para que tu propuesta consiga los %{max_votes_count} apoyos y que vaya a referéndum. Ánimo y sigue difundiendo. ¿Te faltan ideas?" - text_4: "NUEVA ACCIÓN DE DIFUSIÓN RECOMENDADA" - text_5: "Aún hay más, consulta la siguiente acción:" - footer_text: "Como siempre, entra en el Panel de propuestas y te contamos detalladamente cómo utilizar estos recursos y cómo sacarle el máximo partido." - dashboard_button: "Adelante, ¡descúbrelos!" new_actions_notification_on_create: subject: "Tu borrador de propuesta ciudadana está creado" hi: "Hola %{name}!" diff --git a/config/schedule.rb b/config/schedule.rb index 9acb31c19..4e7675dc5 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -31,11 +31,6 @@ every 2.hours do rake "-s stats:generate" end -# Temporally not send dashboard's notifications -# every 1.day, at: "7:00 am" do -# rake "dashboards:send_notifications" -# end - every 1.day, at: "1:00 am", roles: [:cron] do rake "files:remove_old_cached_attachments" end diff --git a/lib/tasks/dashboards.rake b/lib/tasks/dashboards.rake deleted file mode 100644 index 20663efd8..000000000 --- a/lib/tasks/dashboards.rake +++ /dev/null @@ -1,18 +0,0 @@ -namespace :dashboards do - desc "Send to user notifications from new actions availability on dashboard" - task send_notifications: :environment do - Proposal.not_archived.each do |proposal| - new_actions_ids = Dashboard::Action.detect_new_actions_since(Date.yesterday, proposal) - - if new_actions_ids.present? - if proposal.published? - Dashboard::Mailer.delay.new_actions_notification_rake_published(proposal, - new_actions_ids) - else - Dashboard::Mailer.delay.new_actions_notification_rake_created(proposal, - new_actions_ids) - end - end - end - end -end diff --git a/spec/lib/tasks/dashboards_spec.rb b/spec/lib/tasks/dashboards_spec.rb deleted file mode 100644 index 78143a8e4..000000000 --- a/spec/lib/tasks/dashboards_spec.rb +++ /dev/null @@ -1,83 +0,0 @@ -require "rails_helper" -require "rake" - -describe "Dashboards Rake" do - describe "#send_notifications" do - before do - Rake.application.rake_require "tasks/dashboards" - Rake::Task.define_task(:environment) - Setting["feature.dashboard.notification_emails"] = true - ActionMailer::Base.deliveries.clear - end - - let :run_rake_task do - Rake::Task["dashboards:send_notifications"].reenable - Rake.application.invoke_task "dashboards:send_notifications" - end - - describe "Not send notifications to proposal author" do - let!(:action) { create(:dashboard_action, :proposed_action, :active, day_offset: 1) } - let!(:resource) { create(:dashboard_action, :resource, :active, day_offset: 1) } - - it "when there are not news actions actived for published proposals" do - create(:proposal) - action.update!(published_proposal: true) - resource.update!(published_proposal: true) - - expect { run_rake_task }.to change { ActionMailer::Base.deliveries.count }.by(0) - end - - it "when there are not news actions actived for draft proposals" do - create(:proposal, :draft) - action.update!(published_proposal: false) - resource.update!(published_proposal: false) - - expect { run_rake_task }.to change { ActionMailer::Base.deliveries.count }.by(0) - end - - it "when there are news actions actived for archived proposals" do - create(:proposal, :archived) - action.update!(day_offset: 0, published_proposal: true) - resource.update!(day_offset: 0, published_proposal: true) - - expect { run_rake_task }.to change { ActionMailer::Base.deliveries.count }.by(0) - end - end - - describe "Send notifications to proposal author" do - let!(:action) { create(:dashboard_action, :proposed_action, :active, day_offset: 0) } - let!(:resource) { create(:dashboard_action, :resource, :active, day_offset: 0) } - - before do - Setting["mailer_from_name"] = "CONSUL" - Setting["mailer_from_address"] = "noreply@consul.dev" - end - - it " when there are news actions actived for published proposals" do - proposal = create(:proposal) - action.update!(published_proposal: true) - resource.update!(published_proposal: true) - - run_rake_task - email = open_last_email - - expect(email).to deliver_from("CONSUL ") - expect(email).to deliver_to(proposal.author) - expect(email).to have_subject("More news about your citizen proposal") - end - - it "when there are news actions actived for draft proposals" do - proposal = create(:proposal, :draft) - action.update!(published_proposal: false) - resource.update!(published_proposal: false) - - run_rake_task - email = open_last_email - - expect(email).to deliver_from("CONSUL ") - expect(email).to deliver_to(proposal.author) - expect(email).to have_subject("More news about your citizen proposal") - end - end - end -end diff --git a/spec/mailers/dashboard/mailer_spec.rb b/spec/mailers/dashboard/mailer_spec.rb index 7a2d2a3b2..5cc59d23c 100644 --- a/spec/mailers/dashboard/mailer_spec.rb +++ b/spec/mailers/dashboard/mailer_spec.rb @@ -44,111 +44,6 @@ describe Dashboard::Mailer do end end - describe "#new_actions_notification rake task" do - before do - Rake.application.rake_require "tasks/dashboards" - Rake::Task.define_task(:environment) - ActionMailer::Base.deliveries.clear - end - - let :run_rake_task do - Rake::Task["dashboards:send_notifications"].reenable - Rake.application.invoke_task "dashboards:send_notifications" - end - - describe "#new_actions_notification_rake_created" do - let!(:proposal) { create(:proposal, :draft) } - - it "Disables notification email delivery using setting" do - Setting["feature.dashboard.notification_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 - action.update!(published_proposal: false) - resource.update!(published_proposal: false) - run_rake_task - - email = open_last_email - - expect(email).to deliver_from("CONSUL ") - expect(email).to deliver_to(proposal.author) - expect(email).to have_subject("More news about your citizen proposal") - expect(email).to have_body_text("Hello #{proposal.author.name},") - expect(email).to have_body_text("As you know, on the #{proposal.created_at.day} day of "\ - "the #{proposal.created_at.strftime("%B")} you created "\ - "the proposal in draft mode #{proposal.title}.") - expect(email).to have_body_text("Whenever you want you can publish on this link:") - expect(email).to have_body_text("Seize this moment! Learn, add other people with the same "\ - "interests and prepare the diffusion that you will need "\ - "when you publish your proposal definitively.") - expect(email).to have_body_text("And to accompany you in this challenge, "\ - "here are the news...") - expect(email).to have_body_text("NEW UNLOCKED RESOURCE") - expect(email).to have_body_text(resource.title) - expect(email).to have_body_text("Take a look at this NEW recommended ACTION:") - expect(email).to have_body_text(action.title) - expect(email).to have_body_text(action.description) - expect(email).to have_body_text("As always, enter the Proposals Panel and we will tell "\ - "you in detail how to use these resources and how to get "\ - "the most out of it.") - expect(email).to have_body_text("Go ahead, discover them!") - end - end - - describe "#new_actions_notification_rake_published" do - let!(:proposal) { create(:proposal) } - - it "Disables notification email delivery using setting" do - Setting["feature.dashboard.notification_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 - run_rake_task - - email = open_last_email - - expect(email).to deliver_from("CONSUL ") - expect(email).to deliver_to(proposal.author) - expect(email).to have_subject("More news about your citizen proposal") - expect(email).to have_body_text("Hello #{proposal.author.name},") - expect(email).to have_body_text("As you know, on the #{proposal.published_at.day} day of "\ - "the #{proposal.published_at.strftime("%B")} you "\ - "published the proposal #{proposal.title}.") - expect(email).to have_body_text("And so, you have a new resource available to help "\ - "you keep moving forward.") - expect(email).to have_body_text("NEW UNLOCKED RESOURCE") - expect(email).to have_body_text(resource.title) - - months_to_archive_proposals = Setting["months_to_archive_proposals"].to_i.months - limit_to_archive_proposal = proposal.created_at.to_date + months_to_archive_proposals - days_count = (limit_to_archive_proposal - Date.current).to_i - - expect(email).to have_body_text("You are missing #{days_count} days before your proposal "\ - "gets the #{Setting["votes_for_proposal_success"]} "\ - "supports and goes to referendum. Cheer up and keep "\ - "spreading. Are you short of ideas?") - expect(email).to have_body_text("NEW RECOMMENDED DIFFUSION ACTION") - expect(email).to have_body_text(action.title) - expect(email).to have_body_text(action.description) - expect(email).to have_body_text("As always, enter the Proposals Panel and we will tell "\ - "you in detail how to use these resources and how to get "\ - "the most out of it.") - expect(email).to have_body_text("Go ahead, discover them!") - end - end - end - describe "#new_actions_notification_on_create" do before do ActionMailer::Base.deliveries.clear diff --git a/spec/mailers/previews/dashboard_mailer_preview.rb b/spec/mailers/previews/dashboard_mailer_preview.rb index ebcb07f44..0a5d82fb4 100644 --- a/spec/mailers/previews/dashboard_mailer_preview.rb +++ b/spec/mailers/previews/dashboard_mailer_preview.rb @@ -4,20 +4,6 @@ class DashboardMailerPreview < ActionMailer::Preview Dashboard::Mailer.forward(proposal) end - # http://localhost:3000/rails/mailers/dashboard_mailer/new_actions_notification_rake_published - def new_actions_notification_rake_published - proposal = Proposal.find_by(published: true) - new_actions_ids = Dashboard::Action.limit(1).id - Dashboard::Mailer.new_actions_notification(proposal, [new_actions_ids]) - end - - # http://localhost:3000/rails/mailers/dashboard_mailer/new_actions_notification_rake_created - def new_actions_notification_rake_created - proposal = Proposal.find_by(published: false) - new_actions_ids = Dashboard::Action.limit(1).id - Dashboard::Mailer.new_actions_notification(proposal, [new_actions_ids]) - end - # http://localhost:3000/rails/mailers/dashboard_mailer/new_actions_notification_on_create def new_actions_notification_on_create proposal = Proposal.first