dmails: send automated dmails from Danbooru.config.system_user.

Sends automated dmails from `Danbooru.config.system_user`, rather than
whichever user is performing the action happens to be (usually User.admins.first).

Also adds a notice in the view that the dmail was automated.
This commit is contained in:
evazion 2017-02-23 20:15:29 -06:00
parent 1400f64338
commit b1af644f67
9 changed files with 40 additions and 28 deletions

View File

@ -22,7 +22,7 @@ class ApproverPruner
user.save
end
Dmail.create_split(
Dmail.create_automated(
:to_id => user.id,
:title => "Approver inactivity",
:body => "You haven't approved a post in the past three months. In order to make sure the list of active approvers is up-to-date, you have lost your approver privileges. Please reply to this message if you want to be reinstated."

View File

@ -84,7 +84,7 @@ private
end
def create_dmail
Dmail.create_split(
Dmail.create_automated(
:to_id => user.id,
:title => "You have been promoted",
:body => build_messages

View File

@ -45,20 +45,24 @@ class Dmail < ActiveRecord::Base
copy = nil
Dmail.transaction do
# recipient's copy
copy = Dmail.new(params)
copy.owner_id = copy.to_id
unless copy.to_id == CurrentUser.id
copy.save
end
copy.save unless copy.to_id == copy.from_id
# sender's copy
copy = Dmail.new(params)
copy.owner_id = CurrentUser.id
copy.owner_id = copy.from_id
copy.is_read = true
copy.save
end
copy
end
def create_automated(params)
create_split(from: Danbooru.config.system_user, **params)
end
end
def build_response(options = {})
@ -186,6 +190,10 @@ class Dmail < ActiveRecord::Base
end
end
def is_automated?
from == Danbooru.config.system_user
end
def filtered?
CurrentUser.dmail_filter.try(:filtered?, self)
end

View File

@ -73,7 +73,7 @@ class JanitorTrial < ActiveRecord::Base
def send_dmail
body = "You have been selected as a test janitor. You can now approve pending posts and have access to the moderation interface. You should reacquaint yourself with the [[howto:upload]] guide to make sure you understand the site rules.\n\nOver the next several weeks your approvals will be monitored. If the majority of them are not quality uploads you will fail the trial period and lose your approval privileges. You will also receive a negative user record indicating you previously attempted and failed a test janitor trial.\n\nThere is a minimum quota of 1 approval a month to indicate that you are being active. Remember, the goal isn't to approve as much as possible. It's to filter out borderline-quality art.\n\nIf you have any questions please respond to this message."
Dmail.create_split(:title => "Test Janitor Trial Period", :body => body, :to_id => user_id)
Dmail.create_automated(:title => "Test Janitor Trial Period", :body => body, :to_id => user_id)
end
def promote_user

View File

@ -17,27 +17,20 @@ class PostDisapproval < ActiveRecord::Base
end
def self.dmail_messages!
admin = User.admins.first
disapprovals = {}
PostDisapproval.with_message.where("created_at >= ?", 1.day.ago).find_each do |disapproval|
disapprovals[disapproval.post.uploader_id] ||= []
disapprovals[disapproval.post.uploader_id] << disapproval
disapprovals = PostDisapproval.with_message.where("created_at >= ?", 1.day.ago).group_by do |pd|
pd.post.uploader
end
disapprovals.each do |user_id, list|
user = User.find(user_id)
CurrentUser.scoped(admin, "127.0.0.1") do
message = list.map do |x|
"* post ##{x.post_id}: #{x.message}"
end.join("\n")
disapprovals.each do |uploader, list|
message = list.map do |x|
"* post ##{x.post_id}: #{x.message}"
end.join("\n")
Dmail.create_split(
:to_id => user.id,
:title => "Some of your uploads have been critiqued by the moderators",
:body => message
)
end
Dmail.create_automated(
:to_id => uploader.id,
:title => "Some of your uploads have been critiqued by the moderators",
:body => message
)
end
end

View File

@ -92,7 +92,7 @@ class UserFeedback < ActiveRecord::Base
def create_dmail
unless disable_dmail_notification
body = %{#{creator_name} created a "#{category} record":/user_feedbacks?search[user_id]=#{user_id} for your account. #{body}}
Dmail.create_split(:to_id => user_id, :title => "Your user record has been updated", :body => body)
Dmail.create_automated(:to_id => user_id, :title => "Your user record has been updated", :body => body)
end
end

View File

@ -52,7 +52,7 @@ class UserNameChangeRequest < ActiveRecord::Base
update_attributes(:status => "approved", :approver_id => CurrentUser.user.id)
user.update_attribute(:name, desired_name)
body = "Your name change request has been approved. Be sure to log in with your new user name."
Dmail.create_split(:title => "Name change request approved", :body => body, :to_id => user_id)
Dmail.create_automated(:title => "Name change request approved", :body => body, :to_id => user_id)
UserFeedback.create(:user_id => user_id, :category => "neutral", :body => "Name changed from #{original_name} to #{desired_name}")
ModAction.log("Name changed from #{original_name} to #{desired_name}")
end
@ -60,7 +60,7 @@ class UserNameChangeRequest < ActiveRecord::Base
def reject!(reason)
update_attributes(:status => "rejected", :rejection_reason => reason)
body = "Your name change request has been rejected for the following reason: #{rejection_reason}"
Dmail.create_split(:title => "Name change request rejected", :body => body, :to_id => user_id)
Dmail.create_automated(:title => "Name change request rejected", :body => body, :to_id => user_id)
end
def not_limited

View File

@ -16,6 +16,12 @@
<h3>Body</h3>
<div class="prose">
<%= format_text(@dmail.body, :ragel => true) %>
<% if @dmail.is_automated? %>
<p class="tn">
This is an automated message. Post in the forums if you have any questions.
</p>
<% end %>
</div>
<p>

View File

@ -30,6 +30,11 @@ module Danbooru
"webmaster@#{server_host}"
end
# System actions, such as sending automated dmails, will be performed with this account.
def system_user
User.find_by_name("DanbooruBot") || User.admins.first
end
def upgrade_account_email
contact_email
end