Prepare to drop `EmailLog#topic_id`.
This commit is contained in:
parent
dbfa491ee2
commit
3874d40910
|
@ -1,6 +1,8 @@
|
|||
require_dependency 'distributed_mutex'
|
||||
|
||||
class EmailLog < ActiveRecord::Base
|
||||
self.ignored_columns = %w{topic_id}
|
||||
|
||||
CRITICAL_EMAIL_TYPES ||= Set.new %w{
|
||||
account_created
|
||||
admin_login
|
||||
|
@ -14,7 +16,7 @@ class EmailLog < ActiveRecord::Base
|
|||
|
||||
belongs_to :user
|
||||
belongs_to :post
|
||||
belongs_to :topic
|
||||
has_one :topic, through: :post
|
||||
|
||||
validates :email_type, :to_address, presence: true
|
||||
|
||||
|
|
|
@ -634,7 +634,7 @@ module Email
|
|||
def forwarded_reply_key?(email_log, user)
|
||||
incoming_emails = IncomingEmail
|
||||
.joins(:post)
|
||||
.where('posts.topic_id = ?', email_log.topic_id)
|
||||
.where('posts.topic_id = ?', email_log.topic.id)
|
||||
.addressed_to(email_log.reply_key)
|
||||
.addressed_to_user(user)
|
||||
.pluck(:to_addresses, :cc_addresses)
|
||||
|
|
|
@ -77,11 +77,9 @@ module Email
|
|||
# always set a default Message ID from the host
|
||||
@message.header['Message-ID'] = "<#{SecureRandom.uuid}@#{host}>"
|
||||
|
||||
if topic_id.present?
|
||||
email_log.topic_id = topic_id
|
||||
|
||||
post = Post.find_by(id: post_id)
|
||||
topic = Topic.find_by(id: topic_id)
|
||||
if topic_id.present? && post_id.present?
|
||||
post = Post.find_by(id: post_id, topic_id: topic_id)
|
||||
topic = post.topic
|
||||
first_post = topic.ordered_posts.first
|
||||
|
||||
topic_message_id = first_post.incoming_email&.message_id.present? ?
|
||||
|
|
|
@ -316,7 +316,7 @@ describe Email::Sender do
|
|||
it 'should create the right log' do
|
||||
email_sender.send
|
||||
expect(email_log.post_id).to eq(post.id)
|
||||
expect(email_log.topic_id).to eq(topic.id)
|
||||
expect(email_log.topic.id).to eq(topic.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue