about summary refs log tree commit diff
diff options
context:
space:
mode:
authornightpool <eg1290@gmail.com>2018-06-09 18:38:17 -0400
committerEugen Rochko <eugen@zeonfederated.com>2018-06-10 00:38:17 +0200
commit6310dd233ac2581b989228a15bc3d1cd7eaafe9a (patch)
tree4b295124420123ba1bf973231be275bf648fc75e
parent7086aa598b95257ddf9b268efb58bdad7572350c (diff)
Migration to cleanup blocked users that are still following (#7773)
* Migration to cleanup blocked users that are still following

* use follow directly, commit schema
-rw-r--r--db/migrate/20180608213548_reject_following_blocked_users.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/db/migrate/20180608213548_reject_following_blocked_users.rb b/db/migrate/20180608213548_reject_following_blocked_users.rb
new file mode 100644
index 000000000..302db6b68
--- /dev/null
+++ b/db/migrate/20180608213548_reject_following_blocked_users.rb
@@ -0,0 +1,40 @@
+class RejectFollowingBlockedUsers < ActiveRecord::Migration[5.2]
+  disable_ddl_transaction!
+
+  def up
+    blocked_follows = Follow.find_by_sql(<<-SQL)
+      select f.* from follows f
+      inner join blocks b on
+        f.account_id = b.target_account_id and
+        f.target_account_id = b.account_id
+    SQL
+
+    domain_blocked_follows = Follow.find_by_sql(<<-SQL)
+      select f.* from follows f
+      inner join accounts following on f.account_id = following.id
+      inner join account_domain_blocks b on
+        lower(b.domain) = lower(following.domain) and
+        f.target_account_id = b.account_id
+    SQL
+
+    follows = (blocked_follows + domain_blocked_follows).uniq
+    say "Destroying #{follows.size} blocked follow relationships..."
+
+    follows.each do |follow|
+      blocked_account = follow.account
+      followed_acccount = follow.target_account
+
+      next follow.destroy! if blocked_account.local?
+
+      reject_follow_json = Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(follow, serializer: ActivityPub::RejectFollowSerializer, adapter: ActivityPub::Adapter).as_json).sign!(followed_acccount))
+
+      ActivityPub::DeliveryWorker.perform_async(reject_follow_json, followed_acccount, blocked_account.inbox_url)
+
+      follow.destroy!
+    end
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end