about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-07-25 01:35:49 -0500
committermultiple creatures <dev@multiple-creature.party>2019-07-25 01:35:49 -0500
commit0d17c2bf2e5245245935778588fd642a024aa8d4 (patch)
tree42c3195a8849e6271fbf5db7590d1a056b73a885
parent234fae09ad2e789a478858362320e6a3f73b960f (diff)
add all `ActionLog`-able admin & moderator actions to logger
-rw-r--r--app/controllers/concerns/accountable_concern.rb2
-rw-r--r--app/helpers/bangtag_helper.rb9
-rw-r--r--app/helpers/log_helper.rb97
-rw-r--r--app/lib/bangtags.rb7
-rw-r--r--app/models/account.rb5
-rw-r--r--app/services/block_domain_service.rb1
-rw-r--r--app/services/suspend_account_service.rb2
-rw-r--r--app/services/unblock_domain_service.rb1
8 files changed, 111 insertions, 13 deletions
diff --git a/app/controllers/concerns/accountable_concern.rb b/app/controllers/concerns/accountable_concern.rb
index 3cdcffc51..bb78f1645 100644
--- a/app/controllers/concerns/accountable_concern.rb
+++ b/app/controllers/concerns/accountable_concern.rb
@@ -2,8 +2,10 @@
 
 module AccountableConcern
   extend ActiveSupport::Concern
+  include LogHelper
 
   def log_action(action, target)
     Admin::ActionLog.create(account: current_account, action: action, target: target)
+    user_friendly_action_log(current_account, action, target)
   end
 end
diff --git a/app/helpers/bangtag_helper.rb b/app/helpers/bangtag_helper.rb
index 2dd135976..1ace17f85 100644
--- a/app/helpers/bangtag_helper.rb
+++ b/app/helpers/bangtag_helper.rb
@@ -1,4 +1,6 @@
 module BangtagHelper
+  include LogHelper
+
   POLICIES = %w(silence unsilence suspend unsuspend force_unlisted allow_public force_sensitive allow_nonsensitive reset)
   EXCLUDED_DOMAINS = %w(tailma.ws monsterpit.net monsterpit.cloud monsterpit.gallery monsterpit.blog)
 
@@ -15,11 +17,10 @@ module BangtagHelper
 
     if policy == 'reset'
       Admin::ActionLog.create(account: @account, action: unsuspend, target: acct)
-      Admin::ActionLog.create(account: @account, action: unsilence, target: acct)
-      Admin::ActionLog.create(account: @account, action: allow_public, target: acct)
-      Admin::ActionLog.create(account: @account, action: allow_nonsensitive, target: acct)
+      user_friendly_action_log(@account, :unsuspend, acct)
     else
       Admin::ActionLog.create(account: @account, action: policy, target: acct)
+      user_friendly_action_log(@account, policy.to_sym, acct)
     end
 
     case policy
@@ -88,12 +89,14 @@ module BangtagHelper
       domain_block.save
 
       Admin::ActionLog.create(account: @account, action: :create, target: domain_block)
+      user_friendly_action_log(@account, :create, domain_block)
       BlockDomainService.new.call(domain_block)
     else
       domain_block = DomainBlock.find_by(domain: domain)
       return false if domain_block.nil?
 
       Admin::ActionLog.create(account: @account, action: :destroy, target: domain_block)
+      user_friendly_action_log(@account, :destroy, domain_block)
       UnblockDomainService.new.call(domain_block)
     end
 
