See #170: Funkwhale federation

This commit is contained in:
Eliot Berriot 2020-03-25 15:32:10 +01:00
parent fce4d87551
commit 9aa12db62e
20 changed files with 3722 additions and 125 deletions

View file

@ -1,8 +1,6 @@
import logging
from django.db.models.deletion import Collector
from funkwhale_api.federation import routes
from funkwhale_api.federation import tasks as federation_tasks
from funkwhale_api.taskapp import celery
from . import models
@ -20,39 +18,6 @@ def delete_account(user):
user.delete()
logger.info("Deleted user object")
# Then we broadcast the info over federation. We do this *before* deleting objects
# associated with the actor, otherwise follows are removed and we don't know where
# to broadcast
logger.info("Broadcasting deletion to federation…")
routes.outbox.dispatch(
{"type": "Delete", "object": {"type": actor.type}}, context={"actor": actor}
)
# then we delete any object associated with the actor object, but *not* the actor
# itself. We keep it for auditability and sending the Delete ActivityPub message
collector = Collector(using="default")
logger.info(
"Prepare deletion of objects associated with account %s", user.username
)
collector.collect([actor])
for model, instances in collector.data.items():
if issubclass(model, actor.__class__):
# we skip deletion of the actor itself
continue
logger.info(
"Deleting %s objects associated with account %s",
len(instances),
user.username,
)
to_delete = model.objects.filter(pk__in=[instance.pk for instance in instances])
to_delete.delete()
# Finally, we update the actor itself and mark it as removed
logger.info("Marking actor as Tombsone…")
actor.type = "Tombstone"
actor.name = None
actor.summary = None
actor.save(update_fields=["type", "name", "summary"])
logger.info("Deletion of account done %s!", user.username)
# ensure actor is set to tombstone, activities are removed, etc.
federation_tasks.remove_actor(actor_id=actor.pk)
logger.info("Deletion of account done %s!", actor.preferred_username)