about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-12-07 20:17:07 -0600
committermultiple creatures <dev@multiple-creature.party>2019-12-07 20:17:07 -0600
commit5d7349f2ab41f4e68080b10a988646d0aff17e2c (patch)
tree9d0bb152340f0ae78157ee47e507a532fca2af04 /app/services
parent2765793f7dabf4a6a9758566fe02b7f31598c0a0 (diff)
domain policies also now get applied to subdomains
Diffstat (limited to 'app/services')
-rw-r--r--app/services/activitypub/process_account_service.rb29
1 files changed, 24 insertions, 5 deletions
diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb
index a1d508405..a863f1f11 100644
--- a/app/services/activitypub/process_account_service.rb
+++ b/app/services/activitypub/process_account_service.rb
@@ -23,7 +23,8 @@ class ActivityPub::ProcessAccountService < BaseService
 
         is_new_account = @account.nil?
         if is_new_account
-          set_reject_unknown_policy if Setting.auto_reject_unknown
+          copy_policy_of_parent_domain
+          set_reject_unknown_policy if Setting.auto_reject_unknown && new_domain?
           create_account
         end
         update_account
@@ -101,11 +102,29 @@ class ActivityPub::ProcessAccountService < BaseService
     @account.moved_to_account  = @json['movedTo'].present? ? moved_account : nil
   end
 
+  def copy_policy_of_parent_domain
+    domain_parts = @domain.split('.')
+    domains = (1..domain_parts.count-1).map { |i| domain_parts[i..-1] }
+    return if domains.empty?
+
+    existing_policy = DomainBlock.find_by(domain: domains)
+    return if existing_policy.nil?
+
+    policy_attributes = existing_policy.template
+    policy_attributes['domain'] = @domain
+    policy = DomainBlock.create!(policy_attributes)
+    user_friendly_action_log(existing_policy, :create, policy)
+
+    @new_domain = false
+  end
+
   def set_reject_unknown_policy
-    unless Account.where(domain: @domain).exists? || DomainBlock.where(domain: @domain).exists?
-      policy = DomainBlock.create!(domain: @domain, severity: :noop, reject_unknown: true)
-      user_friendly_action_log(nil, :mark_unknown, @domain)
-    end
+    policy = DomainBlock.create!(domain: @domain, severity: :noop, reject_unknown: true)
+    user_friendly_action_log(nil, :mark_unknown, @domain)
+  end
+
+  def new_domain?
+    @new_domain ||= !(Account.where(domain: @domain).exists? || DomainBlock.where(domain: @domain).exists?)
   end
 
   def after_key_change!