diff --git a/app/helpers/log_helper.rb b/app/helpers/log_helper.rb
new file mode 100644
index 000000000..c2d82c8ca
--- /dev/null
+++ b/app/helpers/log_helper.rb
@@ -0,0 +1,97 @@
+module LogHelper
+  def user_friendly_action_log(source, action, target)
+    source = source.username if source.is_a?(Account)
+
+    case action
+    when :create
+      if target.is_a? DomainBlock
+        LogWorker.perform_async("\xf0\x9f\x9a\xab <#{source}> applied a #{target.severity}#{target.force_sensitive? ? " and force sensitive media" : ''}#{target.reject_media? ? " and reject media" : ''} policy on https://#{target.domain}\u200b.")
+      elsif target.is_a? EmailDomainBlock
+        LogWorker.perform_async("\u26d4 <#{source}> added a registration block on email domain '#{target.domain}'.")
+      elsif target.is_a? CustomEmoji
+        LogWorker.perform_async("\xf0\x9f\x98\xba <#{source}> added the '#{target.shortcode}' emoji. :#{target.shortcode}:")
+      elsif target.is_a? AccountWarning
+        LogWorker.perform_async("\xe2\x9a\xa0\xef\xb8\x8f <#{source}> sent someone an admin notice.")
+      end
+    when :destroy
+      if target.is_a? DomainBlock
+        LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> reset the policy on https://#{target.domain}\u200b.")
+      elsif target.is_a? EmailDomainBlock
+        LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> removed the registration block on email domain '#{target.domain}'.")
+      elsif target.is_a? CustomEmoji
+        LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed the '#{target.shortcode}' emoji.")
+      elsif target.is_a? Status
+        LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed post #{TagManager.instance.url_for(target)}\u200b.")
+      end
+
+    when :update
+      if target.is_a? Status
+        LogWorker.perform_async("\xf0\x9f\x91\x81\xef\xb8\x8f <#{source}> changed visibility flags of post #{TagManager.instance.url_for(target)}\u200b.")
+      elsif target.is_a? CustomEmoji
+        LogWorker.perform_async("\xf0\x9f\x94\x81 <#{source}> replaced the '#{target.shortcode}' emoji. :#{target.shortcode}:")
+      end
+
+    when :enable
+      if target.is_a? User
+        LogWorker.perform_async("\xf0\x9f\x92\xa7 <#{source}> unfroze the account of <#{target.username}>.")
+      elsif target.is_a? CustomEmoji
+        LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> enabled the '#{target.shortcode}' emoji. :#{target.shortcode}:")
+      end
+    when :disable
+      if target.is_a? User
+        LogWorker.perform_async("\xe2\x9d\x84\xef\xb8\x8f <#{source}> froze the account of <#{target.username}>.")
+      elsif target.is_a? CustomEmoji
+        LogWorker.perform_async("\u26d4 <#{source}> disabled the '#{target.shortcode}' emoji.")
+      end
+
+    when :force_sensitive
+      LogWorker.perform_async("\xf0\x9f\x94\x9e <#{source}> forced the media of <#{target.acct}> to be marked sensitive.")
+    when :force_unlisted
+      LogWorker.perform_async("\xf0\x9f\x94\x89 <#{source}> forced the posts of <#{target.acct}> to be unlisted.")
+    when :silence
+      LogWorker.perform_async("\xf0\x9f\x94\x87 <#{source}> silenced <#{target.acct}>'.")
+    when :suspend
+      LogWorker.perform_async("\u26d4 <#{source}> suspended <#{target.acct}>.")
+
+    when :allow_nonsensitive
+      LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> allowed <#{target.acct}> to post media without a sensitive flag.")
+    when :allow_public
+      LogWorker.perform_async("\xf0\x9f\x86\x8a <#{source}> allowed <#{target.acct}> to post with public visibility.")
+    when :unsilence
+      LogWorker.perform_async("\xf0\x9f\x94\x8a <#{source}> unsilenced <#{target.acct}>.")
+    when :unsuspend
+      LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> unsuspended <#{target.acct}>.")
+
+    when :remove_avatar
+      LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed the avatar of <#{target.acct}>.")
+    when :remove_header
+      LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed the profile header of <#{target.acct}>.")
+
+    when :resolve
+      LogWorker.perform_async("\u2705 <#{source}> resolved report ##{target.id}.")
+    when :reopen
+      LogWorker.perform_async("\u2757 <#{source}> reopened report ##{target.id}.")
+    when :assigned_to_self
+      LogWorker.perform_async("\xf0\x9f\x91\x80 <#{source}> is resolving report ##{target.id}.")
+    when :unassigned
+      LogWorker.perform_async("\u274c <#{source}> is no longer assigned to report ##{target.id}.")
+
+    when :promote
+      LogWorker.perform_async("\xf0\x9f\x94\xba <#{source}> upgraded a local account from #{target.role}.")
+    when :demote
+      LogWorker.perform_async("\xf0\x9f\x94\xbb <#{source}> downgraded a local account from #{target.role}.")
+
+    when :confirm
+      LogWorker.perform_async("\u2705 <#{source}> manually confirmed a local account.")
+    when :reset_password
+      LogWorker.perform_async("\xf0\x9f\x94\x81 <#{source}> manually reset a local account's password.")
+    when :disable_2fa
+      LogWorker.perform_async("\xf0\x9f\x94\x81 <#{source}> manually reset a local account's 2-factor auth.")
+    when :change_email
+      LogWorker.perform_async("\xf0\x9f\x93\x9d <#{source}> manually changed a local account's email address.")
+
+    when :memorialize
+      LogWorker.perform_async("\xf0\x9f\x8f\x85 <#{source}> memorialized an account.")
+    end
+  end
+end
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb
index cd3d86daf..1b3fd0136 100644
--- a/app/lib/bangtags.rb
+++ b/app/lib/bangtags.rb
@@ -170,8 +170,10 @@ class Bangtags
           if emoji.id.nil?
             emoji.image = src_img
             emoji.save
