about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-06-22 00:13:10 +0200
committermultiple creatures <dev@multiple-creature.party>2020-02-21 01:48:49 -0600
commit0a238f34b39b606d5f20e1ef1fbdd2a8c56951db (patch)
tree9192e83c420e085c16c8a65fe6077ca30046dd44 /app/services
parente6e69f091e3414b29271040926cc1d2e7c5f0e41 (diff)
port tootsuite#11138 to monsterfork: Change domain blocks to automatically support subdomains
* Change domain blocks to automatically support subdomains

If a more authoritative domain is blocked (example.com), then the
same block will be applied to a subdomain (foo.example.com)

* Match subdomains of existing accounts when blocking/unblocking domains

* Improve code style
Diffstat (limited to 'app/services')
-rw-r--r--app/services/activitypub/process_account_service.rb3
-rw-r--r--app/services/block_domain_service.rb4
-rw-r--r--app/services/resolve_account_service.rb7
-rw-r--r--app/services/unblock_domain_service.rb3
4 files changed, 11 insertions, 6 deletions
diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb
index 08005f042..96a2c4b0b 100644
--- a/app/services/activitypub/process_account_service.rb
+++ b/app/services/activitypub/process_account_service.rb
@@ -256,8 +256,7 @@ class ActivityPub::ProcessAccountService < BaseService
 
   def domain_block
     return @domain_block if defined?(@domain_block)
-
-    @domain_block = DomainBlock.find_by(domain: @domain)
+    @domain_block = DomainBlock.rule_for(@domain)
   end
 
   def key_changed?
diff --git a/app/services/block_domain_service.rb b/app/services/block_domain_service.rb
index 36634fdd5..8ec77ce82 100644
--- a/app/services/block_domain_service.rb
+++ b/app/services/block_domain_service.rb
@@ -123,7 +123,7 @@ class BlockDomainService < BaseService
   end
 
   def blocked_domain_accounts
-    Account.where(domain: blocked_domain).reorder(nil)
+    Account.by_domain_and_subdomains(blocked_domain)
   end
 
   def media_from_blocked_domain
@@ -131,7 +131,7 @@ class BlockDomainService < BaseService
   end
 
   def emojis_from_blocked_domains
-    CustomEmoji.where(domain: blocked_domain)
+    CustomEmoji.by_domain_and_subdomains(blocked_domain)
   end
 
   def unknown_accounts
diff --git a/app/services/resolve_account_service.rb b/app/services/resolve_account_service.rb
index c0356a4b3..37c88d113 100644
--- a/app/services/resolve_account_service.rb
+++ b/app/services/resolve_account_service.rb
@@ -102,6 +102,8 @@ class ResolveAccountService < BaseService
     end
 
     @account
+  rescue Oj::ParseError
+    nil
   end
 
   def webfinger_update_due?
@@ -109,7 +111,10 @@ class ResolveAccountService < BaseService
   end
 
   def activitypub_ready?
-    !@webfinger.link('self').nil? && ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(@webfinger.link('self').type)
+    !@webfinger.link('self').nil? &&
+      ['application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'].include?(@webfinger.link('self').type) &&
+      !actor_json.nil? &&
+      actor_json['inbox'].present?
   end
 
   def actor_url
diff --git a/app/services/unblock_domain_service.rb b/app/services/unblock_domain_service.rb
index c9130d90e..d8a6a25d0 100644
--- a/app/services/unblock_domain_service.rb
+++ b/app/services/unblock_domain_service.rb
@@ -25,7 +25,8 @@ class UnblockDomainService < BaseService
   end
 
   def blocked_accounts
-    scope = Account.where(domain: domain_block.domain)
+    scope = Account.by_domain_and_subdomains(domain_block.domain)
+
     if domain_block.silence?
       scope.where(silenced_at: @domain_block.created_at)
     else