From 3b06175e8f5cb9d688e8ec376dbfd88abf5f3278 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Fri, 10 May 2019 03:48:11 -0500 Subject: Moderation: add `force sensitive` and `force unlisted` actions. Accounts: add federatable `adult content` tag. Handle from remote accounts as well. --- .../activitypub/process_account_service.rb | 21 ++++++++++++++----- app/services/block_domain_service.rb | 24 ++++++++++++++++++++-- app/services/post_status_service.rb | 7 +++++-- app/services/unblock_domain_service.rb | 9 +++++++- 4 files changed, 51 insertions(+), 10 deletions(-) (limited to 'app/services') diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index f36ab7d61..ee24718e1 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -48,11 +48,13 @@ class ActivityPub::ProcessAccountService < BaseService def create_account @account = Account.new - @account.username = @username - @account.domain = @domain - @account.private_key = nil - @account.suspended_at = domain_block.created_at if auto_suspend? - @account.silenced_at = domain_block.created_at if auto_silence? + @account.username = @username + @account.domain = @domain + @account.private_key = nil + @account.suspended_at = domain_block.created_at if auto_suspend? + @account.silenced_at = domain_block.created_at if auto_silence? + @account.force_unlisted = true if force_unlisted? + @account.force_sensitive = true if force_sensitive? end def update_account @@ -75,6 +77,7 @@ class ActivityPub::ProcessAccountService < BaseService @account.display_name = @json['name'] || '' @account.note = @json['summary'] || '' @account.locked = @json['manuallyApprovesFollowers'] || false + @account.adults_only = @json['suggestedMinAge'].to_i >= 18 @account.fields = property_values || {} @account.also_known_as = as_array(@json['alsoKnownAs'] || []).map { |item| value_or_id(item) } @account.actor_type = actor_type @@ -195,6 +198,14 @@ class ActivityPub::ProcessAccountService < BaseService domain_block&.silence? end + def auto_force_unlisted? + domain_block&.force_unlisted? + end + + def auto_force_sensitive? + domain_block&.force_sensitive? + end + def domain_block return @domain_block if defined?(@domain_block) @domain_block = DomainBlock.find_by(domain: @domain) diff --git a/app/services/block_domain_service.rb b/app/services/block_domain_service.rb index 497f0394b..154d00427 100644 --- a/app/services/block_domain_service.rb +++ b/app/services/block_domain_service.rb @@ -12,8 +12,11 @@ class BlockDomainService < BaseService def process_domain_block! clear_media! if domain_block.reject_media? + force_accounts_sensitive! if domain_block.force_sensitive? - if domain_block.silence? + if domain_block.force_unlisted? + force_accounts_unlisted! + elsif domain_block.silence? silence_accounts! elsif domain_block.suspend? suspend_accounts! @@ -28,6 +31,24 @@ class BlockDomainService < BaseService @affected_status_ids.each { |id| Rails.cache.delete_matched("statuses/#{id}-*") } end + def force_accounts_sensitive! + ApplicationRecord.transaction do + blocked_domain_accounts.in_batches.update_all(force_sensitive: true) + blocked_domain_accounts.reorder(nil).find_each do |account| + account.statuses.where(sensitive: false).in_batches.update_all(sensitive: true) + end + end + end + + def force_accounts_unlisted! + ApplicationRecord.transaction do + blocked_domain_accounts.in_batches.update_all(force_unlisted: true) + blocked_domain_accounts.reorder(nil).find_each do |account| + account.statuses.with_public_visibility.in_batches.update_all(visibility: :unlisted) + end + end + end + def silence_accounts! blocked_domain_accounts.without_silenced.in_batches.update_all(silenced_at: @domain_block.created_at) end @@ -44,7 +65,6 @@ class BlockDomainService < BaseService def suspend_accounts! blocked_domain_accounts.without_suspended.reorder(nil).find_each do |account| - UnsubscribeService.new.call(account) if account.subscribed? SuspendAccountService.new.call(account, suspended_at: @domain_block.created_at) end end diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index d54f9295e..5a73b541f 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -30,6 +30,7 @@ class PostStatusService < BaseService @in_reply_to = @options[:thread] @tags = @options[:tags] @local_only = @options[:local_only] + @sensitive = (@account.force_sensitive? ? true : @options[:sensitive]) return idempotency_duplicate if idempotency_given? && idempotency_duplicate? @@ -58,7 +59,7 @@ class PostStatusService < BaseService end @visibility = @options[:visibility] || @account.user&.setting_default_privacy - @visibility = :unlisted if @visibility == :public && @account.silenced? + @visibility = :unlisted if @visibility.in?([nil, 'public']) && @account.silenced? || @account.force_unlisted if @in_reply_to.present? && @in_reply_to.visibility.present? v = %w(public unlisted private direct limited) @@ -67,6 +68,8 @@ class PostStatusService < BaseService @local_only = true if @account.user_always_local? || @in_reply_to&.local_only + @sensitive = (@account.default_sensitive? || @options[:spoiler_text].present?) if @sensitive.nil? + @scheduled_at = @options[:scheduled_at]&.to_datetime @scheduled_at = nil if scheduled_in_the_past? rescue ArgumentError @@ -176,7 +179,7 @@ class PostStatusService < BaseService media_attachments: @media || [], thread: @in_reply_to, poll_attributes: poll_attributes, - sensitive: (@options[:sensitive].nil? ? @account.user&.setting_default_sensitive : @options[:sensitive]) || @options[:spoiler_text].present?, + sensitive: @sensitive, spoiler_text: @options[:spoiler_text] || '', visibility: @visibility, local_only: @local_only, diff --git a/app/services/unblock_domain_service.rb b/app/services/unblock_domain_service.rb index 9b8526fbe..d9b96edfe 100644 --- a/app/services/unblock_domain_service.rb +++ b/app/services/unblock_domain_service.rb @@ -27,6 +27,13 @@ class UnblockDomainService < BaseService end def domain_block_impact - domain_block.silence? ? :silenced_at : :suspended_at + case domain_block.severity + when :force_unlisted + :force_unlisted + when :silence + :silenced_at + when :suspend + :suspended_at + end end end -- cgit