diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb index ff1989b5..55436d25 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 b1cf34e9..aa904588 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 2361c0ec..729bf42f 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 a074f0ad..a2a3628d 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 47f1e230..de63dd7f 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' diff --git a/config/routes.rb b/config/routes.rb index ac53bbed..cde84d3b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,7 +46,12 @@ Rails.application.routes.draw do namespace :admin do resources :pubsubhubbub, only: [:index] - resources :accounts, only: [:index, :show, :update] + + resources :accounts, only: [:index, :show, :update] do + member do + post :suspend + end + end end namespace :api do diff --git a/spec/controllers/api/v1/notifications_controller_spec.rb b/spec/controllers/api/v1/notifications_controller_spec.rb new file mode 100644 index 00000000..e5f7eec7 --- /dev/null +++ b/spec/controllers/api/v1/notifications_controller_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +RSpec.describe Api::V1::NotificationsController, type: :controller do + render_views + + let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } + let(:token) { double acceptable?: true, resource_owner_id: user.id } + + before do + allow(controller).to receive(:doorkeeper_token) { token } + end + + describe 'GET #index' do + it 'returns http success' do + get :index + expect(response).to have_http_status(:success) + end + end +end