+            user_friendly_action_log(@account, :create, emoji)
           end
         when 'emoji'
+          chunk = nil
           next if cmd[1].nil?
           shortcode = cmd[1]
           domain = (cmd[2].blank? ? nil : cmd[2].downcase)
@@ -186,6 +188,7 @@ class Bangtags
             unless theirs.nil?
               ours.image = theirs.image
               ours.save
+              user_friendly_action_log(@account, :create, ours)
             end
           end
         when 'char'
@@ -306,6 +309,7 @@ class Bangtags
                 if ours.id.nil?
                   ours.image = theirs.image
                   ours.save
+                  user_friendly_action_log(@account, :create, ours)
                 end
               end
             end
@@ -332,6 +336,7 @@ class Bangtags
               if ours.id.nil?
                 ours.image = theirs.image
                 ours.save
+                user_friendly_action_log(@account, :create, ours)
               end
             end
           when 'urls'
@@ -643,7 +648,7 @@ class Bangtags
         end
       end
 
-      chunk.gsub!("#\uf666!", '#!') unless chunk.blank?
+      chunk.gsub!("#\uf666!", '#!') unless chunk.blank? || chunk.frozen?
 
       if chunk.present? && @tf_cmds.present?
         @tf_cmds.each do |tf_cmd|
diff --git a/app/models/account.rb b/app/models/account.rb
index 8d5e5ee1a..efa6b8fbd 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -212,7 +212,6 @@ class Account < ApplicationRecord
   end
 
   def force_unlisted!
-    LogWorker.perform_async("\xf0\x9f\x93\xb5 Forced the media of account '#{@account.acct}' to be unlisted.")
     transaction do
       update!(force_unlisted: true)
       Status.where(account_id: id, visibility: :public).in_batches.update_all(visibility: :unlisted)
@@ -220,7 +219,6 @@ class Account < ApplicationRecord
   end
 
   def force_sensitive!
-    LogWorker.perform_async("\xf0\x9f\x94\x9e Forced the media of account '#{@account.acct}' to be marked sensitive.")
     transaction do
       update!(force_sensitive: true)
       Status.where(account_id: id, sensitive: false).in_batches.update_all(sensitive: true)
@@ -228,7 +226,6 @@ class Account < ApplicationRecord
   end
 
   def allow_public!
-    LogWorker.perform_async("\xf0\x9f\x86\x97 No longer forcing the media of account '#{@account.acct}' to be marked sensitive.")
     update!(force_unlisted: false)
   end
 
@@ -243,12 +240,10 @@ class Account < ApplicationRecord
   def silence!(date = nil)
     date ||= Time.now.utc
     update!(silenced_at: date)
-    LogWorker.perform_async("\xf0\x9f\x94\x87 Silenced account '#{@account.acct}'.")
   end
 
   def unsilence!
     update!(silenced_at: nil)
-    LogWorker.perform_async("\xf0\x9f\x94\x8a Unsilenced account '#{@account.acct}'.")
   end
 
   def suspended?
diff --git a/app/services/block_domain_service.rb b/app/services/block_domain_service.rb
index 5158f6793..4a1218e3f 100644
--- a/app/services/block_domain_service.rb
+++ b/app/services/block_domain_service.rb
@@ -5,7 +5,6 @@ class BlockDomainService < BaseService
 
   def call(domain_block)
     @domain_block = domain_block
-    LogWorker.perform_async("\xf0\x9f\x9a\xab Applying #{@domain_block.severity}#{@domain_block.force_sensitive? ? " and force sensitive media" : ''}#{@domain_block.reject_media? ? " and reject media" : ''} policy on domain '#{blocked_domain}'.")
     process_domain_block!
   end
 
diff --git a/app/services/suspend_account_service.rb b/app/services/suspend_account_service.rb
index c38e6c814..86c7ac137 100644
--- a/app/services/suspend_account_service.rb
+++ b/app/services/suspend_account_service.rb
@@ -40,8 +40,6 @@ class SuspendAccountService < BaseService
     @account = account
     @options = options
 
-    LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f Suspending account '#{@account.acct}'.")
-
     reject_follows!
     purge_user!
     purge_profile!
diff --git a/app/services/unblock_domain_service.rb b/app/services/unblock_domain_service.rb
index 58b33a7f3..eceecd6d7 100644
--- a/app/services/unblock_domain_service.rb
+++ b/app/services/unblock_domain_service.rb
@@ -5,7 +5,6 @@ class UnblockDomainService < BaseService
 
   def call(domain_block)
     @domain_block = domain_block
-    LogWorker.perform_async("\xf0\x9f\x86\x97 Reset policy on domain '#{@domain_block.domain}'.")
     process_retroactive_updates
     domain_block.destroy
   end