Merge branch 'disable-federation' into 'develop'

Do not deliver anything to remote instances when federation is disabled

See merge request funkwhale/funkwhale!423
environments/review-docs-funkw-78jnxn/deployments/34
Eliot Berriot 2018-09-28 19:25:11 +00:00
commit 762b9f73ad
2 zmienionych plików z 26 dodań i 1 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ from django.utils import timezone
from dynamic_preferences.registries import global_preferences_registry
from requests.exceptions import RequestException
from funkwhale_api.common import preferences
from funkwhale_api.common import session
from funkwhale_api.music import models as music_models
from funkwhale_api.taskapp import celery
@ -87,11 +88,16 @@ def dispatch_outbox(activity):
Deliver a local activity to its recipients, both locally and remotely
"""
inbox_items = activity.inbox_items.filter(is_read=False).select_related()
deliveries = activity.deliveries.filter(is_delivered=False)
if inbox_items.exists():
dispatch_inbox.delay(activity_id=activity.pk)
if not preferences.get("federation__enabled"):
# federation is disabled, we only deliver to local recipients
return
deliveries = activity.deliveries.filter(is_delivered=False)
for id in deliveries.values_list("pk", flat=True):
deliver_to_remote.delay(delivery_id=id)
@ -109,6 +115,11 @@ def dispatch_outbox(activity):
"delivery",
)
def deliver_to_remote(delivery):
if not preferences.get("federation__enabled"):
# federation is disabled, we only deliver to local recipients
return
actor = delivery.activity.actor
logger.info("Preparing activity delivery to %s", delivery.inbox_url)
auth = signing.get_auth(actor.private_key, actor.private_key_id)

Wyświetl plik

@ -87,6 +87,20 @@ def test_dispatch_outbox(factories, mocker):
mocked_deliver_to_remote.assert_called_once_with(delivery_id=delivery.pk)
def test_dispatch_outbox_disabled_federation(factories, mocker, preferences):
preferences["federation__enabled"] = False
mocked_inbox = mocker.patch("funkwhale_api.federation.tasks.dispatch_inbox.delay")
mocked_deliver_to_remote = mocker.patch(
"funkwhale_api.federation.tasks.deliver_to_remote.delay"
)
activity = factories["federation.Activity"](actor__local=True)
factories["federation.InboxItem"](activity=activity)
factories["federation.Delivery"](activity=activity)
tasks.dispatch_outbox(activity_id=activity.pk)
mocked_inbox.assert_called_once_with(activity_id=activity.pk)
mocked_deliver_to_remote.assert_not_called()
def test_deliver_to_remote_success_mark_as_delivered(factories, r_mock, now):
delivery = factories["federation.Delivery"]()
r_mock.post(delivery.inbox_url)