From bf96025507dd76ab6dc93762b6a8ca2510baac26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 16 Feb 2016 16:35:57 +0100 Subject: [PATCH] link email logs to the post that generate the email notification when available --- .../javascripts/admin/templates/email-sent.hbs | 8 +++++++- .../javascripts/admin/templates/email-skipped.hbs | 8 +++++++- app/controllers/admin/email_controller.rb | 2 +- app/jobs/regular/user_email.rb | 9 +++++---- app/serializers/email_log_serializer.rb | 12 +++++++++++- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/admin/templates/email-sent.hbs b/app/assets/javascripts/admin/templates/email-sent.hbs index 4e4f5dbf7..2f8785c6f 100644 --- a/app/assets/javascripts/admin/templates/email-sent.hbs +++ b/app/assets/javascripts/admin/templates/email-sent.hbs @@ -30,7 +30,13 @@ {{l.to_address}} {{l.email_type}} - {{l.reply_key}} + + {{#if l.post_url}} + {{l.reply_key}} + {{else}} + {{l.reply_key}} + {{/if}} + {{else}} {{i18n 'admin.email.logs.none'}} diff --git a/app/assets/javascripts/admin/templates/email-skipped.hbs b/app/assets/javascripts/admin/templates/email-skipped.hbs index d983b0937..6ef487256 100644 --- a/app/assets/javascripts/admin/templates/email-skipped.hbs +++ b/app/assets/javascripts/admin/templates/email-skipped.hbs @@ -30,7 +30,13 @@ {{l.to_address}} {{l.email_type}} - {{l.skipped_reason}} + + {{#if l.post_url}} + {{l.skipped_reason}} + {{else}} + {{l.skipped_reason}} + {{/if}} + {{else}} {{i18n 'admin.email.logs.none'}} diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb index 4b685c48e..8ca208afb 100644 --- a/app/controllers/admin/email_controller.rb +++ b/app/controllers/admin/email_controller.rb @@ -67,7 +67,7 @@ class Admin::EmailController < Admin::AdminController private def filter_email_logs(email_logs, params) - email_logs = email_logs.includes(:user) + email_logs = email_logs.includes(:user, { post: :topic }) .references(:user) .order(created_at: :desc) .offset(params[:offset] || 0) diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rb index 404dd07f8..6830ec2e6 100644 --- a/app/jobs/regular/user_email.rb +++ b/app/jobs/regular/user_email.rb @@ -15,7 +15,7 @@ module Jobs user = User.find_by(id: args[:user_id]) to_address = args[:to_address].presence || user.try(:email).presence || "no_email_found" - set_skip_context(type, args[:user_id], to_address) + set_skip_context(type, args[:user_id], to_address, args[:post_id]) return skip(I18n.t("email_log.no_user", user_id: args[:user_id])) unless user @@ -44,8 +44,8 @@ module Jobs end end - def set_skip_context(type, user_id, to_address) - @skip_context = { type: type, user_id: user_id, to_address: to_address } + def set_skip_context(type, user_id, to_address, post_id) + @skip_context = { type: type, user_id: user_id, to_address: to_address, post_id: post_id } end NOTIFICATIONS_SENT_BY_MAILING_LIST ||= Set.new %w{posted replied mentioned group_mentioned quoted} @@ -54,7 +54,7 @@ module Jobs notification_type=nil, notification_data_hash=nil, email_token=nil, to_address=nil) - set_skip_context(type, user.id, to_address || user.email) + set_skip_context(type, user.id, to_address || user.email, post.try(:id)) return skip_message(I18n.t("email_log.anonymous_user")) if user.anonymous? return skip_message(I18n.t("email_log.suspended_not_pm")) if user.suspended? && type != :user_private_message @@ -142,6 +142,7 @@ module Jobs email_type: @skip_context[:type], to_address: @skip_context[:to_address], user_id: @skip_context[:user_id], + post_id: @skip_context[:post_id], skipped: true, skipped_reason: "[UserEmail] #{reason}", ) diff --git a/app/serializers/email_log_serializer.rb b/app/serializers/email_log_serializer.rb index 977e3ee93..07f336d4e 100644 --- a/app/serializers/email_log_serializer.rb +++ b/app/serializers/email_log_serializer.rb @@ -7,11 +7,21 @@ class EmailLogSerializer < ApplicationSerializer :user_id, :created_at, :skipped, - :skipped_reason + :skipped_reason, + :post_url has_one :user, serializer: BasicUserSerializer, embed: :objects def include_skipped_reason? object.skipped end + + def post_url + object.post.url + end + + def include_post_url? + object.post.present? + end + end