瀏覽代碼

Add suspend account functionality to admin UI

master
Eugen Rochko 7 年之前
父節點
當前提交
f978b06dd1
共有 7 個文件被更改,包括 56 次插入13 次删除
  1. +9
    -3
      app/controllers/admin/accounts_controller.rb
  2. +4
    -0
      app/models/account.rb
  3. +9
    -9
      app/services/suspend_account_service.rb
  4. +7
    -0
      app/views/admin/accounts/index.html.haml
  5. +2
    -0
      app/views/admin/accounts/show.html.haml
  6. +6
    -1
      config/routes.rb
  7. +19
    -0
      spec/controllers/api/v1/notifications_controller_spec.rb

+ 9
- 3
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


+ 4
- 0
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)


+ 9
- 9
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

+ 7
- 0
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

+ 2
- 0
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'

+ 6
- 1
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


+ 19
- 0
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

Loading…
取消
儲存