Browse Source

Add account suspension

closed-social-glitch-2
Eugen Rochko 7 years ago
parent
commit
39cc9fde8a
7 changed files with 24 additions and 10 deletions
  1. +1
    -1
      app/controllers/admin/accounts_controller.rb
  2. +11
    -8
      app/models/status.rb
  3. +2
    -0
      app/services/process_feed_service.rb
  4. +2
    -0
      app/services/process_interaction_service.rb
  5. +1
    -0
      app/views/admin/accounts/show.html.haml
  6. +5
    -0
      db/migrate/20161205214545_add_suspended_to_accounts.rb
  7. +2
    -1
      db/schema.rb

+ 1
- 1
app/controllers/admin/accounts_controller.rb View File

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

+ 11
- 8
app/models/status.rb View File

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

+ 2
- 0
app/services/process_feed_service.rb View File

@ -93,6 +93,8 @@ class ProcessFeedService < BaseService
account = @account
end
return if account.suspended?
status = Status.create!(
uri: id(entry),
url: url(entry),

+ 2
- 0
app/services/process_interaction_service.rb View File

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

+ 1
- 0
app/views/admin/accounts/show.html.haml View File

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

+ 5
- 0
db/migrate/20161205214545_add_suspended_to_accounts.rb View File

@ -0,0 +1,5 @@
class AddSuspendedToAccounts < ActiveRecord::Migration[5.0]
def change
add_column :accounts, :suspended, :boolean, null: false, default: false
end
end

+ 2
- 1
db/schema.rb View File

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

Loading…
Cancel
Save