From 887bcb536e439854511fea06380ff82a40cfbf3d Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 25 Sep 2024 10:41:11 +0200 Subject: [PATCH 01/10] Jointly notify the import of proposals and answers --- .../admin/import/importer_decorator.rb | 35 +++++++ .../proposal_answer_creator_decorator.rb | 14 +++ .../import/proposal_creator_decorator.rb | 12 +++ app/mailers/proposals_answers_mailer.rb | 25 +++++ app/mailers/proposals_mailer.rb | 25 +++++ .../notify_massive_import.html.erb | 4 + .../notify_massive_import.html.erb | 4 + config/locales/ca_proposals.yml | 12 +++ config/locales/en_proposals.yml | 12 +++ config/locales/es_proposals.yml | 14 ++- config/locales/oc_proposals.yml | 10 ++ .../config/locales/ca.yml | 3 + lib/assets/import_answers.csv | 4 + .../admin/import/importer_decorator_spec.rb | 94 +++++++++++++++++++ .../import/proposal_answer_creator_spec.rb | 63 +++++++++++++ .../import/proposal_creator_decorator_spec.rb | 63 +++++++++++++ spec/shared/proposal_importer_examples.rb | 54 +++++++++++ 17 files changed, 447 insertions(+), 1 deletion(-) create mode 100644 app/decorators/decidim/admin/import/importer_decorator.rb create mode 100644 app/decorators/decidim/proposals/import/proposal_answer_creator_decorator.rb create mode 100644 app/decorators/decidim/proposals/import/proposal_creator_decorator.rb create mode 100644 app/mailers/proposals_answers_mailer.rb create mode 100644 app/mailers/proposals_mailer.rb create mode 100644 app/views/proposals_answers_mailer/notify_massive_import.html.erb create mode 100644 app/views/proposals_mailer/notify_massive_import.html.erb create mode 100644 lib/assets/import_answers.csv create mode 100644 spec/decorators/decidim/admin/import/importer_decorator_spec.rb create mode 100644 spec/decorators/decidim/proposals/import/proposal_answer_creator_spec.rb create mode 100644 spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb create mode 100644 spec/shared/proposal_importer_examples.rb diff --git a/app/decorators/decidim/admin/import/importer_decorator.rb b/app/decorators/decidim/admin/import/importer_decorator.rb new file mode 100644 index 00000000..96c53861 --- /dev/null +++ b/app/decorators/decidim/admin/import/importer_decorator.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +Decidim::Admin::Import::Importer.class_eval do + def import! + finished_collection = collection.map { |elem| object_to_manage_without_notify_uniquely?(elem) ? elem.finish_without_notif! : elem.finish! } + if collection.any? { |elem| elem.is_a? Decidim::Proposals::Import::ProposalCreator } + notify_collection(finished_collection, :proposals) + elsif collection.any? { |elem| elem.is_a? Decidim::Proposals::Import::ProposalAnswerCreator } + notify_collection(finished_collection, :answers) + end + end + + def notify_collection(collection, type) + recipients = collection.map { |elem| elem.participatory_space.followers.uniq }.flatten.uniq + case type + when :proposals + recipients.each do |recipient| + next unless ["all", "followed-only"].include?(recipient.notification_types) + + ProposalsMailer.notify_massive_import(collection, recipient).deliver_now + end + when :answers + recipients.each do |recipient| + next unless ["all", "followed-only"].include?(recipient.notification_types) + + ProposalsAnswersMailer.notify_massive_import(collection, recipient).deliver_now + end + end + end + + def object_to_manage_without_notify_uniquely?(obj) + # These types of object must be notified in group, not uniquely + [Decidim::Proposals::Import::ProposalCreator, Decidim::Proposals::Import::ProposalAnswerCreator].include? obj.class + end +end diff --git a/app/decorators/decidim/proposals/import/proposal_answer_creator_decorator.rb b/app/decorators/decidim/proposals/import/proposal_answer_creator_decorator.rb new file mode 100644 index 00000000..fb9564e7 --- /dev/null +++ b/app/decorators/decidim/proposals/import/proposal_answer_creator_decorator.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +Decidim::Proposals::Import::ProposalAnswerCreator.class_eval do + def finish_without_notif! + Decidim.traceability.perform_action!( + "answer", + resource, + current_user + ) do + resource.try(:save!) + end + resource + end +end diff --git a/app/decorators/decidim/proposals/import/proposal_creator_decorator.rb b/app/decorators/decidim/proposals/import/proposal_creator_decorator.rb new file mode 100644 index 00000000..347b24f7 --- /dev/null +++ b/app/decorators/decidim/proposals/import/proposal_creator_decorator.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +Decidim::Proposals::Import::ProposalCreator.class_eval do + def finish_without_notif! + Decidim.traceability.perform_action!(:create, self.class.resource_klass, context[:current_user], visibility: "admin-only") do + resource.save! + resource + end + publish(resource) + resource + end +end diff --git a/app/mailers/proposals_answers_mailer.rb b/app/mailers/proposals_answers_mailer.rb new file mode 100644 index 00000000..933a30ea --- /dev/null +++ b/app/mailers/proposals_answers_mailer.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class ProposalsAnswersMailer < ApplicationMailer + include Decidim::SanitizeHelper + include Decidim::ComponentPathHelper + + layout "decidim/mailer" + + def notify_massive_import(answers_collection, user) + @organization = user.organization + @participatory_space_title = decidim_sanitize_translated(answers_collection.first.participatory_space.title) if answers_collection.first.present? + @user = user + @component_url = manage_component_url(answers_collection.first.component) + I18n.locale = user.locale if user.locale.present? + + subject = I18n.t("proposals_answers_publisheds_for_space.email_subject", scope: "decidim.events.proposals", participatory_space_title: @participatory_space_title) + mail(to: user, subject: subject) + end + + private + + def manage_component_url(component) + Decidim::EngineRouter.main_proxy(component).root_url + end +end diff --git a/app/mailers/proposals_mailer.rb b/app/mailers/proposals_mailer.rb new file mode 100644 index 00000000..f710a851 --- /dev/null +++ b/app/mailers/proposals_mailer.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class ProposalsMailer < ApplicationMailer + include Decidim::SanitizeHelper + include Decidim::ComponentPathHelper + + layout "decidim/mailer" + + def notify_massive_import(proposals_collection, user) + @organization = user.organization + @participatory_space_title = decidim_sanitize_translated(proposals_collection.first.participatory_space.title) if proposals_collection.first.present? + @user = user + @component_url = manage_component_url(proposals_collection.first.component) + I18n.locale = user.locale if user.locale.present? + + subject = I18n.t("proposals_publisheds_for_space.email_subject", scope: "decidim.events.proposals", participatory_space_title: @participatory_space_title) + mail(to: user.email, subject: subject) + end + + private + + def manage_component_url(component) + Decidim::EngineRouter.main_proxy(component).root_url + end +end diff --git a/app/views/proposals_answers_mailer/notify_massive_import.html.erb b/app/views/proposals_answers_mailer/notify_massive_import.html.erb new file mode 100644 index 00000000..ccd5e926 --- /dev/null +++ b/app/views/proposals_answers_mailer/notify_massive_import.html.erb @@ -0,0 +1,4 @@ +

