Add suspend account functionality to admin UI

rebase/4.0.0rc2
Eugen Rochko 2016-12-06 18:22:59 +01:00
parent f406e01fcf
commit f978b06dd1
7 changed files with 56 additions and 13 deletions

View File

@ -7,13 +7,14 @@ class Admin::AccountsController < ApplicationController
layout 'public' layout 'public'
def index 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.local if params[:local].present?
@accounts = @accounts.remote if params[:remote].present? @accounts = @accounts.remote if params[:remote].present?
@accounts = @accounts.where(domain: params[:by_domain]) if params[:by_domain].present? @accounts = @accounts.where(domain: params[:by_domain]) if params[:by_domain].present?
@accounts = @accounts.where(silenced: true) if params[:silenced].present? @accounts = @accounts.silenced if params[:silenced].present?
@accounts = @accounts.reorder('id desc') if params[:recent].present? @accounts = @accounts.recent if params[:recent].present?
@accounts = @accounts.suspended if params[:suspended].present?
end end
def show; end def show; end
@ -26,6 +27,11 @@ class Admin::AccountsController < ApplicationController
end end
end end
def suspend
Admin::SuspensionWorker.perform_async(@account.id)
redirect_to admin_accounts_path
end
private private
def set_account def set_account

View File

@ -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 :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 :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 :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) def follow!(other_account)
active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account) active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account)

View File

@ -12,14 +12,14 @@ class SuspendAccountService < BaseService
private private
def purge_content def purge_content
@account.media_attachments.destroy_all! @account.media_attachments.destroy_all
@account.statuses.destroy_all! @account.statuses.destroy_all
@account.stream_entries.destroy_all! @account.stream_entries.destroy_all
@account.mentions.destroy_all! @account.mentions.destroy_all
@account.notifications.destroy_all! @account.notifications.destroy_all
@account.favourites.destroy_all! @account.favourites.destroy_all
@account.active_relationships.destroy_all! @account.active_relationships.destroy_all
@account.passive_relationships.destroy_all! @account.passive_relationships.destroy_all
end end
def purge_profile def purge_profile
@ -34,6 +34,6 @@ class SuspendAccountService < BaseService
end end
def unsubscribe_push_subscribers def unsubscribe_push_subscribers
@account.subscriptions.destroy_all! @account.subscriptions.destroy_all
end end
end end

View File

@ -2,6 +2,7 @@
%li= link_to 'Local', admin_accounts_path(local: '1') %li= link_to 'Local', admin_accounts_path(local: '1')
%li= link_to 'Remote', admin_accounts_path(remote: '1') %li= link_to 'Remote', admin_accounts_path(remote: '1')
%li= link_to 'Silenced', admin_accounts_path(silenced: '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') %li= link_to 'Most recent', admin_accounts_path(recent: '1')
%table.table %table.table
@ -11,6 +12,7 @@
%th Domain %th Domain
%th Subscribed %th Subscribed
%th Silenced %th Silenced
%th Suspended
%th %th
%tbody %tbody
- @accounts.each do |account| - @accounts.each do |account|
@ -31,6 +33,11 @@
%i.fa.fa-check %i.fa.fa-check
- else - else
%i.fa.fa-times %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) %td= link_to 'Edit', admin_account_path(account.id)
= will_paginate @accounts, pagination_options = will_paginate @accounts, pagination_options

View File

@ -33,3 +33,5 @@
.actions .actions
= f.button :button, t('generic.save_changes'), type: :submit = 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'

View File

@ -46,7 +46,12 @@ Rails.application.routes.draw do
namespace :admin do namespace :admin do
resources :pubsubhubbub, only: [:index] resources :pubsubhubbub, only: [:index]
resources :accounts, only: [:index, :show, :update]
resources :accounts, only: [:index, :show, :update] do
member do
post :suspend
end
end
end end
namespace :api do namespace :api do

View File

@ -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