From 39cc9fde8a2e34da0639d83688d4d6d6d6240382 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 5 Dec 2016 22:59:30 +0100 Subject: [PATCH] Add account suspension --- app/controllers/admin/accounts_controller.rb | 2 +- app/models/status.rb | 19 +++++++++++-------- app/services/process_feed_service.rb | 2 ++ app/services/process_interaction_service.rb | 2 ++ app/views/admin/accounts/show.html.haml | 1 + ...0161205214545_add_suspended_to_accounts.rb | 5 +++++ db/schema.rb | 3 ++- 7 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20161205214545_add_suspended_to_accounts.rb diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb index 79fb37eb9..ff1989b52 100644 --- a/app/controllers/admin/accounts_controller.rb +++ b/app/controllers/admin/accounts_controller.rb @@ -33,6 +33,6 @@ class Admin::AccountsController < ApplicationController end def account_params - params.require(:account).permit(:silenced) + params.require(:account).permit(:silenced, :suspended) end end diff --git a/app/models/status.rb b/app/models/status.rb index 1f5cf9b46..9d1dae963 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -104,22 +104,20 @@ class Status < ApplicationRecord def as_public_timeline(account = nil) query = joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id') .where(visibility: :public) - .where('accounts.silenced = FALSE') .where('(statuses.in_reply_to_id IS NULL OR statuses.in_reply_to_account_id = statuses.account_id)') .where('statuses.reblog_of_id IS NULL') - query = filter_timeline(query, account) unless account.nil? - query + + account.nil? ? filter_timeline_default(query) : filter_timeline(query, account) end def as_tag_timeline(tag, account = nil) query = tag.statuses .joins('LEFT OUTER JOIN accounts ON statuses.account_id = accounts.id') .where(visibility: :public) - .where('accounts.silenced = FALSE') .where('(statuses.in_reply_to_id IS NULL OR statuses.in_reply_to_account_id = statuses.account_id)') .where('statuses.reblog_of_id IS NULL') - query = filter_timeline(query, account) unless account.nil? - query + + account.nil? ? filter_timeline_default(query) : filter_timeline(query, account) end def favourites_map(status_ids, account_id) @@ -150,8 +148,13 @@ class Status < ApplicationRecord def filter_timeline(query, account) blocked = Block.where(account: account).pluck(:target_account_id) - return query if blocked.empty? - query.where('statuses.account_id NOT IN (?)', blocked) + query = query.where('statuses.account_id NOT IN (?)', blocked) unless blocked.empty? + query = query.where('accounts.silenced = TRUE') if account.silenced? + query + end + + def filter_timeline_default(query) + query.where('accounts.silenced = FALSE') end end diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb index 3aa0ceff8..1a831fa73 100644 --- a/app/services/process_feed_service.rb +++ b/app/services/process_feed_service.rb @@ -93,6 +93,8 @@ class ProcessFeedService < BaseService account = @account end + return if account.suspended? + status = Status.create!( uri: id(entry), url: url(entry), diff --git a/app/services/process_interaction_service.rb b/app/services/process_interaction_service.rb index 129b2a2be..4e5487681 100644 --- a/app/services/process_interaction_service.rb +++ b/app/services/process_interaction_service.rb @@ -23,6 +23,8 @@ class ProcessInteractionService < BaseService account = follow_remote_account_service.call("#{username}@#{domain}") end + return if account.suspended? + if salmon.verify(envelope, account.keypair) update_remote_profile_service.call(xml.at_xpath('/xmlns:entry', xmlns: TagManager::XMLNS), account, true) diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml index 02f7dcfe9..47f1e2308 100644 --- a/app/views/admin/accounts/show.html.haml +++ b/app/views/admin/accounts/show.html.haml @@ -29,6 +29,7 @@ = render 'shared/error_messages', object: @account = f.input :silenced, as: :boolean, wrapper: :with_label + = f.input :suspended, as: :boolean, wrapper: :with_label .actions = f.button :button, t('generic.save_changes'), type: :submit diff --git a/db/migrate/20161205214545_add_suspended_to_accounts.rb b/db/migrate/20161205214545_add_suspended_to_accounts.rb new file mode 100644 index 000000000..0d7e2beac --- /dev/null +++ b/db/migrate/20161205214545_add_suspended_to_accounts.rb @@ -0,0 +1,5 @@ +class AddSuspendedToAccounts < ActiveRecord::Migration[5.0] + def change + add_column :accounts, :suspended, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 8e5c806d4..4f23cf144 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161203164520) do +ActiveRecord::Schema.define(version: 20161205214545) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -41,6 +41,7 @@ ActiveRecord::Schema.define(version: 20161203164520) do t.string "avatar_remote_url" t.datetime "subscription_expires_at" t.boolean "silenced", default: false, null: false + t.boolean "suspended", default: false, null: false t.index ["username", "domain"], name: "index_accounts_on_username_and_domain", unique: true, using: :btree end