<%= I18n.t("decidim.events.email_event.email_greeting", user_name: @user.name) %>

+

<%= I18n.t("decidim.events.proposals.proposals_answers_publisheds_for_space.email_intro", participatory_space_title: @participatory_space_title).html_safe %>

+

<%= I18n.t("decidim.events.proposals.proposals_answers_publisheds_for_space.email_link", participatory_space_url: @component_url).html_safe %>

+

<%= I18n.t("decidim.events.proposals.proposals_answers_publisheds_for_space.email_outro", participatory_space_title: @participatory_space_title) %>

diff --git a/app/views/proposals_mailer/notify_massive_import.html.erb b/app/views/proposals_mailer/notify_massive_import.html.erb new file mode 100644 index 00000000..6c4d97be --- /dev/null +++ b/app/views/proposals_mailer/notify_massive_import.html.erb @@ -0,0 +1,4 @@ +

<%= I18n.t("decidim.events.email_event.email_greeting", user_name: @user.name) %>

+

<%= I18n.t("decidim.events.proposals.proposals_publisheds_for_space.email_intro", participatory_space_title: @participatory_space_title).html_safe %>

+

<%= I18n.t("decidim.events.proposals.proposals_publisheds_for_space.email_link", participatory_space_url: @component_url).html_safe %>

+

<%= I18n.t("decidim.events.proposals.proposals_publisheds_for_space.email_outro", participatory_space_title: @participatory_space_title) %>

