diff --git a/app/logical/approver_pruner.rb b/app/logical/approver_pruner.rb index 089f615d3..8d9300bfc 100644 --- a/app/logical/approver_pruner.rb +++ b/app/logical/approver_pruner.rb @@ -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." diff --git a/app/logical/user_promotion.rb b/app/logical/user_promotion.rb index 981c9e2fd..7a28f47c1 100644 --- a/app/logical/user_promotion.rb +++ b/app/logical/user_promotion.rb @@ -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 diff --git a/app/models/dmail.rb b/app/models/dmail.rb index dba81634d..d6263d1d6 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -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 diff --git a/app/models/janitor_trial.rb b/app/models/janitor_trial.rb index 481cbf815..d7e1a55cb 100644 --- a/app/models/janitor_trial.rb +++ b/app/models/janitor_trial.rb @@ -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 diff --git a/app/models/post_disapproval.rb b/app/models/post_disapproval.rb index b1045b054..052764503 100644 --- a/app/models/post_disapproval.rb +++ b/app/models/post_disapproval.rb @@ -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 diff --git a/app/models/user_feedback.rb b/app/models/user_feedback.rb index a2e06b102..143c88dd2 100644 --- a/app/models/user_feedback.rb +++ b/app/models/user_feedback.rb @@ -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 diff --git a/app/models/user_name_change_request.rb b/app/models/user_name_change_request.rb index 59fc7eec9..eaf8cd372 100644 --- a/app/models/user_name_change_request.rb +++ b/app/models/user_name_change_request.rb @@ -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 diff --git a/app/views/dmails/show.html.erb b/app/views/dmails/show.html.erb index 6260dc070..ef0a43623 100644 --- a/app/views/dmails/show.html.erb +++ b/app/views/dmails/show.html.erb @@ -16,6 +16,12 @@
+ This is an automated message. Post in the forums if you have any questions. +
+ <% end %>diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 2d84aecd4..bbc0f771b 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -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