Add filters for suspended accounts

This commit is contained in:
Eugen Rochko 2016-12-06 18:03:30 +01:00
parent 2488162733
commit f406e01fcf
8 changed files with 35 additions and 12 deletions

View File

@ -5,6 +5,8 @@ class AccountsController < ApplicationController
before_action :set_account before_action :set_account
before_action :set_link_headers before_action :set_link_headers
before_action :authenticate_user!, only: [:follow, :unfollow]
before_action :check_account_suspension
def show def show
respond_to do |format| respond_to do |format|
@ -50,4 +52,8 @@ class AccountsController < ApplicationController
def webfinger_account_url def webfinger_account_url
webfinger_url(resource: "acct:#{@account.acct}@#{Rails.configuration.x.local_domain}") webfinger_url(resource: "acct:#{@account.acct}@#{Rails.configuration.x.local_domain}")
end end
def check_account_suspension
head 410 if @account.suspended?
end
end end

View File

@ -15,6 +15,7 @@ class ApplicationController < ActionController::Base
before_action :store_current_location, except: :raise_not_found, unless: :devise_controller? before_action :store_current_location, except: :raise_not_found, unless: :devise_controller?
before_action :set_locale before_action :set_locale
before_action :set_user_activity before_action :set_user_activity
before_action :check_suspension, if: :user_signed_in?
def raise_not_found def raise_not_found
raise ActionController::RoutingError, "No route matches #{params[:unmatched_route]}" raise ActionController::RoutingError, "No route matches #{params[:unmatched_route]}"
@ -40,6 +41,10 @@ class ApplicationController < ActionController::Base
current_user.touch(:current_sign_in_at) if !current_user.nil? && (current_user.current_sign_in_at.nil? || current_user.current_sign_in_at < 24.hours.ago) current_user.touch(:current_sign_in_at) if !current_user.nil? && (current_user.current_sign_in_at.nil? || current_user.current_sign_in_at < 24.hours.ago)
end end
def check_suspension
head 403 if current_user.account.suspended?
end
protected protected
def not_found def not_found

View File

@ -5,8 +5,7 @@ class Settings::PreferencesController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
def show def show; end
end
def update def update
current_user.settings(:notification_emails).follow = user_params[:notification_emails][:follow] == '1' current_user.settings(:notification_emails).follow = user_params[:notification_emails][:follow] == '1'

View File

@ -10,8 +10,7 @@ class Settings::ProfilesController < ApplicationController
obfuscate_filename [:account, :avatar] obfuscate_filename [:account, :avatar]
obfuscate_filename [:account, :header] obfuscate_filename [:account, :header]
def show def show; end
end
def update def update
if @account.update(account_params) if @account.update(account_params)

View File

@ -6,6 +6,7 @@ class StreamEntriesController < ApplicationController
before_action :set_account before_action :set_account
before_action :set_stream_entry before_action :set_stream_entry
before_action :set_link_headers before_action :set_link_headers
before_action :check_account_suspension
def show def show
@type = @stream_entry.activity_type.downcase @type = @stream_entry.activity_type.downcase
@ -37,4 +38,8 @@ class StreamEntriesController < ApplicationController
def set_stream_entry def set_stream_entry
@stream_entry = @account.stream_entries.find(params[:id]) @stream_entry = @account.stream_entries.find(params[:id])
end end
def check_account_suspension
head 410 if @account.suspended?
end
end end

View File

@ -7,7 +7,7 @@ class FollowService < BaseService
def call(source_account, uri) def call(source_account, uri)
target_account = follow_remote_account_service.call(uri) target_account = follow_remote_account_service.call(uri)
raise ActiveRecord::RecordNotFound if target_account.nil? || target_account.id == source_account.id raise ActiveRecord::RecordNotFound if target_account.nil? || target_account.id == source_account.id || target_account.suspended?
follow = source_account.follow!(target_account) follow = source_account.follow!(target_account)

View File

@ -33,13 +33,13 @@ class NotifyService < BaseService
end end
def blocked? def blocked?
blocked = false blocked = @recipient.suspended? # Skip if the recipient account is suspended anyway
blocked ||= @recipient.id == @notification.from_account.id blocked ||= @recipient.id == @notification.from_account.id # Skip for interactions with self
blocked ||= @recipient.blocking?(@notification.from_account) blocked ||= @recipient.blocking?(@notification.from_account) # Skip for blocked accounts
blocked ||= (@notification.from_account.silenced? && !@recipient.following?(@notification.from_account)) blocked ||= (@notification.from_account.silenced? && !@recipient.following?(@notification.from_account)) # Hellban
blocked ||= (@recipient.user.settings(:interactions).must_be_follower && !@notification.from_account.following?(@recipient)) blocked ||= (@recipient.user.settings(:interactions).must_be_follower && !@notification.from_account.following?(@recipient)) # Options
blocked ||= (@recipient.user.settings(:interactions).must_be_following && !@recipient.following?(@notification.from_account)) blocked ||= (@recipient.user.settings(:interactions).must_be_following && !@recipient.following?(@notification.from_account)) # Options
blocked ||= send("blocked_#{@notification.type}?") blocked ||= send("blocked_#{@notification.type}?") # Type-dependent filters
blocked blocked
end end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class Admin::SuspensionWorker
include Sidekiq::Worker
def perform(account_id)
SuspendAccountService.new.call(Account.find(account_id))
end
end