diff --git a/config/locales/ca_proposals.yml b/config/locales/ca_proposals.yml index 1dad909e..f632a1f4 100644 --- a/config/locales/ca_proposals.yml +++ b/config/locales/ca_proposals.yml @@ -14,6 +14,18 @@ ca: step: endorsements_blocked: Adhesions bloquejades endorsements_enabled: Adhesions habilitades + events: + proposals: + proposals_answers_publisheds_for_space: + email_intro: S'ha donat resposta a propostes de l'espai "%{participatory_space_title}". + email_link: "Pots llegir les respostes des d'aquesta pàgina: enllaç." + email_outro: Has rebut aquesta notificació perquè estas seguint l'espai "%{participatory_space_title}". Pots deixar de rebre notificacions seguint l'enllaç anterior. + email_subject: Noves respostes a propostes de %{participatory_space_title} + proposals_publisheds_for_space: + email_intro: S'han afegit noves propostes a l'espai "%{participatory_space_title}". + email_link: Pots veure les noves propostes seguint aquest enllaç. + email_outro: Has rebut aquesta notificació perquè estas seguint l'espai "%{participatory_space_title}". Pots deixar de rebre notificacions seguint l'enllaç anterior. + email_subject: Noves propostes afegides a %{participatory_space_title} proposals: application_helper: filter_type_values: diff --git a/config/locales/en_proposals.yml b/config/locales/en_proposals.yml index c2f1d27f..4197fb35 100644 --- a/config/locales/en_proposals.yml +++ b/config/locales/en_proposals.yml @@ -1,6 +1,18 @@ --- en: decidim: + events: + proposals: + proposals_answers_publisheds_for_space: + email_intro: Proposals have been answered in the "%{participatory_space_title}" space. + email_link: "You can read the answers from this page: link." + email_outro: You have received this notification because you are following "%{participatory_space_title}". You can unfollow it from the previous link. + email_subject: New responses to proposals in %{participatory_space_title} + proposals_publisheds_for_space: + email_intro: New proposals has been added to "%{participatory_space_title}". + email_link: You can see the new proposals by following this link. + email_outro: You have received this notification because you are following "%{participatory_space_title}". You can unfollow it from the previous link. + email_subject: New proposals added to %{participatory_space_title} proposals: proposals: show: diff --git a/config/locales/es_proposals.yml b/config/locales/es_proposals.yml index d75a5ba1..a24c9e12 100644 --- a/config/locales/es_proposals.yml +++ b/config/locales/es_proposals.yml @@ -1,7 +1,19 @@ --- es: decidim: + events: + proposals: + proposals_answers_publisheds_for_space: + email_intro: Se ha dado respuesta a propuestas del espacio "%{participatory_space_title}". + email_link: "Puedes leer las respuestas desde esta página: enlace." + email_outro: Has recibido esta notificación porque estas siguiendo el espacio "%{participatory_space_title}". Puedes dejar de recibir notificaciones siguiendo el enlace anterior. + email_subject: Nuevas respuestas a propuestas de %{participatory_space_title} + proposals_publisheds_for_space: + email_intro: Se han añadido nuevas propuestas al espacio "%{participatory_space_title}". + email_link: Puedes ver las nuevas propuestas siguiendo este enlace. + email_outro: Has recibido esta notificación porque estas siguiendo el espacio "%{participatory_space_title}". Puedes dejar de recibir notificaciones siguiendo el enlace anterior. + email_subject: Nuevas propuestas añadidas a %{participatory_space_title} proposals: proposals: show: - proposal_in_evaluation_reason: 'Esta propuesta está en evaluación porque:' \ No newline at end of file + proposal_in_evaluation_reason: 'Esta propuesta está en evaluación porque:' diff --git a/config/locales/oc_proposals.yml b/config/locales/oc_proposals.yml index 8cfbb685..722aee0a 100644 --- a/config/locales/oc_proposals.yml +++ b/config/locales/oc_proposals.yml @@ -255,6 +255,16 @@ oc: email_outro: Has rebut aquesta notificació perquè estàs seguint "%{participatory_space_title}". Pots deixar de rebre notificacions seguint l'enllaç anterior. email_subject: Nova proposta "%{resource_title}" afegida a %{participatory_space_title} notification_title: La proposta %{resource_title} s'ha afegit a %{participatory_space_title} + proposals_answers_publisheds_for_space: + email_intro: S'a dat responsa a prepauses der espaci "%{participatory_space_title}". + email_link: "Pòdes liéger es responses dempús d'aguesta pagina: ligam." + email_outro: As arrecebut aguesta notificacion pr'amor qu'estas en tot seguir er espaci "%{participatory_space_title}". Pòdes quitar d'arrecéber notificacions en tot seguir eth ligam anterior. + email_subject: Naues responses a prepauses en %{participatory_space_title} + proposals_publisheds_for_space: + email_intro: S'han ahijut naues prepauses ar espaci "%{participatory_space_title}", que seguisses. + email_link: Pòdes veir es naues prepauses en tot seguir aguest lligam. + email_outro: As arrecebut aguesta notificacion pr'amor qu'estas en tot seguir er espaci "%{participatory_space_title}". Pòdes quitar d'arrecéber notificacions en tot seguir eth ligam anterior. + email_subject: Naues prepauses ahijudes en %{participatory_space_title} proposal_rejected: affected_user: email_intro: 'La teva proposta "%{resource_title}" ha estat rebutjada. Pots llegir la resposta en aquesta pàgina:' diff --git a/decidim-process-extended/config/locales/ca.yml b/decidim-process-extended/config/locales/ca.yml index 6eaaab98..06d6e10f 100644 --- a/decidim-process-extended/config/locales/ca.yml +++ b/decidim-process-extended/config/locales/ca.yml @@ -47,6 +47,9 @@ ca: left: Restant title: Té %{limit} suports a distribuir votes: Suports + events: + publish_proposals_event: + email_intro: S'han afegit noves propostes a l'espai "%{resource_title}". Pots veure les noves propostes seguint aquest enllaç. activemodel: attributes: participatory_process: diff --git a/lib/assets/import_answers.csv b/lib/assets/import_answers.csv new file mode 100644 index 00000000..c7b6e0d1 --- /dev/null +++ b/lib/assets/import_answers.csv @@ -0,0 +1,4 @@ +id;state;answer/ca;answer/es;answer/oc;answer/en +89117;accepted;Example answer;Example answer;Example answer;Example answer +89117;rejected;Example answer;Example answer;Example answer;Example answer +89117;evaluating;Example answer;Example answer;Example answer;Example answer diff --git a/spec/decorators/decidim/admin/import/importer_decorator_spec.rb b/spec/decorators/decidim/admin/import/importer_decorator_spec.rb new file mode 100644 index 00000000..18813046 --- /dev/null +++ b/spec/decorators/decidim/admin/import/importer_decorator_spec.rb @@ -0,0 +1,94 @@ +# frozen_string_literal: true + +require "rails_helper" +require "decidim/proposals/import/proposal_creator_decorator" +# require 'spec/shared/proposal_importer_examples' + +describe Decidim::Admin::Import::Importer do + subject { described_class.new(file: blob, reader: reader, creator: creator, context: context) } + + let(:organization) { create(:organization, available_locales: [:en]) } + let(:user) { create(:user, organization: organization) } + let(:follower) { create(:user, organization: organization, notification_types: "all") } + let(:context) do + { + current_organization: organization, + current_user: user, + current_component: current_component, + current_participatory_space: participatory_process + } + end + let(:participatory_process) { create :participatory_process, organization: organization } + let(:current_component) { create :component, manifest_name: :proposals, participatory_space: participatory_process } + + describe "#import!" do + context "when imported collection are proposals" do + let(:creator) { Decidim::Proposals::Import::ProposalCreator } + let(:blob) { upload_test_file(Decidim::Dev.asset("import_proposals.csv"), return_blob: true) } + let(:reader) { Decidim::Admin::Import::Readers::CSV } + + it_behaves_like "proposal importer" + + it "will execute notify_collection method" do + subject.prepare + expect(subject).to receive(:notify_collection) + subject.import! + end + end + + context "when imported collection are answers proposals" do + let!(:proposal_component) { create(:proposal_component, organization: organization) } + let!(:proposal) { create(:proposal, component: proposal_component, id: 89_117) } + let(:creator) { Decidim::Proposals::Import::ProposalAnswerCreator } + let(:blob) { upload_test_file(Rails.root.join("lib", "assets", "import_answers.csv").to_s, return_blob: true) } + let(:reader) { Decidim::Admin::Import::Readers::CSV } + + it "will execute notify_collection method" do + subject.prepare + expect(subject).to receive(:notify_collection) + subject.import! + end + end + end + + describe "#notify_collection" do + context "when imported collection are proposals" do + let(:creator) { Decidim::Proposals::Import::ProposalCreator } + let(:blob) { upload_test_file(Decidim::Dev.asset("import_proposals.csv"), return_blob: true) } + let(:reader) { Decidim::Admin::Import::Readers::CSV } + + before do + participatory_process.followers << follower + ActionMailer::Base.deliveries.clear + allow(ProposalsMailer).to receive(:notify_massive_import).and_call_original + end + + it_behaves_like "proposal importer" + + it "will call ProposalsMailer.notify_massive_import with the collection" do + subject.prepare + subject.import! + expect(ProposalsMailer).to have_received(:notify_massive_import) + end + end + + context "when imported collection are answers proposals" do + let!(:proposal) { create(:proposal, :evaluating, component: current_component, id: 89_117) } + let(:creator) { Decidim::Proposals::Import::ProposalAnswerCreator } + let(:blob) { upload_test_file(Rails.root.join("lib", "assets", "import_answers.csv").to_s, return_blob: true) } + let(:reader) { Decidim::Admin::Import::Readers::CSV } + + before do + participatory_process.followers << follower + ActionMailer::Base.deliveries.clear + allow(ProposalsAnswersMailer).to receive(:notify_massive_import).and_call_original + end + + it "will call ProposalsMailer.notify_massive_import with the collection" do + subject.prepare + subject.import! + expect(ProposalsAnswersMailer).to have_received(:notify_massive_import) + end + end + end +end diff --git a/spec/decorators/decidim/proposals/import/proposal_answer_creator_spec.rb b/spec/decorators/decidim/proposals/import/proposal_answer_creator_spec.rb new file mode 100644 index 00000000..5e34aec1 --- /dev/null +++ b/spec/decorators/decidim/proposals/import/proposal_answer_creator_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require "rails_helper" +require "decidim/proposals/import/proposal_answer_creator" + +describe Decidim::Proposals::Import::ProposalAnswerCreator do + subject { described_class.new(data, context) } + + let(:proposal) { create(:proposal, state: state, component: component) } + let!(:moment) { Time.current } + let(:data) do + { + id: proposal.id, + state: state, + "answer/en": Faker::Lorem.paragraph + } + end + let(:organization) { create(:organization, available_locales: [:en]) } + let(:user) { create(:user, organization: organization) } + let(:context) do + { + current_organization: organization, + current_user: user, + current_component: component, + current_participatory_space: participatory_process + } + end + let(:participatory_process) { create :participatory_process, organization: organization } + let(:component) { create :component, manifest_name: :proposals, participatory_space: participatory_process } + let(:state) { %w(evaluating accepted rejected).sample } + + describe "#finish_without_notif!" do + it "saves the answer proposal" do + record = subject.produce + subject.finish! + expect(record.new_record?).to be(false) + end + + it "creates an admin log record" do + record = subject.produce + subject.finish! + + log = Decidim::ActionLog.last + expect(log.resource).to eq(record) + expect(log.action).to eq("answer") + end + + it "does not notify the import with ActiveSupport::Notifications" do + subject.produce + subject.finish_without_notif! + expect(subject).not_to receive(:notify) + end + + context "when proposal state changes" do + let!(:proposal) { create(:proposal, :evaluating, component: component) } + let(:state) { "accepted" } + + it "returns broadcast :ok" do + expect(subject.finish!).to eq({ ok: [] }) + end + end + end +end diff --git a/spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb b/spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb new file mode 100644 index 00000000..a0b8c2b5 --- /dev/null +++ b/spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require "rails_helper" +require "decidim/proposals/import/proposal_creator" + +describe Decidim::Proposals::Import::ProposalCreator do + subject { described_class.new(data, context) } + + let!(:moment) { Time.current } + let(:data) do + { + id: 1337, + "id" => "101", + category: category, + scope: scope, + :"title/en" => Faker::Lorem.sentence, + :"body/en" => Faker::Lorem.paragraph(sentence_count: 3), + address: "#{Faker::Address.street_name}, #{Faker::Address.city}", + latitude: Faker::Address.latitude, + longitude: Faker::Address.longitude, + component: component, + published_at: moment + } + end + let(:organization) { create(:organization, available_locales: [:en]) } + let(:user) { create(:user, organization: organization) } + let(:context) do + { + current_organization: organization, + current_user: user, + current_component: component, + current_participatory_space: participatory_process + } + end + let(:participatory_process) { create :participatory_process, organization: organization } + let(:component) { create :component, manifest_name: :proposals, participatory_space: participatory_process } + let(:scope) { create :scope, organization: organization } + let(:category) { create :category, participatory_space: participatory_process } + + describe "#finish_without_notif!" do + context "when a proposals file are created" do + it "saves the proposal" do + record = subject.produce + subject.finish! + expect(record.new_record?).to be(false) + end + + it "creates admin log" do + record = subject.produce + expect { subject.finish! }.to change(Decidim::ActionLog, :count).by(1) + expect(Decidim::ActionLog.last.user).to eq(user) + expect(Decidim::ActionLog.last.resource).to eq(record) + expect(Decidim::ActionLog.last.visibility).to eq("admin-only") + end + + it "does not notify the import with ActiveSupport::Notifications" do + subject.produce + subject.finish_without_notif! + expect(subject).not_to receive(:notify) + end + end + end +end diff --git a/spec/shared/proposal_importer_examples.rb b/spec/shared/proposal_importer_examples.rb new file mode 100644 index 00000000..29345e7b --- /dev/null +++ b/spec/shared/proposal_importer_examples.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +shared_context "with proposal import data" do + let(:expected_data) do + [ + { + title: { + "en" => "Esse qui. Ut." + }, + body: { + "en" => "Aliquid in ut. Laboriosam consequatur consequatur. Unde dolorem omnis. +Et earum aut. Quis enim quis. Dolore corporis et. Quia vel ex." + }, + component: current_component + }, + { + title: { + "en" => "Nihil id." + }, + body: { + "en" => "Atque qui aut. Quia et incidunt. Qui nihil dolore. +Delectus asperiores nihil. Sapiente omnis culpa. Eos at voluptatem." + }, + component: current_component + }, + { + title: { + "en" => "Suspendisse lobortis" + }, + body: { + "en" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit." + }, + component: current_component + } + ] + end +end + +shared_examples "proposal importer" do + include_context "with proposal import data" + + describe "#collection" do + it "creates a collection of creators" do + expect(subject.collection.length).to be(3) + + # Check that produced data matches with expected data + expected_data.each_with_index do |data, index| + data.each do |key, value| + expect(subject.collection[index].produce.send(key)).to eq(value) + end + end + end + end +end From 6e525e380042de603b220c37158f6f09480f8e58 Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 25 Sep 2024 11:53:51 +0200 Subject: [PATCH 02/10] Add modifications on code according to review suggestions --- app/decorators/decidim/admin/import/importer_decorator.rb | 4 ++-- app/mailers/proposals_answers_mailer.rb | 7 ++++--- app/mailers/proposals_mailer.rb | 7 ++++--- .../notify_massive_import.html.erb | 6 +++--- app/views/proposals_mailer/notify_massive_import.html.erb | 6 +++--- config/locales/ca_proposals.yml | 4 ++-- config/locales/en_proposals.yml | 4 ++-- config/locales/es_proposals.yml | 4 ++-- config/locales/oc_proposals.yml | 4 ++-- decidim-process-extended/config/locales/en.yml | 3 +++ decidim-process-extended/config/locales/es.yml | 3 +++ decidim-process-extended/config/locales/oc.yml | 3 +++ .../decidim/admin/import/importer_decorator_spec.rb | 1 - 13 files changed, 33 insertions(+), 23 deletions(-) diff --git a/app/decorators/decidim/admin/import/importer_decorator.rb b/app/decorators/decidim/admin/import/importer_decorator.rb index 96c53861..db2216c5 100644 --- a/app/decorators/decidim/admin/import/importer_decorator.rb +++ b/app/decorators/decidim/admin/import/importer_decorator.rb @@ -17,13 +17,13 @@ def notify_collection(collection, type) recipients.each do |recipient| next unless ["all", "followed-only"].include?(recipient.notification_types) - ProposalsMailer.notify_massive_import(collection, recipient).deliver_now + ProposalsMailer.notify_massive_import(collection, recipient).deliver_later end when :answers recipients.each do |recipient| next unless ["all", "followed-only"].include?(recipient.notification_types) - ProposalsAnswersMailer.notify_massive_import(collection, recipient).deliver_now + ProposalsAnswersMailer.notify_massive_import(collection, recipient).deliver_later end end end diff --git a/app/mailers/proposals_answers_mailer.rb b/app/mailers/proposals_answers_mailer.rb index 933a30ea..f778ff45 100644 --- a/app/mailers/proposals_answers_mailer.rb +++ b/app/mailers/proposals_answers_mailer.rb @@ -8,12 +8,13 @@ class ProposalsAnswersMailer < ApplicationMailer def notify_massive_import(answers_collection, user) @organization = user.organization - @participatory_space_title = decidim_sanitize_translated(answers_collection.first.participatory_space.title) if answers_collection.first.present? + first_answer = answers_collection.first + @participatory_space_title = decidim_sanitize_translated(first_answer.participatory_space.title) if first_answer.present? @user = user - @component_url = manage_component_url(answers_collection.first.component) + @component_url = manage_component_url(first_answer.component) I18n.locale = user.locale if user.locale.present? - subject = I18n.t("proposals_answers_publisheds_for_space.email_subject", scope: "decidim.events.proposals", participatory_space_title: @participatory_space_title) + subject = I18n.t("proposals_answers_imported.email_subject", scope: "decidim.events.proposals", participatory_space_title: @participatory_space_title) mail(to: user, subject: subject) end diff --git a/app/mailers/proposals_mailer.rb b/app/mailers/proposals_mailer.rb index f710a851..100f6979 100644 --- a/app/mailers/proposals_mailer.rb +++ b/app/mailers/proposals_mailer.rb @@ -8,12 +8,13 @@ class ProposalsMailer < ApplicationMailer def notify_massive_import(proposals_collection, user) @organization = user.organization - @participatory_space_title = decidim_sanitize_translated(proposals_collection.first.participatory_space.title) if proposals_collection.first.present? + first_proposal = proposals_collection.first + @participatory_space_title = decidim_sanitize_translated(first_proposal.participatory_space.title) if first_proposal.present? @user = user - @component_url = manage_component_url(proposals_collection.first.component) + @component_url = manage_component_url(first_proposal.component) I18n.locale = user.locale if user.locale.present? - subject = I18n.t("proposals_publisheds_for_space.email_subject", scope: "decidim.events.proposals", participatory_space_title: @participatory_space_title) + subject = I18n.t("proposals_imported.email_subject", scope: "decidim.events.proposals", participatory_space_title: @participatory_space_title) mail(to: user.email, subject: subject) end diff --git a/app/views/proposals_answers_mailer/notify_massive_import.html.erb b/app/views/proposals_answers_mailer/notify_massive_import.html.erb index ccd5e926..b006060b 100644 --- a/app/views/proposals_answers_mailer/notify_massive_import.html.erb +++ b/app/views/proposals_answers_mailer/notify_massive_import.html.erb @@ -1,4 +1,4 @@ - - - + + + diff --git a/app/views/proposals_mailer/notify_massive_import.html.erb b/app/views/proposals_mailer/notify_massive_import.html.erb index 6c4d97be..c08dd09c 100644 --- a/app/views/proposals_mailer/notify_massive_import.html.erb +++ b/app/views/proposals_mailer/notify_massive_import.html.erb @@ -1,4 +1,4 @@ - - - + + + diff --git a/config/locales/ca_proposals.yml b/config/locales/ca_proposals.yml index f632a1f4..3e4a0e9c 100644 --- a/config/locales/ca_proposals.yml +++ b/config/locales/ca_proposals.yml @@ -16,12 +16,12 @@ ca: endorsements_enabled: Adhesions habilitades events: proposals: - proposals_answers_publisheds_for_space: + proposals_answers_imported: email_intro: S'ha donat resposta a propostes de l'espai "%{participatory_space_title}". email_link: "Pots llegir les respostes des d'aquesta pàgina: enllaç." email_outro: Has rebut aquesta notificació perquè estas seguint l'espai "%{participatory_space_title}". Pots deixar de rebre notificacions seguint l'enllaç anterior. email_subject: Noves respostes a propostes de %{participatory_space_title} - proposals_publisheds_for_space: + proposals_imported: email_intro: S'han afegit noves propostes a l'espai "%{participatory_space_title}". email_link: Pots veure les noves propostes seguint aquest enllaç. email_outro: Has rebut aquesta notificació perquè estas seguint l'espai "%{participatory_space_title}". Pots deixar de rebre notificacions seguint l'enllaç anterior. diff --git a/config/locales/en_proposals.yml b/config/locales/en_proposals.yml index 4197fb35..9003c059 100644 --- a/config/locales/en_proposals.yml +++ b/config/locales/en_proposals.yml @@ -3,12 +3,12 @@ en: decidim: events: proposals: - proposals_answers_publisheds_for_space: + proposals_answers_imported: email_intro: Proposals have been answered in the "%{participatory_space_title}" space. email_link: "You can read the answers from this page: link." email_outro: You have received this notification because you are following "%{participatory_space_title}". You can unfollow it from the previous link. email_subject: New responses to proposals in %{participatory_space_title} - proposals_publisheds_for_space: + proposals_imported: email_intro: New proposals has been added to "%{participatory_space_title}". email_link: You can see the new proposals by following this link. email_outro: You have received this notification because you are following "%{participatory_space_title}". You can unfollow it from the previous link. diff --git a/config/locales/es_proposals.yml b/config/locales/es_proposals.yml index a24c9e12..4ee4cabe 100644 --- a/config/locales/es_proposals.yml +++ b/config/locales/es_proposals.yml @@ -3,12 +3,12 @@ es: decidim: events: proposals: - proposals_answers_publisheds_for_space: + proposals_answers_imported: email_intro: Se ha dado respuesta a propuestas del espacio "%{participatory_space_title}". email_link: "Puedes leer las respuestas desde esta página: enlace." email_outro: Has recibido esta notificación porque estas siguiendo el espacio "%{participatory_space_title}". Puedes dejar de recibir notificaciones siguiendo el enlace anterior. email_subject: Nuevas respuestas a propuestas de %{participatory_space_title} - proposals_publisheds_for_space: + proposals_imported: email_intro: Se han añadido nuevas propuestas al espacio "%{participatory_space_title}". email_link: Puedes ver las nuevas propuestas siguiendo este enlace. email_outro: Has recibido esta notificación porque estas siguiendo el espacio "%{participatory_space_title}". Puedes dejar de recibir notificaciones siguiendo el enlace anterior. diff --git a/config/locales/oc_proposals.yml b/config/locales/oc_proposals.yml index 722aee0a..14c972ef 100644 --- a/config/locales/oc_proposals.yml +++ b/config/locales/oc_proposals.yml @@ -255,12 +255,12 @@ oc: email_outro: Has rebut aquesta notificació perquè estàs seguint "%{participatory_space_title}". Pots deixar de rebre notificacions seguint l'enllaç anterior. email_subject: Nova proposta "%{resource_title}" afegida a %{participatory_space_title} notification_title: La proposta %{resource_title} s'ha afegit a %{participatory_space_title} - proposals_answers_publisheds_for_space: + proposals_answers_imported: email_intro: S'a dat responsa a prepauses der espaci "%{participatory_space_title}". email_link: "Pòdes liéger es responses dempús d'aguesta pagina: ligam." email_outro: As arrecebut aguesta notificacion pr'amor qu'estas en tot seguir er espaci "%{participatory_space_title}". Pòdes quitar d'arrecéber notificacions en tot seguir eth ligam anterior. email_subject: Naues responses a prepauses en %{participatory_space_title} - proposals_publisheds_for_space: + proposals_imported: email_intro: S'han ahijut naues prepauses ar espaci "%{participatory_space_title}", que seguisses. email_link: Pòdes veir es naues prepauses en tot seguir aguest lligam. email_outro: As arrecebut aguesta notificacion pr'amor qu'estas en tot seguir er espaci "%{participatory_space_title}". Pòdes quitar d'arrecéber notificacions en tot seguir eth ligam anterior. diff --git a/decidim-process-extended/config/locales/en.yml b/decidim-process-extended/config/locales/en.yml index bbbebcd5..9be5d4d9 100644 --- a/decidim-process-extended/config/locales/en.yml +++ b/decidim-process-extended/config/locales/en.yml @@ -47,6 +47,9 @@ en: left: Left title: You have %{limit} supports to distribute votes: Votes + events: + publish_proposals_event: + email_intro: New proposals has been added to "%{resource_title}". You can see the new proposals by following this link. activemodel: attributes: participatory_process: diff --git a/decidim-process-extended/config/locales/es.yml b/decidim-process-extended/config/locales/es.yml index 86d2c1d2..80c62554 100644 --- a/decidim-process-extended/config/locales/es.yml +++ b/decidim-process-extended/config/locales/es.yml @@ -47,6 +47,9 @@ es: left: Restante title: Tiene %{limit} soportes a distribuir votes: Soportes + events: + publish_proposals_event: + email_intro: Se han añadido nuevas propuestas al espacio "%{resource_title}. Puedes ver las nuevas propuestas siguiendo este enlace. activemodel: attributes: participatory_process: diff --git a/decidim-process-extended/config/locales/oc.yml b/decidim-process-extended/config/locales/oc.yml index b87100e3..4a1fc7a0 100644 --- a/decidim-process-extended/config/locales/oc.yml +++ b/decidim-process-extended/config/locales/oc.yml @@ -27,6 +27,9 @@ oc: application: attachments: meetings_available: Hi ha trobades programades actualment + events: + publish_proposals_event: + email_intro: S'han ahijut naues prepauses ar espaci "%{participatory_space_title}", que seguisses. Pòdes veir es naues prepauses en tot seguir aguest lligam. activemodel: attributes: participatory_process: diff --git a/spec/decorators/decidim/admin/import/importer_decorator_spec.rb b/spec/decorators/decidim/admin/import/importer_decorator_spec.rb index 18813046..5f1c0e79 100644 --- a/spec/decorators/decidim/admin/import/importer_decorator_spec.rb +++ b/spec/decorators/decidim/admin/import/importer_decorator_spec.rb @@ -2,7 +2,6 @@ require "rails_helper" require "decidim/proposals/import/proposal_creator_decorator" -# require 'spec/shared/proposal_importer_examples' describe Decidim::Admin::Import::Importer do subject { described_class.new(file: blob, reader: reader, creator: creator, context: context) } From 340e33202364df37c72599eca2d5df35ac603831 Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 25 Sep 2024 13:22:36 +0200 Subject: [PATCH 03/10] Modify decorators to updated version of zeitwek --- .../admin/import/importer_decorator.rb | 46 ++++++++----------- .../proposal_answer_creator_decorator.rb | 24 ++++++---- .../import/proposal_creator_decorator.rb | 20 +++++--- 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/app/decorators/decidim/admin/import/importer_decorator.rb b/app/decorators/decidim/admin/import/importer_decorator.rb index db2216c5..c7801230 100644 --- a/app/decorators/decidim/admin/import/importer_decorator.rb +++ b/app/decorators/decidim/admin/import/importer_decorator.rb @@ -1,35 +1,29 @@ # frozen_string_literal: true -Decidim::Admin::Import::Importer.class_eval do - def import! - finished_collection = collection.map { |elem| object_to_manage_without_notify_uniquely?(elem) ? elem.finish_without_notif! : elem.finish! } - if collection.any? { |elem| elem.is_a? Decidim::Proposals::Import::ProposalCreator } - notify_collection(finished_collection, :proposals) - elsif collection.any? { |elem| elem.is_a? Decidim::Proposals::Import::ProposalAnswerCreator } - notify_collection(finished_collection, :answers) - end - end - - def notify_collection(collection, type) - recipients = collection.map { |elem| elem.participatory_space.followers.uniq }.flatten.uniq - case type - when :proposals - recipients.each do |recipient| - next unless ["all", "followed-only"].include?(recipient.notification_types) +module Decidim::Admin::Import::ImporterDecorator + def self.decorate + Decidim::Admin::Import::Importer.class_eval do + def import! + finished_collection = collection.map { |elem| object_to_manage_without_notify_uniquely?(elem) ? elem.finish_without_notif! : elem.finish! } + notify_collection(finished_collection, collection.first) + end - ProposalsMailer.notify_massive_import(collection, recipient).deliver_later + def notify_collection(collection, klass) + recipients = collection.flat_map { |elem| elem.participatory_space.followers.where(notification_types: %w(all followed-only)).uniq }.uniq + case klass + when Decidim::Proposals::Import::ProposalCreator + recipients.each { |recipient| ProposalsMailer.notify_massive_import(collection, recipient).deliver_later } + when Decidim::Proposals::Import::ProposalAnswerCreator + recipients.each { |recipient| ProposalsAnswersMailer.notify_massive_import(collection, recipient).deliver_later } + end end - when :answers - recipients.each do |recipient| - next unless ["all", "followed-only"].include?(recipient.notification_types) - ProposalsAnswersMailer.notify_massive_import(collection, recipient).deliver_later + def object_to_manage_without_notify_uniquely?(obj) + # These types of object must be notified in group, not uniquely + [Decidim::Proposals::Import::ProposalCreator, Decidim::Proposals::Import::ProposalAnswerCreator].include? obj.class end end end - - def object_to_manage_without_notify_uniquely?(obj) - # These types of object must be notified in group, not uniquely - [Decidim::Proposals::Import::ProposalCreator, Decidim::Proposals::Import::ProposalAnswerCreator].include? obj.class - end end + +::Decidim::Admin::Import::ImporterDecorator.decorate diff --git a/app/decorators/decidim/proposals/import/proposal_answer_creator_decorator.rb b/app/decorators/decidim/proposals/import/proposal_answer_creator_decorator.rb index fb9564e7..37a6f0aa 100644 --- a/app/decorators/decidim/proposals/import/proposal_answer_creator_decorator.rb +++ b/app/decorators/decidim/proposals/import/proposal_answer_creator_decorator.rb @@ -1,14 +1,20 @@ # frozen_string_literal: true -Decidim::Proposals::Import::ProposalAnswerCreator.class_eval do - def finish_without_notif! - Decidim.traceability.perform_action!( - "answer", - resource, - current_user - ) do - resource.try(:save!) +module Decidim::Proposals::Import::ProposalAnswerCreatorDecorator + def self.decorate + Decidim::Proposals::Import::ProposalAnswerCreator.class_eval do + def finish_without_notif! + Decidim.traceability.perform_action!( + "answer", + resource, + current_user + ) do + resource.try(:save!) + end + resource + end end - resource end end + +Decidim::Proposals::Import::ProposalAnswerCreatorDecorator.decorate diff --git a/app/decorators/decidim/proposals/import/proposal_creator_decorator.rb b/app/decorators/decidim/proposals/import/proposal_creator_decorator.rb index 347b24f7..f47c3d2e 100644 --- a/app/decorators/decidim/proposals/import/proposal_creator_decorator.rb +++ b/app/decorators/decidim/proposals/import/proposal_creator_decorator.rb @@ -1,12 +1,18 @@ # frozen_string_literal: true -Decidim::Proposals::Import::ProposalCreator.class_eval do - def finish_without_notif! - Decidim.traceability.perform_action!(:create, self.class.resource_klass, context[:current_user], visibility: "admin-only") do - resource.save! - resource +module Decidim::Proposals::Import::ProposalCreatorDecorator + def self.decorate + Decidim::Proposals::Import::ProposalCreator.class_eval do + def finish_without_notif! + Decidim.traceability.perform_action!(:create, self.class.resource_klass, context[:current_user], visibility: "admin-only") do + resource.save! + resource + end + publish(resource) + resource + end end - publish(resource) - resource end end + +::Decidim::Proposals::Import::ProposalCreatorDecorator.decorate From 02d8c38d7230ec3da96a3bc5458b259c1722fe42 Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 25 Sep 2024 14:32:02 +0200 Subject: [PATCH 04/10] Refactor importer decorator spec to avoid rubocop issue stub methods --- .../admin/import/importer_decorator_spec.rb | 35 ++----------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/spec/decorators/decidim/admin/import/importer_decorator_spec.rb b/spec/decorators/decidim/admin/import/importer_decorator_spec.rb index 5f1c0e79..39822115 100644 --- a/spec/decorators/decidim/admin/import/importer_decorator_spec.rb +++ b/spec/decorators/decidim/admin/import/importer_decorator_spec.rb @@ -19,42 +19,12 @@ end let(:participatory_process) { create :participatory_process, organization: organization } let(:current_component) { create :component, manifest_name: :proposals, participatory_space: participatory_process } - - describe "#import!" do - context "when imported collection are proposals" do - let(:creator) { Decidim::Proposals::Import::ProposalCreator } - let(:blob) { upload_test_file(Decidim::Dev.asset("import_proposals.csv"), return_blob: true) } - let(:reader) { Decidim::Admin::Import::Readers::CSV } - - it_behaves_like "proposal importer" - - it "will execute notify_collection method" do - subject.prepare - expect(subject).to receive(:notify_collection) - subject.import! - end - end - - context "when imported collection are answers proposals" do - let!(:proposal_component) { create(:proposal_component, organization: organization) } - let!(:proposal) { create(:proposal, component: proposal_component, id: 89_117) } - let(:creator) { Decidim::Proposals::Import::ProposalAnswerCreator } - let(:blob) { upload_test_file(Rails.root.join("lib", "assets", "import_answers.csv").to_s, return_blob: true) } - let(:reader) { Decidim::Admin::Import::Readers::CSV } - - it "will execute notify_collection method" do - subject.prepare - expect(subject).to receive(:notify_collection) - subject.import! - end - end - end + let(:reader) { Decidim::Admin::Import::Readers::CSV } describe "#notify_collection" do context "when imported collection are proposals" do let(:creator) { Decidim::Proposals::Import::ProposalCreator } let(:blob) { upload_test_file(Decidim::Dev.asset("import_proposals.csv"), return_blob: true) } - let(:reader) { Decidim::Admin::Import::Readers::CSV } before do participatory_process.followers << follower @@ -72,13 +42,12 @@ end context "when imported collection are answers proposals" do - let!(:proposal) { create(:proposal, :evaluating, component: current_component, id: 89_117) } let(:creator) { Decidim::Proposals::Import::ProposalAnswerCreator } let(:blob) { upload_test_file(Rails.root.join("lib", "assets", "import_answers.csv").to_s, return_blob: true) } - let(:reader) { Decidim::Admin::Import::Readers::CSV } before do participatory_process.followers << follower + create(:proposal, :evaluating, component: current_component, id: 89_117) ActionMailer::Base.deliveries.clear allow(ProposalsAnswersMailer).to receive(:notify_massive_import).and_call_original end From 1ae8ca067757873b861b7182fefb526524a5f60b Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 25 Sep 2024 14:32:16 +0200 Subject: [PATCH 05/10] Add schema update --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index af6df6b7..920511c2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_07_30_145314) do +ActiveRecord::Schema.define(version: 2024_09_05_140527) do # These are extensions that must be enabled in order to support this database enable_extension "ltree" From 59883acf07d26634c15bf7a2618f16933db49f08 Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 25 Sep 2024 14:37:55 +0200 Subject: [PATCH 06/10] Refactor decorators to avoid rubocop issue stub methods --- .../proposals/import/proposal_answer_creator_spec.rb | 6 ------ .../proposals/import/proposal_creator_decorator_spec.rb | 6 ------ 2 files changed, 12 deletions(-) diff --git a/spec/decorators/decidim/proposals/import/proposal_answer_creator_spec.rb b/spec/decorators/decidim/proposals/import/proposal_answer_creator_spec.rb index 5e34aec1..ba7bb9e1 100644 --- a/spec/decorators/decidim/proposals/import/proposal_answer_creator_spec.rb +++ b/spec/decorators/decidim/proposals/import/proposal_answer_creator_spec.rb @@ -45,12 +45,6 @@ expect(log.action).to eq("answer") end - it "does not notify the import with ActiveSupport::Notifications" do - subject.produce - subject.finish_without_notif! - expect(subject).not_to receive(:notify) - end - context "when proposal state changes" do let!(:proposal) { create(:proposal, :evaluating, component: component) } let(:state) { "accepted" } diff --git a/spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb b/spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb index a0b8c2b5..4f3b4b1d 100644 --- a/spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb +++ b/spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb @@ -52,12 +52,6 @@ expect(Decidim::ActionLog.last.resource).to eq(record) expect(Decidim::ActionLog.last.visibility).to eq("admin-only") end - - it "does not notify the import with ActiveSupport::Notifications" do - subject.produce - subject.finish_without_notif! - expect(subject).not_to receive(:notify) - end end end end From 88bb1626aca7a7ed8ba8fb2f05f638ac32b403fd Mon Sep 17 00:00:00 2001 From: Ivan Date: Wed, 25 Sep 2024 16:40:06 +0200 Subject: [PATCH 07/10] Unify syntax for proposal_creator_decorator_spec --- .../proposals/import/proposal_creator_decorator_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb b/spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb index 4f3b4b1d..98ee9698 100644 --- a/spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb +++ b/spec/decorators/decidim/proposals/import/proposal_creator_decorator_spec.rb @@ -10,11 +10,10 @@ let(:data) do { id: 1337, - "id" => "101", category: category, scope: scope, - :"title/en" => Faker::Lorem.sentence, - :"body/en" => Faker::Lorem.paragraph(sentence_count: 3), + "title/en": Faker::Lorem.sentence, + "body/en": Faker::Lorem.paragraph(sentence_count: 3), address: "#{Faker::Address.street_name}, #{Faker::Address.city}", latitude: Faker::Address.latitude, longitude: Faker::Address.longitude, From 9ce5c6e4250ef5c3a7985b277c967b5cda8d7ebe Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 26 Sep 2024 11:46:14 +0200 Subject: [PATCH 08/10] Modify mailer sender default --- app/mailers/application_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 5cc63a0c..61d626b2 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true class ApplicationMailer < ActionMailer::Base - default from: "from@example.com" + default from: Decidim.mailer_sender layout "mailer" end From 0483f334e72a92920a0635006f8aa74183bb1fbf Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 26 Sep 2024 12:50:01 +0200 Subject: [PATCH 09/10] Modifying mailer to on answers importer --- app/mailers/proposals_answers_mailer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mailers/proposals_answers_mailer.rb b/app/mailers/proposals_answers_mailer.rb index f778ff45..47aae758 100644 --- a/app/mailers/proposals_answers_mailer.rb +++ b/app/mailers/proposals_answers_mailer.rb @@ -15,7 +15,7 @@ def notify_massive_import(answers_collection, user) I18n.locale = user.locale if user.locale.present? subject = I18n.t("proposals_answers_imported.email_subject", scope: "decidim.events.proposals", participatory_space_title: @participatory_space_title) - mail(to: user, subject: subject) + mail(to: user.email, subject: subject) end private From 6d749b1db1b2e1b074bcc2cd3a32f5a38f32b861 Mon Sep 17 00:00:00 2001 From: Ivan Date: Thu, 26 Sep 2024 12:53:22 +0200 Subject: [PATCH 10/10] Remove publish for every proposal import process --- .../decidim/proposals/import/proposal_creator_decorator.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/decorators/decidim/proposals/import/proposal_creator_decorator.rb b/app/decorators/decidim/proposals/import/proposal_creator_decorator.rb index f47c3d2e..558aa0a0 100644 --- a/app/decorators/decidim/proposals/import/proposal_creator_decorator.rb +++ b/app/decorators/decidim/proposals/import/proposal_creator_decorator.rb @@ -8,7 +8,6 @@ def finish_without_notif! resource.save! resource end - publish(resource) resource end end