Merge pull request #3413 from LextrendIT/feature/notify_evaluation_comments
notify by email new evaluation comments
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
16
app/models/evaluation_comment_notifier.rb
Normal file
16
app/models/evaluation_comment_notifier.rb
Normal file
@@ -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
|
||||
@@ -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,
|
||||
|
||||
19
app/views/mailer/evaluation_comment.html.erb
Normal file
19
app/views/mailer/evaluation_comment.html.erb
Normal file
@@ -0,0 +1,19 @@
|
||||
<td style="padding-bottom: 20px; padding-left: 10px;">
|
||||
|
||||
<h1 style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;">
|
||||
<%= t("mailers.evaluation_comment.title", investment: @email.commentable.title) %>
|
||||
</h1>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.evaluation_comment.hi") %> <strong><%= @email_to.name %></strong>,
|
||||
</p>
|
||||
|
||||
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
|
||||
<%= t("mailers.evaluation_comment.new_comment_by_html", commenter: @email.comment.author.name, investment: valuation_comments_link(@email.commentable)) %>
|
||||
</p>
|
||||
|
||||
<%= t("mailers.evaluation_comment.commenter_info", commenter: @email.comment.author.name, time: l(@email.comment.created_at)) %>
|
||||
<div style="border-left: 2px solid #DEE0E3;font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-style: italic;font-weight: normal;line-height: 24px;margin-left: 20px;padding: 10px;">
|
||||
<%= simple_format text_with_links(@email.comment.body), {}, sanitize: false %>
|
||||
</div>
|
||||
</td>
|
||||
Reference in New Issue
Block a user