about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/accounts_controller.rb12
-rw-r--r--app/models/account.rb4
-rw-r--r--app/services/suspend_account_service.rb18
-rw-r--r--app/views/admin/accounts/index.html.haml7
-rw-r--r--app/views/admin/accounts/show.html.haml2
5 files changed, 31 insertions, 12 deletions
diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb
index ff1989b52..55436d253 100644
--- a/app/controllers/admin/accounts_controller.rb
+++ b/app/controllers/admin/accounts_controller.rb
@@ -7,13 +7,14 @@ class Admin::AccountsController < ApplicationController
   layout 'public'
 
   def index
-    @accounts = Account.order('domain ASC, username ASC').paginate(page: params[:page], per_page: 40)
+    @accounts = Account.alphabetic.paginate(page: params[:page], per_page: 40)
 
     @accounts = @accounts.local                             if params[:local].present?
     @accounts = @accounts.remote                            if params[:remote].present?
     @accounts = @accounts.where(domain: params[:by_domain]) if params[:by_domain].present?
-    @accounts = @accounts.where(silenced: true)             if params[:silenced].present?
-    @accounts = @accounts.reorder('id desc')                if params[:recent].present?
+    @accounts = @accounts.silenced                          if params[:silenced].present?
+    @accounts = @accounts.recent                            if params[:recent].present?
+    @accounts = @accounts.suspended                         if params[:suspended].present?
   end
 
   def show; end
@@ -26,6 +27,11 @@ class Admin::AccountsController < ApplicationController
     end
   end
 
+  def suspend
+    Admin::SuspensionWorker.perform_async(@account.id)
+    redirect_to admin_accounts_path
+  end
+
   private
 
   def set_account
diff --git a/app/models/account.rb b/app/models/account.rb
index b1cf34e9a..aa904588b 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -58,6 +58,10 @@ class Account < ApplicationRecord
   scope :without_followers, -> { where('(select count(f.id) from follows as f where f.target_account_id = accounts.id) = 0') }
   scope :with_followers, -> { where('(select count(f.id) from follows as f where f.target_account_id = accounts.id) > 0') }
   scope :expiring, ->(time) { where(subscription_expires_at: nil).or(where('subscription_expires_at < ?', time)).remote.with_followers }
+  scope :silenced, -> { where(silenced: true) }
+  scope :suspended, -> { where(suspended: true) }
+  scope :recent, -> { reorder('id desc') }
+  scope :alphabetic, -> { order('domain ASC, username ASC') }
 
   def follow!(other_account)
     active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account)
diff --git a/app/services/suspend_account_service.rb b/app/services/suspend_account_service.rb
index 2361c0ec7..729bf42fe 100644
--- a/app/services/suspend_account_service.rb
+++ b/app/services/suspend_account_service.rb
@@ -12,14 +12,14 @@ class SuspendAccountService < BaseService
   private
 
   def purge_content
-    @account.media_attachments.destroy_all!
-    @account.statuses.destroy_all!
-    @account.stream_entries.destroy_all!
-    @account.mentions.destroy_all!
-    @account.notifications.destroy_all!
-    @account.favourites.destroy_all!
-    @account.active_relationships.destroy_all!
-    @account.passive_relationships.destroy_all!
+    @account.media_attachments.destroy_all
+    @account.statuses.destroy_all
+    @account.stream_entries.destroy_all
+    @account.mentions.destroy_all
+    @account.notifications.destroy_all
+    @account.favourites.destroy_all
+    @account.active_relationships.destroy_all
+    @account.passive_relationships.destroy_all
   end
 
   def purge_profile
@@ -34,6 +34,6 @@ class SuspendAccountService < BaseService
   end
 
   def unsubscribe_push_subscribers
-    @account.subscriptions.destroy_all!
+    @account.subscriptions.destroy_all
   end
 end
diff --git a/app/views/admin/accounts/index.html.haml b/app/views/admin/accounts/index.html.haml
index a074f0ad9..a2a3628d6 100644
--- a/app/views/admin/accounts/index.html.haml
+++ b/app/views/admin/accounts/index.html.haml
@@ -2,6 +2,7 @@
   %li= link_to 'Local', admin_accounts_path(local: '1')
   %li= link_to 'Remote', admin_accounts_path(remote: '1')
   %li= link_to 'Silenced', admin_accounts_path(silenced: '1')
+  %li= link_to 'Suspended', admin_accounts_path(suspended: '1')
   %li= link_to 'Most recent', admin_accounts_path(recent: '1')
 
 %table.table
@@ -11,6 +12,7 @@
       %th Domain
       %th Subscribed
       %th Silenced
+      %th Suspended
       %th
   %tbody
     - @accounts.each do |account|
@@ -31,6 +33,11 @@
             %i.fa.fa-check
           - else
             %i.fa.fa-times
+        %td
+          - if account.suspended?
+            %i.fa.fa-check
+          - else
+            %i.fa.fa-times
         %td= link_to 'Edit', admin_account_path(account.id)
 
 = will_paginate @accounts, pagination_options
diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml
index 47f1e2308..de63dd7f9 100644
--- a/app/views/admin/accounts/show.html.haml
+++ b/app/views/admin/accounts/show.html.haml
@@ -33,3 +33,5 @@
 
   .actions
     = f.button :button, t('generic.save_changes'), type: :submit
+
+= link_to 'Perform full suspension', suspend_admin_account_path(@account.id), method: :post, data: { confirm: 'Are you sure?' }, class: 'button'