about summary refs log tree commit diff
path: root/app/models/form/account_batch.rb
diff options
context:
space:
mode:
authorReverite <github@reverite.sh>2019-04-12 01:38:18 -0700
committerReverite <github@reverite.sh>2019-04-12 01:38:18 -0700
commite10a9794f4ed7c90e3190f285359f55dd00da435 (patch)
tree579ebf95d6bbf091d05e66907a9c8168c926e0af /app/models/form/account_batch.rb
parentff736905fa534f7189e57c1d0c14fbac45f239a1 (diff)
parentbb50ec2e6687238ad8b2ec545a73270fee7a7b09 (diff)
Merge branch 'glitch' into production
Diffstat (limited to 'app/models/form/account_batch.rb')
-rw-r--r--app/models/form/account_batch.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/models/form/account_batch.rb b/app/models/form/account_batch.rb
index 60eaaf0e2..5bc44e809 100644
--- a/app/models/form/account_batch.rb
+++ b/app/models/form/account_batch.rb
@@ -2,6 +2,7 @@
 
 class Form::AccountBatch
   include ActiveModel::Model
+  include Authorization
 
   attr_accessor :account_ids, :action, :current_account
 
@@ -13,6 +14,10 @@ class Form::AccountBatch
       remove_from_followers!
     when 'block_domains'
       block_domains!
+    when 'approve'
+      approve!
+    when 'reject'
+      reject!
     end
   end
 
@@ -57,4 +62,18 @@ class Form::AccountBatch
 
     ActivityPub::DeliveryWorker.perform_async(json, current_account.id, follow.account.inbox_url)
   end
+
+  def approve!
+    users = accounts.includes(:user).map(&:user)
+
+    users.each { |user| authorize(user, :approve?) }
+         .each(&:approve!)
+  end
+
+  def reject!
+    records = accounts.includes(:user)
+
+    records.each { |account| authorize(account.user, :reject?) }
+           .each { |account| SuspendAccountService.new.call(account, including_user: true, destroy: true, skip_distribution: true) }
+  end
 end