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.
This commit is contained in:
evazion
2017-12-15 12:38:17 -06:00
parent eab63daa29
commit b48211cd4a
2 changed files with 5 additions and 5 deletions

View File

@@ -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

View File

@@ -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