Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gordon
funkwhale
Commits
b028f3f8
Verified
Commit
b028f3f8
authored
6 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Do not deliver anything to remote instances when federation is disabled
parent
6572db3a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/funkwhale_api/federation/tasks.py
+12
-1
12 additions, 1 deletion
api/funkwhale_api/federation/tasks.py
api/tests/federation/test_tasks.py
+14
-0
14 additions, 0 deletions
api/tests/federation/test_tasks.py
with
26 additions
and
1 deletion
api/funkwhale_api/federation/tasks.py
+
12
−
1
View file @
b028f3f8
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
api/tests/federation/test_tasks.py
+
14
−
0
View file @
b028f3f8
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment