Show all system emails in Admin section

This commit is contained in:
Julian Herrero
2019-02-19 22:25:11 +01:00
parent bca283c35d
commit 00bd7008bb
11 changed files with 469 additions and 27 deletions

View File

@@ -410,6 +410,10 @@ $sidebar-active: #f4fcd0;
}
}
code {
word-break: break-all;
}
// 02. Sidebar
// -----------

View File

@@ -5,14 +5,35 @@ class Admin::SystemEmailsController < Admin::BaseController
def index
@system_emails = {
proposal_notification_digest: %w[view preview_pending],
budget_investment_created: %w[view edit_info],
budget_investment_selected: %w[view edit_info],
budget_investment_unfeasible: %w[view edit_info],
budget_investment_unselected: %w[view edit_info],
comment: %w[view edit_info],
reply: %w[view edit_info],
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]
}
end
def view
case @system_email
when "proposal_notification_digest"
@notifications = Notification.where(notifiable_type: "ProposalNotification").limit(2)
@subject = t('mailers.proposal_notification_digest.title', org_name: Setting['org_name'])
load_sample_proposal_notifications
when /\Abudget_investment/
load_sample_investment
when /\Adirect_message/
load_sample_direct_message
when "comment"
load_sample_comment
when "reply"
load_sample_reply
when "email_verification"
load_sample_user
when "user_invite"
@subject = t("mailers.user_invite.subject", org_name: Setting["org_name"])
end
end
@@ -39,12 +60,62 @@ class Admin::SystemEmailsController < Admin::BaseController
private
def load_system_email
@system_email = params[:system_email_id]
end
def load_system_email
@system_email = params[:system_email_id]
end
def unsent_proposal_notifications_ids
Notification.where(notifiable_type: "ProposalNotification", emailed_at: nil)
.group(:notifiable_id).count.keys
end
def load_sample_proposal_notifications
@notifications = Notification.where(notifiable_type: "ProposalNotification").limit(2)
@subject = t("mailers.proposal_notification_digest.title", org_name: Setting["org_name"])
end
def load_sample_investment
if Budget::Investment.any?
@investment = Budget::Investment.last
@subject = t("mailers.#{@system_email}.subject", code: @investment.code)
else
redirect_to admin_system_emails_path, alert: t("admin.system_emails.alert.no_investments")
end
end
def load_sample_comment
@comment = Comment.where(commentable_type: %w[Debate Proposal Budget::Investment]).last
if @comment
@commentable = @comment.commentable
@subject = t("mailers.comment.subject", commentable: commentable_name)
else
redirect_to admin_system_emails_path, alert: t("admin.system_emails.alert.no_comments")
end
end
def load_sample_reply
reply = Comment.select { |comment| comment.reply? }.last
if reply
@email = ReplyEmail.new(reply)
else
redirect_to admin_system_emails_path, alert: t("admin.system_emails.alert.no_replies")
end
end
def load_sample_user
@user = User.last
@token = @user.email_verification_token || SecureRandom.hex
@subject = t("mailers.email_verification.subject")
end
def load_sample_direct_message
@direct_message = DirectMessage.new(sender: current_user, receiver: current_user,
title: t("admin.system_emails.message_title"),
body: t("admin.system_emails.message_body"))
@subject = t("mailers.#{@system_email}.subject")
end
def commentable_name
t("activerecord.models.#{@commentable.class.name.underscore}", count: 1)
end
def unsent_proposal_notifications_ids
Notification.where(notifiable_type: "ProposalNotification", emailed_at: nil)
.group(:notifiable_id).count.keys
end
end

View File

@@ -17,14 +17,11 @@ class Mailer < ApplicationMailer
end
def reply(reply)
@reply = reply
@commentable = @reply.commentable
parent = Comment.find(@reply.parent_id)
@recipient = parent.author
@email_to = @recipient.email
@email = ReplyEmail.new(reply)
@email_to = @email.to
with_user(@recipient) do
mail(to: @email_to, subject: t('mailers.reply.subject')) if @commentable.present? && @recipient.present?
with_user(@email.recipient) do
mail(to: @email_to, subject: @email.subject) if @email.can_be_sent?
end
end

View File

@@ -37,6 +37,13 @@
method: :put %>
</div>
<% end %>
<% if system_email_actions.include?("edit_info") %>
<div class="small-8 column">
<p class="help-text">
<%= t("admin.system_emails.edit_info") %><br>
<code><%= "app/views/mailer/#{system_email_title}.html.erb" %></code>
</p>
</div>
<% end %>
</td>
</tr>

View File

@@ -11,7 +11,7 @@
</div>
<div class="small-12 medium-8 column">
<strong><%= t("admin.newsletters.show.subject") %></strong><br>
<%= @subject %>
<%= @subject || @email.subject %>
</div>
</div>
</div>

View File

@@ -5,16 +5,16 @@
</h1>
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t("mailers.reply.hi") %> <strong><%= @recipient.name %></strong>,
<%= t("mailers.reply.hi") %> <strong><%= @email.recipient.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.reply.new_reply_by_html", commenter: @reply.author.name) %> <%= link_to @commentable.title, comment_url(@reply.id), style: "color: #2895F1; text-decoration:none;" %>
<%= t("mailers.reply.new_reply_by_html", commenter: @email.reply.author.name) %> <%= link_to @email.commentable.title, comment_url(@email.reply.id), style: "color: #2895F1; text-decoration:none;" %>
</p>
<p 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;">
<%= text_with_links @reply.body %>
</p>
<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.reply.body), {}, sanitize: false %>
</div>
<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 12px;font-weight: normal;line-height: 20px;">
<%= t("mailers.config.manage_email_subscriptions") %> <%= link_to t("account.show.title"), account_url, style: "color: #2895F1; text-decoration:none;" %>