about summary refs log tree commit diff
path: root/app/models/form
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-04-08 15:57:56 +0200
committerThibaut Girka <thib@sitedethib.com>2019-04-08 15:57:56 +0200
commitf5f6d23d554b3a81020feebc65188cc64f644095 (patch)
treeb30197858c2018a32be559f5b4b479571c75dee3 /app/models/form
parent30500dff7cbf27fbee6eb45e20cc24ca0b7a9e77 (diff)
parent3f036ac6b8f9919b3b141012db163476f18fe299 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- config/locales/pl.yml
  Conflict caused by new upstream string too close to glitch-specific
  “flavour” string. Took both strings.
Diffstat (limited to 'app/models/form')
-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