dmails: set sender name and ip address explicitly.

Set the sender name and IP addresses explicitly in the controller rather
than implicitly in the model.

Fixes cases where automated dmails from DanbooruBot had their IP
addresses set to the person who triggered the dmail, even though they
didn't actually send the dmail themselves.
This commit is contained in:
evazion
2020-02-23 01:41:54 -06:00
parent 7855e36d17
commit 3a018ee9f7
4 changed files with 17 additions and 35 deletions

View File

@@ -33,7 +33,7 @@ class DmailsController < ApplicationController
end
def create
@dmail = Dmail.create_split(dmail_params(:create))
@dmail = Dmail.create_split(from: CurrentUser.user, creator_ip_addr: CurrentUser.ip_addr, **dmail_params(:create))
respond_with(@dmail)
end

View File

@@ -10,7 +10,6 @@ class Dmail < ApplicationRecord
belongs_to :from, :class_name => "User"
has_many :moderation_reports, as: :model
after_initialize :initialize_attributes, if: :new_record?
before_create :autoreport_spam
after_save :update_unread_dmail_count
after_commit :send_email, on: :create
@@ -28,11 +27,6 @@ class Dmail < ApplicationRecord
def to_name=(name)
self.to = User.find_by_name(name)
end
def initialize_attributes
self.from_id ||= CurrentUser.id
self.creator_ip_addr ||= CurrentUser.ip_addr
end
end
module FactoryMethods
@@ -59,12 +53,10 @@ class Dmail < ApplicationRecord
end
def create_automated(params)
CurrentUser.as_system do
dmail = Dmail.new(from: User.system, **params)
dmail.owner = dmail.to
dmail.save
dmail
end
dmail = Dmail.new(from: User.system, creator_ip_addr: "127.0.0.1", **params)
dmail.owner = dmail.to
dmail.save
dmail
end
end