diff --git a/app/controllers/admin/system_emails_controller.rb b/app/controllers/admin/system_emails_controller.rb
index 689425569..f70c4bd53 100644
--- a/app/controllers/admin/system_emails_controller.rb
+++ b/app/controllers/admin/system_emails_controller.rb
@@ -14,7 +14,8 @@ class Admin::SystemEmailsController < Admin::BaseController
direct_message_for_receiver: %w[view edit_info],
direct_message_for_sender: %w[view edit_info],
email_verification: %w[view edit_info],
- user_invite: %w[view edit_info]
+ user_invite: %w[view edit_info],
+ evaluation_comment: %w[view edit_info]
}
end
@@ -34,6 +35,8 @@ class Admin::SystemEmailsController < Admin::BaseController
load_sample_user
when "user_invite"
@subject = t("mailers.user_invite.subject", org_name: Setting["org_name"])
+ when "evaluation_comment"
+ load_sample_valuation_comment
end
end
@@ -97,6 +100,17 @@ class Admin::SystemEmailsController < Admin::BaseController
end
end
+ def load_sample_valuation_comment
+ comment = Comment.where(commentable_type: "Budget::Investment").last
+ if comment
+ @email = EvaluationCommentEmail.new(comment)
+ @email_to = @email.to.first
+ else
+ redirect_to admin_system_emails_path,
+ alert: t("admin.system_emails.alert.no_evaluation_comments")
+ end
+ end
+
def load_sample_user
@user = User.last
@token = @user.email_verification_token || SecureRandom.hex
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb
index 47434ba16..18ee03e09 100644
--- a/app/controllers/comments_controller.rb
+++ b/app/controllers/comments_controller.rb
@@ -14,6 +14,7 @@ class CommentsController < ApplicationController
if @comment.save
CommentNotifier.new(comment: @comment).process
add_notification @comment
+ EvaluationCommentNotifier.new(comment: @comment).process if send_evaluation_notification?
else
render :new
end
@@ -107,4 +108,7 @@ class CommentsController < ApplicationController
end
end
+ def send_evaluation_notification?
+ @comment.valuation && Setting["feature.valuation_comment_notification"]
+ end
end
diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb
index c3bda48b9..1f6f4d3a6 100644
--- a/app/helpers/mailer_helper.rb
+++ b/app/helpers/mailer_helper.rb
@@ -8,4 +8,16 @@ module MailerHelper
return budget_investment_url(commentable.budget_id, commentable) if commentable.is_a?(Budget::Investment)
end
+ def valuation_comments_url(commentable)
+ admin_budget_budget_investment_url(commentable.budget, commentable, anchor: "comments")
+ end
+
+ def valuation_comments_link(commentable)
+ link_to(
+ commentable.title,
+ valuation_comments_url(@email.commentable),
+ target: :blank,
+ style: "color: #2895F1; text-decoration:none;"
+ )
+ end
end
diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb
index d8fa120a4..9defb0f15 100644
--- a/app/mailers/mailer.rb
+++ b/app/mailers/mailer.rb
@@ -120,6 +120,13 @@ class Mailer < ApplicationMailer
mail(to: @email_to, from: @newsletter.from, subject: @newsletter.subject)
end
+ def evaluation_comment(comment, to)
+ @email = EvaluationCommentEmail.new(comment)
+ @email_to = to
+
+ mail(to: @email_to.email, subject: @email.subject) if @email.can_be_sent?
+ end
+
private
def with_user(user, &block)
diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb
index 8156e3822..d078437bb 100644
--- a/app/models/budget/investment.rb
+++ b/app/models/budget/investment.rb
@@ -374,6 +374,12 @@ class Budget
milestones.published.with_status.order_by_publication_date.last&.status_id
end
+ def admin_and_valuator_users_associated
+ valuator_users = (valuator_groups.map(&:valuators) + valuators).flatten
+ all_users = valuator_users << administrator
+ all_users.compact.uniq
+ end
+
private
def set_denormalized_ids
diff --git a/app/models/evaluation_comment_notifier.rb b/app/models/evaluation_comment_notifier.rb
new file mode 100644
index 000000000..e1231298c
--- /dev/null
+++ b/app/models/evaluation_comment_notifier.rb
@@ -0,0 +1,16 @@
+class EvaluationCommentNotifier
+ def initialize(args = {})
+ @comment = args.fetch(:comment)
+ end
+
+ def process
+ send_evaluation_comment_email
+ end
+
+ private
+ def send_evaluation_comment_email
+ EvaluationCommentEmail.new(@comment).to.each do |to|
+ Mailer.evaluation_comment(@comment, to).deliver_later
+ end
+ end
+end
diff --git a/app/models/setting.rb b/app/models/setting.rb
index afc363502..e538c958a 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -93,6 +93,7 @@ class Setting < ApplicationRecord
"feature.allow_attached_documents": true,
"feature.allow_images": true,
"feature.help_page": true,
+ "feature.valuation_comment_notification": true,
"homepage.widgets.feeds.debates": true,
"homepage.widgets.feeds.processes": true,
"homepage.widgets.feeds.proposals": true,
diff --git a/app/views/mailer/evaluation_comment.html.erb b/app/views/mailer/evaluation_comment.html.erb
new file mode 100644
index 000000000..0d695766d
--- /dev/null
+++ b/app/views/mailer/evaluation_comment.html.erb
@@ -0,0 +1,19 @@
+
+
+
+ <%= t("mailers.evaluation_comment.title", investment: @email.commentable.title) %>
+
+
+
+ <%= t("mailers.evaluation_comment.hi") %> <%= @email_to.name %>,
+
+
+
+ <%= t("mailers.evaluation_comment.new_comment_by_html", commenter: @email.comment.author.name, investment: valuation_comments_link(@email.commentable)) %>
+
+
+ <%= t("mailers.evaluation_comment.commenter_info", commenter: @email.comment.author.name, time: l(@email.comment.created_at)) %>
+
+ <%= simple_format text_with_links(@email.comment.body), {}, sanitize: false %>
+
+ |
diff --git a/config/locales/ar/mailers.yml b/config/locales/ar/mailers.yml
index db0ab258f..7cc1434e2 100644
--- a/config/locales/ar/mailers.yml
+++ b/config/locales/ar/mailers.yml
@@ -3,7 +3,7 @@ ar:
no_reply: "تم إرسال هذه الرسالة من عنوان بريد إلكتروني لا يقبل الردود."
comment:
hi: مرحبا
- new_comment_by_html: هناك تعليق جديد من %{commenter}
+ new_comment_by_html: هناك تعليق جديد من %{commenter}
subject: تم التعليق على %{commentable}
title: تعليق جديد
config:
@@ -16,7 +16,7 @@ ar:
title: أكد حسابك باستخدام الرابط التالي
reply:
hi: مرحبا
- new_reply_by_html: وهناك رد جديد من %{commenter} على التعليق الخاص بك
+ new_reply_by_html: وهناك رد جديد من %{commenter} على التعليق الخاص بك
subject: يوجد رد على تعليقك
title: اجابة جديدة على تعليقك
unfeasible_spending_proposal:
diff --git a/config/locales/ast/mailers.yml b/config/locales/ast/mailers.yml
index 9bb3ab25c..a0a17c6d7 100644
--- a/config/locales/ast/mailers.yml
+++ b/config/locales/ast/mailers.yml
@@ -3,7 +3,7 @@ ast:
no_reply: "Este mensaje se ha enviado desde una dirección de correo electrónico que no admite respuestas."
comment:
hi: Hola
- new_comment_by_html: Hay un nuevo comentario de %{commenter} en
+ new_comment_by_html: Hay un nuevo comentario de %{commenter} en
subject: Alguien ha comentado en tu %{commentable}
title: Nuevo comentario
config:
@@ -16,7 +16,7 @@ ast:
title: Verifica tu cuenta con el siguiente enlace
reply:
hi: Hola
- new_reply_by_html: Hay una nueva respuesta de %{commenter} a tu comentario en
+ new_reply_by_html: Hay una nueva respuesta de %{commenter} a tu comentario en
subject: Alguien ha respondido a tu comentario
title: Nueva respuesta a tu comentario
unfeasible_spending_proposal:
diff --git a/config/locales/ca/mailers.yml b/config/locales/ca/mailers.yml
index fc3c46535..6f4014ce2 100644
--- a/config/locales/ca/mailers.yml
+++ b/config/locales/ca/mailers.yml
@@ -3,7 +3,7 @@ ca:
no_reply: "Aquest missatge s'ha enviat des d'una adreça de correu electrònic que no admet respostes."
comment:
hi: Hola
- new_comment_by_html: Hi ha un nou comentari de %{commenter} en
+ new_comment_by_html: Hi ha un nou comentari de %{commenter} en
subject: Algú ha comentat en el teu %{commentable}
title: Nou comentari
config:
@@ -16,7 +16,7 @@ ca:
title: Verifica el teu compte amb el següent enllaç
reply:
hi: Hola
- new_reply_by_html: Hi ha una nova resposta de %{commenter} al teu comentari en
+ new_reply_by_html: Hi ha una nova resposta de %{commenter} al teu comentari en
subject: Algú ha respost al teu comentari
title: Nova resposta al teu comentari
unfeasible_spending_proposal:
diff --git a/config/locales/de-DE/mailers.yml b/config/locales/de-DE/mailers.yml
index 3bfbaa81a..1b9fbb7b7 100644
--- a/config/locales/de-DE/mailers.yml
+++ b/config/locales/de-DE/mailers.yml
@@ -3,7 +3,7 @@ de:
no_reply: "Diese Nachricht wurde von einer E-Mail-Adresse gesendet, die keine Antworten akzeptiert."
comment:
hi: Hallo
- new_comment_by_html: Es gibt einen neuen Kommentar von %{commenter}
+ new_comment_by_html: Es gibt einen neuen Kommentar von %{commenter}
subject: Jemand hat Ihre %{commentable} kommentiert.
title: Neuer Kommentar
config:
@@ -16,7 +16,7 @@ de:
title: Bestätigen Sie Ihr Konto über den folgenden Link
reply:
hi: Hallo
- new_reply_by_html: Es gibt eine neue Antwort von %{commenter} auf Ihren Kommentar
+ new_reply_by_html: Es gibt eine neue Antwort von %{commenter} auf Ihren Kommentar
subject: Jemand hat auf Ihren Kommentar geantwortet
title: Neue Antwort auf Ihren Kommentar
unfeasible_spending_proposal:
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 1a5c51e11..b854fc616 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -879,6 +879,9 @@ en:
user_invite:
title: "User Invitation"
description: "Sent to the person that has been invited to register an account."
+ evaluation_comment:
+ title: "New evaluation comment"
+ description: "Sent to administrators and evaluators related to commented investment"
edit_info: "You can edit this email in"
message_title: "Message's Title"
message_body: "This is a sample of message's content."
@@ -886,6 +889,7 @@ en:
no_investments: "There aren't any budget investment created. Some example data is needed in order to preview the email."
no_comments: "There aren't any comments created. Some example data is needed in order to preview the email."
no_replies: "There aren't any replies created. Some example data is needed in order to preview the email."
+ no_evaluation_comments: "There aren't any evaluation comments created. Some example data is needed in order to preview the email."
emails_download:
index:
title: Emails download
diff --git a/config/locales/en/mailers.yml b/config/locales/en/mailers.yml
index c92660de4..a1151d57d 100644
--- a/config/locales/en/mailers.yml
+++ b/config/locales/en/mailers.yml
@@ -3,7 +3,7 @@ en:
no_reply: "This message was sent from an email address that does not accept replies."
comment:
hi: Hi
- new_comment_by_html: There is a new comment from %{commenter}
+ new_comment_by_html: There is a new comment from %{commenter}
subject: Someone has commented on your %{commentable}
title: New comment
config:
@@ -17,7 +17,7 @@ en:
title: Confirm your account using the following link
reply:
hi: Hi
- new_reply_by_html: There is a new response from %{commenter} to your comment on
+ new_reply_by_html: There is a new response from %{commenter} to your comment on
subject: Someone has responded to your comment
title: New response to your comment
proposal_notification_digest:
@@ -70,6 +70,12 @@ en:
hi: "Dear user,"
thanks: "Thank you again for participating."
sincerely: "Sincererly"
+ evaluation_comment:
+ subject: "New evaluation comment"
+ title: New evaluation comment for %{investment}
+ hi: Hi
+ new_comment_by_html: There is a new evaluation comment from %{commenter} to the budget investment %{investment}
+ commenter_info: "%{commenter}, %{time}:"
new_actions_notification_rake_created:
subject: "More news about your citizen proposal"
hi: "Hello %{name},"
diff --git a/config/locales/en/settings.yml b/config/locales/en/settings.yml
index dc74ae6fb..7af06fdad 100644
--- a/config/locales/en/settings.yml
+++ b/config/locales/en/settings.yml
@@ -116,6 +116,8 @@ en:
public_stats_description: "Display public stats in the Administration panel"
help_page: "Help page"
help_page_description: 'Displays a Help menu that contains a page with an info section about each enabled feature. Also custom pages and menus can be created in the "Custom pages" and "Custom content blocks" sections'
+ 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"
map:
latitude: "Latitude"
latitude_description: "Latitude to show the map position"
diff --git a/config/locales/es-PE/mailers.yml b/config/locales/es-PE/mailers.yml
index ea972263a..f04a585ab 100644
--- a/config/locales/es-PE/mailers.yml
+++ b/config/locales/es-PE/mailers.yml
@@ -3,7 +3,7 @@ es-PE:
no_reply: "Este mensaje se ha enviado desde una dirección de correo electrónico que no admite respuestas."
comment:
hi: Hola
- new_comment_by_html: Hay un nuevo comentario de %{commenter} en
+ new_comment_by_html: Hay un nuevo comentario de %{commenter} en
subject: Alguien ha comentado en tu %{commentable}
title: Nuevo comentario
config:
@@ -16,7 +16,7 @@ es-PE:
title: Verifica tu cuenta con el siguiente enlace
reply:
hi: Hola
- new_reply_by_html: Hay una nueva respuesta de %{commenter} a tu comentario en
+ new_reply_by_html: Hay una nueva respuesta de %{commenter} a tu comentario en
subject: Alguien ha respondido a tu comentario
title: Nueva respuesta a tu comentario
unfeasible_spending_proposal:
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 80c71a860..934f45d37 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -878,6 +878,9 @@ es:
user_invite:
title: "Invitación de usuarios"
description: "Enviado a la persona que ha sido invitada a registrar una cuenta."
+ evaluation_comment:
+ title: "Nuevo comentario de evaluación"
+ description: "Enviado a administradores y evaluadores del presupuesto."
edit_info: "Puedes editar este email en"
message_title: "Título del mensaje"
message_body: "Este es un ejemplo de contenido de un mensaje."
@@ -885,6 +888,7 @@ es:
no_investments: "No se ha creado ningún proyecto de gasto. Se necesita algún ejemplo para poder previsualizar el email."
no_comments: "No se ha creado ningún comentario. Se necesita algún ejemplo para poder previsualizar el email."
no_replies: "No se ha creado ninguna respuesta. Se necesita algún ejemplo para poder previsualizar el email."
+ no_evaluation_comments: "No se ha creado ningún comentario de evaluación. Se necesita algún ejemplo para poder previsualizar el email."
emails_download:
index:
title: Descarga de emails
diff --git a/config/locales/es/mailers.yml b/config/locales/es/mailers.yml
index b1d0de74b..92a810b39 100644
--- a/config/locales/es/mailers.yml
+++ b/config/locales/es/mailers.yml
@@ -3,7 +3,7 @@ es:
no_reply: "Este mensaje se ha enviado desde una dirección de correo electrónico que no admite respuestas."
comment:
hi: Hola
- new_comment_by_html: Hay un nuevo comentario de %{commenter} en
+ new_comment_by_html: Hay un nuevo comentario de %{commenter} en
subject: Alguien ha comentado en tu %{commentable}
title: Nuevo comentario
config:
@@ -17,7 +17,7 @@ es:
title: Verifica tu cuenta con el siguiente enlace
reply:
hi: Hola
- new_reply_by_html: Hay una nueva respuesta de %{commenter} a tu comentario en
+ new_reply_by_html: Hay una nueva respuesta de %{commenter} a tu comentario en
subject: Alguien ha respondido a tu comentario
title: Nueva respuesta a tu comentario
proposal_notification_digest:
@@ -70,6 +70,12 @@ es:
hi: "Estimado/a usuario/a"
thanks: "Gracias de nuevo por tu participación."
sincerely: "Atentamente"
+ evaluation_comment:
+ subject: "Nuevo comentario de evaluación"
+ title: Nuevo comentario de evaluación para %{investment}
+ hi: Hola
+ new_comment_by_html: Hay un nuevo comentario de evaluación de %{commenter} en el presupuesto participativo %{investment}
+ commenter_info: "%{commenter}, %{time}"
new_actions_notification_rake_created:
subject: "Más novedades de tu propuesta ciudadana"
hi: "Hola %{name},"
diff --git a/config/locales/es/settings.yml b/config/locales/es/settings.yml
index cdf7f2452..352e4f30d 100644
--- a/config/locales/es/settings.yml
+++ b/config/locales/es/settings.yml
@@ -116,6 +116,8 @@ es:
public_stats_description: "Muestra las estadísticas públicas en el panel de Administración"
help_page: "Página de ayuda"
help_page_description: 'Muestra un menú Ayuda que contiene una página con una sección de información sobre cada funcionalidad habilitada. También se pueden crear páginas y menús personalizados en las secciones "Personalizar páginas" y "Personalizar bloques"'
+ 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"
map:
latitude: "Latitud"
latitude_description: "Latitud para mostrar la posición del mapa"
diff --git a/config/locales/fr/mailers.yml b/config/locales/fr/mailers.yml
index 4c46ab118..4df25de69 100644
--- a/config/locales/fr/mailers.yml
+++ b/config/locales/fr/mailers.yml
@@ -3,7 +3,7 @@ fr:
no_reply: "Ce message a été envoyé d'une adresse qui n'accepte pas les réponses."
comment:
hi: Bonjour
- new_comment_by_html: Il y a un nouveau commentaire de %{commenter}
+ new_comment_by_html: Il y a un nouveau commentaire de %{commenter}
subject: Quelqu'un a commenté votre %{commentable}
title: Nouveau commentaire
config:
@@ -17,7 +17,7 @@ fr:
title: Confirmer votre compte en utilisant le lien suivant
reply:
hi: Bonjour
- new_reply_by_html: Il y a une nouvelle réponse de %{commenter} à votre commentaire sur
+ new_reply_by_html: Il y a une nouvelle réponse de %{commenter} à votre commentaire sur
subject: Quelqu'un a répondu à votre commentaire
title: Nouvelle réponse à votre commentaire
unfeasible_spending_proposal:
diff --git a/config/locales/gl/mailers.yml b/config/locales/gl/mailers.yml
index e8b37c71c..fb4b6e634 100644
--- a/config/locales/gl/mailers.yml
+++ b/config/locales/gl/mailers.yml
@@ -3,7 +3,7 @@ gl:
no_reply: "Esta mensaxe enviouse desde un enderezo de correo electrónico que non admite respostas."
comment:
hi: Ola
- new_comment_by_html: Hai un novo comentario de %{commenter} en
+ new_comment_by_html: Hai un novo comentario de %{commenter} en
subject: Alguén comentou no teu %{commentable}
title: Novo comentario
config:
@@ -17,7 +17,7 @@ gl:
title: Verifica a túa conta co seguinte enlace
reply:
hi: Ola
- new_reply_by_html: Hai unha nova resposta de %{commenter} ao tu comentario en
+ new_reply_by_html: Hai unha nova resposta de %{commenter} ao tu comentario en
subject: Alguén respondeu ao teu comentario
title: Nova resposta ao teu comentario
unfeasible_spending_proposal:
diff --git a/config/locales/he/mailers.yml b/config/locales/he/mailers.yml
index 98b9a0d44..7629188b9 100644
--- a/config/locales/he/mailers.yml
+++ b/config/locales/he/mailers.yml
@@ -3,7 +3,7 @@ he:
no_reply: "נא לא לענות לכתובת דואר זו."
comment:
hi: שלום
- new_comment_by_html: ישנה הערה חדשה מ %{commenter}
+ new_comment_by_html: ישנה הערה חדשה מ %{commenter}
subject: ישנה הערה חדשה %{commentable}
title: הערה חדשה
config:
@@ -17,7 +17,7 @@ he:
title: אשר את חשבונך באמצעות הקישור הבא
reply:
hi: שלום
- new_reply_by_html: ישנה התייחסות חדשה מ %{commenter} לתגובתך בנושא
+ new_reply_by_html: ישנה התייחסות חדשה מ %{commenter} לתגובתך בנושא
subject: מישהו הגיב להערה שלך
title: התקבלה תגובה חדשה להערה שלך
unfeasible_spending_proposal:
diff --git a/config/locales/id-ID/mailers.yml b/config/locales/id-ID/mailers.yml
index 939a868f9..6141cc2ad 100644
--- a/config/locales/id-ID/mailers.yml
+++ b/config/locales/id-ID/mailers.yml
@@ -3,7 +3,7 @@ id:
no_reply: "Pesan ini dikirim dari alamat email yang tidak menerima balasan."
comment:
hi: Hai
- new_comment_by_html: Ada komentar baru dari %{commenter}
+ new_comment_by_html: Ada komentar baru dari %{commenter}
subject: Seseorang telah berkomentar tentang anda %{commentable}
title: Komentar baru
config:
@@ -16,7 +16,7 @@ id:
title: Konfirmasikan akun anda menggunakan tautan berikut
reply:
hi: Hai
- new_reply_by_html: Ada respon baru dari %{commenter} untuk komentar anda
+ new_reply_by_html: Ada respon baru dari %{commenter} untuk komentar anda
subject: Seseorang telah menanggapi komentar anda
title: Tanggapan baru atas komentar anda
unfeasible_spending_proposal:
diff --git a/config/locales/it/mailers.yml b/config/locales/it/mailers.yml
index f6bcfaa59..5f789b6f7 100644
--- a/config/locales/it/mailers.yml
+++ b/config/locales/it/mailers.yml
@@ -3,7 +3,7 @@ it:
no_reply: "Questo messaggio è stato inviato da un indirizzo di posta elettronica che non accetta risposte."
comment:
hi: Salve
- new_comment_by_html: C'è un nuovo commento da %{commenter}
+ new_comment_by_html: C'è un nuovo commento da %{commenter}
subject: Qualcuno ha commentato sul tuo %{commentable}
title: Nuovo commento
config:
@@ -17,7 +17,7 @@ it:
title: Conferma il tuo account utilizzando il seguente link
reply:
hi: Ciao
- new_reply_by_html: C'è una nuova risposta da %{commenter} per il tuo commento su
+ new_reply_by_html: C'è una nuova risposta da %{commenter} per il tuo commento su
subject: Qualcuno ha risposto al tuo commento
title: Nuova risposta al tuo commento
unfeasible_spending_proposal:
diff --git a/config/locales/nl/mailers.yml b/config/locales/nl/mailers.yml
index 53126e894..ead75920f 100644
--- a/config/locales/nl/mailers.yml
+++ b/config/locales/nl/mailers.yml
@@ -3,7 +3,7 @@ nl:
no_reply: "This message was sent from an email address that does not accept replies."
comment:
hi: Hi
- new_comment_by_html: There is a new comment from %{commenter}
+ new_comment_by_html: There is a new comment from %{commenter}
subject: Someone has commented on your %{commentable}
title: New comment
config:
@@ -17,7 +17,7 @@ nl:
title: Confirm your account using the following link
reply:
hi: Hoi
- new_reply_by_html: There is a new response from %{commenter} to your comment on
+ new_reply_by_html: There is a new response from %{commenter} to your comment on
subject: Someone has responded to your comment
title: New response to your comment
unfeasible_spending_proposal:
diff --git a/config/locales/pl-PL/mailers.yml b/config/locales/pl-PL/mailers.yml
index f9eedc9ba..aed305cc6 100644
--- a/config/locales/pl-PL/mailers.yml
+++ b/config/locales/pl-PL/mailers.yml
@@ -3,7 +3,7 @@ pl:
no_reply: "Ta wiadomość została wysłana z adresu e-mail, który nie akceptuje odpowiedzi."
comment:
hi: Cześć
- new_comment_by_html: Nowy komentarz od %{commenter}
+ new_comment_by_html: Nowy komentarz od %{commenter}
subject: Ktoś skomentował Twój %{commentable}
title: Nowy komentarz
config:
@@ -17,7 +17,7 @@ pl:
title: Potwierdź swoje konto za pomocą następującego linku
reply:
hi: Cześć
- new_reply_by_html: Nowa odpowiedź od %{commenter} na Twój komentarz odnośnie
+ new_reply_by_html: Nowa odpowiedź od %{commenter} na Twój komentarz odnośnie
subject: Ktoś odpowiedział na Twój komentarz
title: Nowa odpowiedź na Twój komentarz
unfeasible_spending_proposal:
diff --git a/config/locales/pt-BR/mailers.yml b/config/locales/pt-BR/mailers.yml
index bd7fa72c0..67c00eab7 100644
--- a/config/locales/pt-BR/mailers.yml
+++ b/config/locales/pt-BR/mailers.yml
@@ -3,7 +3,7 @@ pt-BR:
no_reply: "Esta mensagem foi enviada de um endereço de e-mail que não aceita respostas."
comment:
hi: Oi
- new_comment_by_html: Há um novo comentário de %{commenter}
+ new_comment_by_html: Há um novo comentário de %{commenter}
subject: Alguém comentou sobre seu %{commentable}
title: Novo comentário
config:
@@ -17,7 +17,7 @@ pt-BR:
title: Confirme sua conta usando o seguinte link
reply:
hi: Oi
- new_reply_by_html: Há uma nova resposta de %{commenter} ao seu comentário sobre
+ new_reply_by_html: Há uma nova resposta de %{commenter} ao seu comentário sobre
subject: Alguém respondeu ao seu comentário
title: Nova resposta ao seu comentário
unfeasible_spending_proposal:
diff --git a/config/locales/ru/mailers.yml b/config/locales/ru/mailers.yml
index e0de1d260..a12f4ae46 100644
--- a/config/locales/ru/mailers.yml
+++ b/config/locales/ru/mailers.yml
@@ -3,7 +3,7 @@ ru:
no_reply: "Это сообщение было отправлено с email адреса, который не принимает ответы."
comment:
hi: Здравствуйте
- new_comment_by_html: Появился новый комментарий от %{commenter}
+ new_comment_by_html: Появился новый комментарий от %{commenter}
subject: Кто-то прокомментировал ваш %{commentable}
title: Новый комментарий
config:
@@ -17,7 +17,7 @@ ru:
title: Подтвердить ваш аккаунт при помощи следующей ссылки
reply:
hi: Здравствуйте
- new_reply_by_html: Появился новый ответ от %{commenter} на ваш комментарий на
+ new_reply_by_html: Появился новый ответ от %{commenter} на ваш комментарий на
subject: Кто-то ответил на ваш комментарий
title: Новый ответ на ваш комментарий
unfeasible_spending_proposal:
diff --git a/config/locales/sl-SI/mailers.yml b/config/locales/sl-SI/mailers.yml
index c0379edd6..adaed2cd2 100644
--- a/config/locales/sl-SI/mailers.yml
+++ b/config/locales/sl-SI/mailers.yml
@@ -3,7 +3,7 @@ sl:
no_reply: "To sporočilo je bilo poslano z e-naslova, ki ne sprejema odgovorov."
comment:
hi: Hej
- new_comment_by_html: Imaš nov komentar uporabnika/-ce %{commenter}
+ new_comment_by_html: Imaš nov komentar uporabnika/-ce %{commenter}
subject: Nekdo je komentiral na tvoj %{commentable}
title: Nov komentar
config:
@@ -17,7 +17,7 @@ sl:
title: Potrdi svoj račun z uporabo naslednje povezave
reply:
hi: Hej
- new_reply_by_html: Imaš nov odgovor uporabnika/-ce %{commenter} na tvoj komentar o
+ new_reply_by_html: Imaš nov odgovor uporabnika/-ce %{commenter} na tvoj komentar o
subject: Nekdo se je odzval na tvoj komentar
title: Nov odgovor na tvoj komentar
unfeasible_spending_proposal:
diff --git a/config/locales/so-SO/mailers.yml b/config/locales/so-SO/mailers.yml
index 9361e99e0..66fb5bbb7 100644
--- a/config/locales/so-SO/mailers.yml
+++ b/config/locales/so-SO/mailers.yml
@@ -3,7 +3,7 @@ so:
no_reply: "Farriintan waxaa loo direy cinwaanka emailka ah ee aan aqbalin jawaab-celinta."
comment:
hi: Haye
- new_comment_by_html: Waxa jira faalo cusub%{commenter}
+ new_comment_by_html: Waxa jira faalo cusub%{commenter}
subject: Qof ayaa ka falooday%{commentable}
title: Faalo cusub
config:
@@ -17,7 +17,7 @@ so:
title: Xaqiiji xisaabtaada adigoo isticmaalaya xiriirka soo socda
reply:
hi: Haye
- new_reply_by_html: Waxaa jira jawaab cusub oo ka socota %{commenter} si aad faallo uga bixiso
+ new_reply_by_html: Waxaa jira jawaab cusub oo ka socota %{commenter} si aad faallo uga bixiso
subject: Qof ayaa kajawaabay faladadii
title: Jawaabta cusub ee faalladaada
unfeasible_spending_proposal:
diff --git a/config/locales/sq-AL/mailers.yml b/config/locales/sq-AL/mailers.yml
index 4dfbf0869..58896f106 100644
--- a/config/locales/sq-AL/mailers.yml
+++ b/config/locales/sq-AL/mailers.yml
@@ -3,7 +3,7 @@ sq:
no_reply: "Ky mesazh u dërgua nga një adresë e-mail që nuk pranon përgjigje."
comment:
hi: Përshëndetje!
- new_comment_by_html: Ka një koment të ri nga%{commenter}
+ new_comment_by_html: Ka një koment të ri nga%{commenter}
subject: Dikush ka komentuar mbi %{commentable} tuaj
title: Komenti i ri
config:
@@ -17,7 +17,7 @@ sq:
title: Konfirmo llogarinë tënd duke përdorur lidhjen e mëposhtme
reply:
hi: Hi
- new_reply_by_html: Ka një përgjigje të re nga %{commenter} në komentin tuaj
+ new_reply_by_html: Ka një përgjigje të re nga %{commenter} në komentin tuaj
subject: Dikush i është përgjigjur komentit tuaj
title: Përgjigje e re tek komentit tuaj
unfeasible_spending_proposal:
diff --git a/config/locales/sv-SE/mailers.yml b/config/locales/sv-SE/mailers.yml
index ce305afb6..39567de93 100644
--- a/config/locales/sv-SE/mailers.yml
+++ b/config/locales/sv-SE/mailers.yml
@@ -3,7 +3,7 @@ sv:
no_reply: "Det går inte att svara till den här e-postadressen."
comment:
hi: Hej
- new_comment_by_html: Det finns en ny kommentar från %{commenter}
+ new_comment_by_html: Det finns en ny kommentar från %{commenter}
subject: Någon har kommenterat på ditt %{commentable}
title: Ny kommentar
config:
@@ -17,7 +17,7 @@ sv:
title: Bekräfta kontot via länken nedan
reply:
hi: Hej
- new_reply_by_html: Det finns ett nytt svar från %{commenter} till din kommentar på
+ new_reply_by_html: Det finns ett nytt svar från %{commenter} till din kommentar på
subject: Någon har svarat på din kommentar
title: Nytt svar på din kommentar
unfeasible_spending_proposal:
diff --git a/config/locales/val/mailers.yml b/config/locales/val/mailers.yml
index efa3c79de..a0474520b 100644
--- a/config/locales/val/mailers.yml
+++ b/config/locales/val/mailers.yml
@@ -3,7 +3,7 @@ val:
no_reply: "Aquest missatge s'ha enviat des d'una direcció de correu electrònic que no admet respostes."
comment:
hi: Hola
- new_comment_by_html: Hi ha un nou comentari de %{commenter} en
+ new_comment_by_html: Hi ha un nou comentari de %{commenter} en
subject: Algú ha comentat en el teu %{commentable}
title: Nou comentari
config:
@@ -17,7 +17,7 @@ val:
title: Verifica el teu compte amb el següent enllaç
reply:
hi: Hola
- new_reply_by_html: Hi ha noves respostes de %{commenter} al teu comentari en
+ new_reply_by_html: Hi ha noves respostes de %{commenter} al teu comentari en
subject: Algú ha contestat el teu comentari
title: Nova resposta al teu comentari
unfeasible_spending_proposal:
diff --git a/config/locales/zh-CN/mailers.yml b/config/locales/zh-CN/mailers.yml
index 84376169c..c591c3942 100644
--- a/config/locales/zh-CN/mailers.yml
+++ b/config/locales/zh-CN/mailers.yml
@@ -3,7 +3,7 @@ zh-CN:
no_reply: "此消息是从一个不接受回复的电子邮件地址发送的。"
comment:
hi: 您好
- new_comment_by_html: 来自%{commenter}的新评论
+ new_comment_by_html: 来自%{commenter}的新评论
subject: 有人对您的%{commentable} 做了评论
title: 新评论
config:
@@ -17,7 +17,7 @@ zh-CN:
title: 使用以下链接来确认您的账户
reply:
hi: 您好
- new_reply_by_html: %{commenter} 对您评论有新回复
+ new_reply_by_html: %{commenter} 对您评论有新回复
subject: 有人回复了您的评论
title: 对您评论的新回复
unfeasible_spending_proposal:
diff --git a/config/locales/zh-TW/mailers.yml b/config/locales/zh-TW/mailers.yml
index b63e23491..ea06c2522 100644
--- a/config/locales/zh-TW/mailers.yml
+++ b/config/locales/zh-TW/mailers.yml
@@ -3,7 +3,7 @@ zh-TW:
no_reply: "此郵件是從一個不接受回覆的電郵地址發送的。"
comment:
hi: 您好
- new_comment_by_html: %{commenter}發表了新評論
+ new_comment_by_html: %{commenter}發表了新評論
subject: 有人評論了您的%{commentable}
title: 新評論
config:
@@ -17,7 +17,7 @@ zh-TW:
title: 使用以下鏈接確認您的帳戶
reply:
hi: 您好
- new_reply_by_html: %{commenter}對您的評論有新的回覆
+ new_reply_by_html: %{commenter}對您的評論有新的回覆
subject: 有人回覆了您的評論
title: 對您的評論的新回覆
unfeasible_spending_proposal:
diff --git a/lib/evaluation_comment_email.rb b/lib/evaluation_comment_email.rb
new file mode 100644
index 000000000..6321e43dd
--- /dev/null
+++ b/lib/evaluation_comment_email.rb
@@ -0,0 +1,31 @@
+class EvaluationCommentEmail
+ attr_reader :comment
+
+ def initialize(comment)
+ @comment = comment
+ end
+
+ def commentable
+ comment.commentable
+ end
+
+ def to
+ @to ||= related_users
+ end
+
+ def subject
+ I18n.t("mailers.evaluation_comment.subject")
+ end
+
+ def can_be_sent?
+ commentable.present? && to.any?
+ end
+
+ private
+ def related_users
+ return [] if comment.commentable.nil?
+ comment.commentable
+ .admin_and_valuator_users_associated
+ .reject { |associated_user| associated_user.user == comment.author }
+ end
+end
diff --git a/spec/features/admin/system_emails_spec.rb b/spec/features/admin/system_emails_spec.rb
index 4c71f4f3f..b1aed5bed 100644
--- a/spec/features/admin/system_emails_spec.rb
+++ b/spec/features/admin/system_emails_spec.rb
@@ -14,7 +14,8 @@ describe "System Emails" do
let(:system_emails) do
%w[proposal_notification_digest budget_investment_created budget_investment_selected
budget_investment_unfeasible budget_investment_unselected comment reply
- direct_message_for_receiver direct_message_for_sender email_verification user_invite]
+ direct_message_for_receiver direct_message_for_sender email_verification user_invite
+ evaluation_comment]
end
context "System emails" do
@@ -243,6 +244,31 @@ describe "System Emails" do
visit admin_system_email_view_path("reply")
expect(page).to have_content "There aren't any replies created."
expect(page).to have_content "Some example data is needed in order to preview the email."
+
+ visit admin_system_email_view_path("evaluation_comment")
+ expect(page).to have_content "There aren't any evaluation comments created."
+ expect(page).to have_content "Some example data is needed in order to preview the email."
+ end
+
+ scenario "#evaluation_comment" do
+ admin = create(:administrator, user: create(:user, username: "Baby Doe"))
+ investment = create(:budget_investment,
+ title: "Cleaner city",
+ heading: heading,
+ author: user,
+ administrator: admin)
+ comment = create(:comment, :valuation, commentable: investment)
+
+ visit admin_system_email_view_path("evaluation_comment")
+
+ expect(page).to have_content "New evaluation comment for Cleaner city"
+ expect(page).to have_content "Hi #{admin.name}"
+ expect(page).to have_content "There is a new evaluation comment from #{comment.user.name} "\
+ "to the budget investment Cleaner city"
+ expect(page).to have_content comment.body
+
+ expect(page).to have_link "Cleaner city",
+ href: admin_budget_budget_investment_url( investment.budget, investment, anchor: "comments")
end
end
diff --git a/spec/features/comments/budget_investments_valuation_spec.rb b/spec/features/comments/budget_investments_valuation_spec.rb
index 1acb5819c..fd9bf56c7 100644
--- a/spec/features/comments/budget_investments_valuation_spec.rb
+++ b/spec/features/comments/budget_investments_valuation_spec.rb
@@ -171,7 +171,7 @@ describe "Internal valuation comments on Budget::Investments" do
scenario "Create comment", :js do
visit valuation_budget_budget_investment_path(budget, investment)
- fill_in "comment-body-budget_investment_#{investment.id}", with: "Have you thought about...?"
+ fill_in "Leave your comment", with: "Have you thought about...?"
click_button "Publish comment"
within "#comments" do
@@ -199,7 +199,7 @@ describe "Internal valuation comments on Budget::Investments" do
click_link "Reply"
within "#js-comment-form-comment_#{comment.id}" do
- fill_in "comment-body-comment_#{comment.id}", with: "It will be done next week."
+ fill_in "Leave your comment", with: "It will be done next week."
click_button "Publish reply"
end
@@ -261,8 +261,8 @@ describe "Internal valuation comments on Budget::Investments" do
login_as(admin_user)
visit valuation_budget_budget_investment_path(budget, investment)
- fill_in "comment-body-budget_investment_#{investment.id}", with: "I am your Admin!"
- check "comment-as-administrator-budget_investment_#{investment.id}"
+ fill_in "Leave your comment", with: "I am your Admin!"
+ check "Comment as admin"
click_button "Publish comment"
within "#comments" do
@@ -282,8 +282,8 @@ describe "Internal valuation comments on Budget::Investments" do
click_link "Reply"
within "#js-comment-form-comment_#{comment.id}" do
- fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!"
- check "comment-as-administrator-comment_#{comment.id}"
+ fill_in "Leave your comment", with: "Top of the world!"
+ check "Comment as admin"
click_button "Publish reply"
end
@@ -298,4 +298,25 @@ describe "Internal valuation comments on Budget::Investments" do
end
end
+ scenario "Send email notification", :js do
+ ActionMailer::Base.deliveries = []
+
+ login_as(admin_user)
+
+ expect(ActionMailer::Base.deliveries).to eq([])
+
+ visit valuation_budget_budget_investment_path(budget, investment)
+ fill_in "Leave your comment", with: "I am your Admin!"
+ check "Comment as admin"
+ click_button "Publish comment"
+
+ within "#comments" do
+ expect(page).to have_content("I am your Admin!")
+ end
+
+ expect(ActionMailer::Base.deliveries.count).to eq(1)
+ expect(ActionMailer::Base.deliveries.first.to).to eq([valuator_user.email])
+ expect(ActionMailer::Base.deliveries.first.subject).to eq("New evaluation comment")
+ end
+
end
diff --git a/spec/lib/evaluation_comment_email_spec.rb b/spec/lib/evaluation_comment_email_spec.rb
new file mode 100644
index 000000000..18b85c197
--- /dev/null
+++ b/spec/lib/evaluation_comment_email_spec.rb
@@ -0,0 +1,57 @@
+require "rails_helper"
+
+describe EvaluationCommentEmail do
+
+ let(:author) { create(:user) }
+ let(:administrator) { create(:administrator)}
+ let(:investment) { create(:budget_investment, author: author, administrator: administrator) }
+ let(:commenter) { create(:user, email: "email@commenter.org") }
+ let(:comment) { create(:comment, commentable: investment, user: commenter) }
+ let(:comment_email) { EvaluationCommentEmail.new(comment) }
+
+ describe "#commentable" do
+ it "returns the commentable object that contains the replied comment" do
+ expect(comment_email.commentable).to eq investment
+ end
+ end
+
+ describe "#to" do
+ it "returns an array of users related to investment" do
+ expect(comment_email.to).to eq [administrator]
+ end
+
+ it "returns empty array if commentable not exists" do
+ allow(comment).to receive(:commentable).and_return(nil)
+ expect(comment_email.to).to eq []
+ end
+
+ it "returns empty array if not associated users" do
+ allow(investment).to receive(:admin_and_valuator_users_associated).and_return([])
+ expect(comment_email.to).to eq []
+ end
+ end
+
+ describe "#subject" do
+ it "returns the translation for a evaluation comment email subject" do
+ expect(comment_email.subject).to eq "New evaluation comment"
+ end
+ end
+
+ describe "#can_be_sent?" do
+ it "returns true if investment has any associated users" do
+ expect(comment_email.can_be_sent?).to be true
+ end
+
+ it "returns false if the comment doesn't exist" do
+ comment.update(commentable: nil)
+
+ expect(comment_email.can_be_sent?).to be false
+ end
+
+ it "returns false if recipients are empty" do
+ investment.administrator = nil
+ expect(comment_email.can_be_sent?).to be false
+ end
+ end
+
+end
diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb
index 21283d1fe..587c34ba2 100644
--- a/spec/models/budget/investment_spec.rb
+++ b/spec/models/budget/investment_spec.rb
@@ -1242,4 +1242,31 @@ describe Budget::Investment do
end
end
end
+
+ describe "admin_and_valuator_users_associated" do
+ let(:investment) { create(:budget_investment) }
+ let(:valuator_group) { create(:valuator_group) }
+ let(:valuator) { create(:valuator) }
+ let(:administrator) { create(:administrator) }
+
+ it "returns empty array if not valuators or administrator assigned" do
+ expect(investment.admin_and_valuator_users_associated).to eq([])
+ end
+
+ it "returns all valuator and administrator users" do
+ valuator_group.valuators << valuator
+ investment.valuator_groups << valuator_group
+ expect(investment.admin_and_valuator_users_associated).to eq([valuator])
+ investment.administrator = administrator
+ expect(investment.admin_and_valuator_users_associated).to eq([valuator, administrator])
+ end
+
+ it "returns uniq valuators or administrator users" do
+ valuator_group.valuators << valuator
+ investment.valuator_groups << valuator_group
+ investment.valuators << valuator
+ investment.administrator = administrator
+ expect(investment.admin_and_valuator_users_associated).to eq([valuator, administrator])
+ end
+ end
end