From 45aec05b938959864c13cf0f97e0c621ec79e6d7 Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 29 Jan 2020 16:11:50 +0100 Subject: [PATCH 1/4] Update and rename Setting as feature type The old Setting["dashboard.emails"] is a Feature Setting, but appeared as Configuration Setting without button for enable/disable. In this commit, we update the old setting to behave like a Feature Setting. Too we rename setting to clarify what emails are blocked with this feature. --- app/models/setting.rb | 2 +- config/locales/en/settings.yml | 3 +++ config/locales/es/settings.yml | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/setting.rb b/app/models/setting.rb index d9d319784..c3ccd2757 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -170,7 +170,7 @@ class Setting < ApplicationRecord "hot_score_period_in_days": 31, "related_content_score_threshold": -0.3, "featured_proposals_number": 3, - "dashboard.emails": nil, + "feature.dashboard.notification_emails": nil, "remote_census.general.endpoint": "", "remote_census.request.method_name": "", "remote_census.request.structure": "", diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml index a8755f1db..333b64553 100644 --- a/config/locales/en/settings.yml +++ b/config/locales/en/settings.yml @@ -125,6 +125,9 @@ en: valuation_comment_notification: "Valuation comment notification" valuation_comment_notification_description: "Send an email to all associated users except valuation commenter to budget investment when a new valuation comment is created" graphql_api: "GraphQL API" + dashboard: + notification_emails: "Dashboard notification emails" + notification_emails_description: "Enable sending dashboard notification emails to proposal's authors" remote_census: general: endpoint: "Endpoint" diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml index b7de45411..bb700da10 100644 --- a/config/locales/es/settings.yml +++ b/config/locales/es/settings.yml @@ -125,6 +125,9 @@ es: valuation_comment_notification: "Notificar comentarios de evaluación" valuation_comment_notification_description: "Envía un email a todos los usuarios menos al que haya comentado asociados a un presupuesto participativo cuando se cree un nuevo comentario de evaluación" graphql_api: "API GraphQL" + dashboard: + notification_emails: "Emails del panel de progreso" + notification_emails_description: "Activar el envío de emails de notificaciones a los autores de las propuestas en la sección de panel de progreso" remote_census: general: endpoint: "Endpoint" From 5608424510f759b09bf0b0180191cbfaeeabc1a9 Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 29 Jan 2020 16:13:53 +0100 Subject: [PATCH 2/4] Rename all ocurrences from this Setting to new key --- app/mailers/dashboard/mailer.rb | 2 +- spec/lib/tasks/dashboards_spec.rb | 2 +- spec/mailers/dashboard/mailer_spec.rb | 20 ++++++++++---------- spec/models/proposal_spec.rb | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/mailers/dashboard/mailer.rb b/app/mailers/dashboard/mailer.rb index d6bb9da5b..f90b683d5 100644 --- a/app/mailers/dashboard/mailer.rb +++ b/app/mailers/dashboard/mailer.rb @@ -41,6 +41,6 @@ class Dashboard::Mailer < ApplicationMailer end def check_deliverability - mail.perform_deliveries = false unless Setting["dashboard.emails"] + mail.perform_deliveries = false unless Setting["feature.dashboard.notification_emails"] end end diff --git a/spec/lib/tasks/dashboards_spec.rb b/spec/lib/tasks/dashboards_spec.rb index 212979f91..6e50a31a1 100644 --- a/spec/lib/tasks/dashboards_spec.rb +++ b/spec/lib/tasks/dashboards_spec.rb @@ -6,7 +6,7 @@ describe "Dashboards Rake" do before do Rake.application.rake_require "tasks/dashboards" Rake::Task.define_task(:environment) - Setting["dashboard.emails"] = true + Setting["feature.dashboard.notification_emails"] = true ActionMailer::Base.deliveries.clear end diff --git a/spec/mailers/dashboard/mailer_spec.rb b/spec/mailers/dashboard/mailer_spec.rb index 9feb6836b..812c3cfe5 100644 --- a/spec/mailers/dashboard/mailer_spec.rb +++ b/spec/mailers/dashboard/mailer_spec.rb @@ -10,7 +10,7 @@ describe Dashboard::Mailer do end before do - Setting["dashboard.emails"] = true + Setting["feature.dashboard.notification_emails"] = true end describe "#forward" do @@ -21,7 +21,7 @@ describe Dashboard::Mailer do end it "Disables email delivery using setting" do - Setting["dashboard.emails"] = nil + Setting["feature.dashboard.notification_emails"] = nil Dashboard::Mailer.forward(proposal).deliver_now @@ -57,8 +57,8 @@ describe Dashboard::Mailer do describe "#new_actions_notification_rake_created" do let!(:proposal) { create(:proposal, :draft) } - it "Disables email delivery using setting" do - Setting["dashboard.emails"] = nil + it "Disables notification email delivery using setting" do + Setting["feature.dashboard.notification_emails"] = nil action.update!(published_proposal: false) resource.update!(published_proposal: false) @@ -102,8 +102,8 @@ describe Dashboard::Mailer do describe "#new_actions_notification_rake_published" do let!(:proposal) { create(:proposal) } - it "Disables email delivery using setting" do - Setting["dashboard.emails"] = nil + it "Disables notification email delivery using setting" do + Setting["feature.dashboard.notification_emails"] = nil ActionMailer::Base.deliveries.clear run_rake_task @@ -154,8 +154,8 @@ describe Dashboard::Mailer do let!(:proposal) { build(:proposal, :draft) } - it "Disables email delivery using setting" do - Setting["dashboard.emails"] = nil + it "Disables notification email delivery using setting" do + Setting["feature.dashboard.notification_emails"] = nil action.update!(published_proposal: false) resource.update!(published_proposal: false) @@ -220,8 +220,8 @@ describe Dashboard::Mailer do let!(:proposal) { build(:proposal, :draft) } - it "Disables email delivery using setting" do - Setting["dashboard.emails"] = nil + it "Disables notification email delivery using setting" do + Setting["feature.dashboard.notification_emails"] = nil proposal.save! proposal.publish diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index 416a2ceff..a510938cd 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -983,7 +983,7 @@ describe Proposal do describe "#send_new_actions_notification_on_create" do before do - Setting["dashboard.emails"] = true + Setting["feature.dashboard.notification_emails"] = true ActionMailer::Base.deliveries.clear end @@ -1008,7 +1008,7 @@ describe Proposal do describe "#send_new_actions_notification_on_published" do before do - Setting["dashboard.emails"] = true + Setting["feature.dashboard.notification_emails"] = true ActionMailer::Base.deliveries.clear end From b9792241ca411d386e503a5ffd64ad8e773131ac Mon Sep 17 00:00:00 2001 From: taitus Date: Wed, 29 Jan 2020 16:15:49 +0100 Subject: [PATCH 3/4] Allow always send forward email The new key only block notifications emails from Dashboard::Mailer. Fix specs. --- app/mailers/dashboard/mailer.rb | 2 +- spec/mailers/dashboard/mailer_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/mailers/dashboard/mailer.rb b/app/mailers/dashboard/mailer.rb index f90b683d5..669e51815 100644 --- a/app/mailers/dashboard/mailer.rb +++ b/app/mailers/dashboard/mailer.rb @@ -1,6 +1,6 @@ class Dashboard::Mailer < ApplicationMailer layout "mailer" - after_action :check_deliverability + after_action :check_deliverability, except: [:forward] def forward(proposal) @proposal = proposal diff --git a/spec/mailers/dashboard/mailer_spec.rb b/spec/mailers/dashboard/mailer_spec.rb index 812c3cfe5..1464d6872 100644 --- a/spec/mailers/dashboard/mailer_spec.rb +++ b/spec/mailers/dashboard/mailer_spec.rb @@ -20,12 +20,12 @@ describe Dashboard::Mailer do ActionMailer::Base.deliveries.clear end - it "Disables email delivery using setting" do + it "Disables notification emails delivery using setting, does not affect the forward email" do Setting["feature.dashboard.notification_emails"] = nil Dashboard::Mailer.forward(proposal).deliver_now - expect(ActionMailer::Base.deliveries.count).to eq(0) + expect(ActionMailer::Base.deliveries.count).to eq(1) end it "sends forward email" do From 4bb194e1cc2f84b82ed6d73f1e4944467cdbfd3e Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 18 Feb 2020 17:12:55 +0100 Subject: [PATCH 4/4] Recover rake "settings:rename_setting_keys" We need to add :rename_setting_keys before :add_new_settings task. This way the value of the old key will not be lost. --- lib/tasks/consul.rake | 4 +++- lib/tasks/settings.rake | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tasks/consul.rake b/lib/tasks/consul.rake index fea722ae5..4116a8fd0 100644 --- a/lib/tasks/consul.rake +++ b/lib/tasks/consul.rake @@ -1,6 +1,8 @@ namespace :consul do desc "Runs tasks needed to upgrade to the latest version" - task execute_release_tasks: ["settings:add_new_settings", "execute_release_1.1.0_tasks"] + task execute_release_tasks: ["settings:rename_setting_keys", + "settings:add_new_settings", + "execute_release_1.1.0_tasks"] desc "Runs tasks needed to upgrade from 1.0.0 to 1.1.0" task "execute_release_1.1.0_tasks": [ diff --git a/lib/tasks/settings.rake b/lib/tasks/settings.rake index c434180ba..1aa570082 100644 --- a/lib/tasks/settings.rake +++ b/lib/tasks/settings.rake @@ -4,4 +4,10 @@ namespace :settings do ApplicationLogger.new.info "Adding new settings" Setting.add_new_settings end + + desc "Rename existing settings" + task rename_setting_keys: :environment do + ApplicationLogger.new.info "Renaming existing settings" + Setting.rename_key from: "dashboard.emails", to: "feature.dashboard.notification_emails" + end end