From b48211cd4a98026b21715df039725507996d975d Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 15 Dec 2017 12:38:17 -0600 Subject: [PATCH] dmails: only spam check recipient's copy of the dmail. Each dmail creates two copies, one for the sender and one for the receiver. Only spam check the receiver's copy. Prevents senders from being able to tell when their messages are being spam filtered. --- app/models/dmail.rb | 6 +++--- test/unit/dmail_test.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/dmail.rb b/app/models/dmail.rb index 4e861d5d1..ea2a29114 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -31,9 +31,9 @@ class Dmail < ApplicationRecord creator_ip_addr.to_s end - def spam?(sender = CurrentUser.user) + def spam? return false if Danbooru.config.rakismet_key.blank? - return false if sender.is_gold? + return false if from.is_gold? super() end end @@ -58,7 +58,6 @@ class Dmail < ApplicationRecord def initialize_attributes self.from_id ||= CurrentUser.id self.creator_ip_addr ||= CurrentUser.ip_addr - self.is_spam = spam?(CurrentUser.user) end end @@ -73,6 +72,7 @@ class Dmail < ApplicationRecord # recipient's copy copy = Dmail.new(params) copy.owner_id = copy.to_id + copy.is_spam = copy.spam? copy.save unless copy.to_id == copy.from_id # sender's copy diff --git a/test/unit/dmail_test.rb b/test/unit/dmail_test.rb index 0d4427cce..a2ab36fc2 100644 --- a/test/unit/dmail_test.rb +++ b/test/unit/dmail_test.rb @@ -23,8 +23,8 @@ class DmailTest < ActiveSupport::TestCase should "not validate" do assert_difference("Dmail.count", 2)do - dmail = Dmail.create_split(:to_id => @recipient.id, :title => "My video", :body => "hey Noneeditsonlyme. My webcam see here http://bit.ly/2vTv9Ki") - assert(dmail.is_spam?) + Dmail.create_split(:to_id => @recipient.id, :title => "My video", :body => "hey Noneeditsonlyme. My webcam see here http://bit.ly/2vTv9Ki") + assert(@recipient.dmails.last.is_spam?) end end end