kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
See #689: fetch nodeinfo when seing a domain for the first time
rodzic
84e2f0af9f
commit
5e3cc99f20
|
@ -151,6 +151,10 @@ class Domain(models.Model):
|
|||
)
|
||||
return data
|
||||
|
||||
@property
|
||||
def is_local(self):
|
||||
return self.name == settings.FEDERATION_HOSTNAME
|
||||
|
||||
|
||||
class Actor(models.Model):
|
||||
ap_type = "Actor"
|
||||
|
|
|
@ -11,7 +11,7 @@ from funkwhale_api.music import licenses
|
|||
from funkwhale_api.music import models as music_models
|
||||
from funkwhale_api.music import tasks as music_tasks
|
||||
|
||||
from . import activity, actors, contexts, jsonld, models, utils
|
||||
from . import activity, actors, contexts, jsonld, models, tasks, utils
|
||||
|
||||
AP_CONTEXT = jsonld.get_default_context()
|
||||
|
||||
|
@ -152,7 +152,12 @@ class ActorSerializer(jsonld.JsonLdSerializer):
|
|||
if maf is not None:
|
||||
kwargs["manually_approves_followers"] = maf
|
||||
domain = urllib.parse.urlparse(kwargs["fid"]).netloc
|
||||
kwargs["domain"] = models.Domain.objects.get_or_create(pk=domain)[0]
|
||||
domain, domain_created = models.Domain.objects.get_or_create(pk=domain)
|
||||
if domain_created and not domain.is_local:
|
||||
# first time we see the domain, we trigger nodeinfo fetching
|
||||
tasks.update_domain_nodeinfo(domain_name=domain.name)
|
||||
|
||||
kwargs["domain"] = domain
|
||||
for endpoint, url in self.validated_data.get("endpoints", {}).items():
|
||||
if endpoint == "sharedInbox":
|
||||
kwargs["shared_inbox_url"] = url
|
||||
|
|
|
@ -121,6 +121,10 @@ class ManageDomainViewSet(
|
|||
"instance_policy",
|
||||
]
|
||||
|
||||
def perform_create(self, serializer):
|
||||
domain = serializer.save()
|
||||
federation_tasks.update_domain_nodeinfo(domain_name=domain.name)
|
||||
|
||||
@rest_decorators.action(methods=["get"], detail=True)
|
||||
def nodeinfo(self, request, *args, **kwargs):
|
||||
domain = self.get_object()
|
||||
|
|
|
@ -14,7 +14,10 @@ def test_actor_fetching(r_mock):
|
|||
assert r == payload
|
||||
|
||||
|
||||
def test_get_actor(factories, r_mock):
|
||||
def test_get_actor(factories, r_mock, mocker):
|
||||
update_domain_nodeinfo = mocker.patch(
|
||||
"funkwhale_api.federation.tasks.update_domain_nodeinfo"
|
||||
)
|
||||
actor = factories["federation.Actor"].build()
|
||||
payload = serializers.ActorSerializer(actor).data
|
||||
r_mock.get(actor.fid, json=payload)
|
||||
|
@ -22,6 +25,7 @@ def test_get_actor(factories, r_mock):
|
|||
|
||||
assert new_actor.pk is not None
|
||||
assert serializers.ActorSerializer(new_actor).data == payload
|
||||
update_domain_nodeinfo.assert_called_once_with(domain_name=new_actor.domain_id)
|
||||
|
||||
|
||||
def test_get_actor_use_existing(factories, preferences, mocker):
|
||||
|
|
|
@ -77,12 +77,16 @@ def test_domain_detail(factories, superuser_api_client):
|
|||
assert response.data["name"] == d.pk
|
||||
|
||||
|
||||
def test_domain_create(superuser_api_client):
|
||||
def test_domain_create(superuser_api_client, mocker):
|
||||
update_domain_nodeinfo = mocker.patch(
|
||||
"funkwhale_api.federation.tasks.update_domain_nodeinfo"
|
||||
)
|
||||
url = reverse("api:v1:manage:federation:domains-list")
|
||||
response = superuser_api_client.post(url, {"name": "test.federation"})
|
||||
|
||||
assert response.status_code == 201
|
||||
assert federation_models.Domain.objects.filter(pk="test.federation").exists()
|
||||
update_domain_nodeinfo.assert_called_once_with(domain_name="test.federation")
|
||||
|
||||
|
||||
def test_domain_nodeinfo(factories, superuser_api_client, mocker):
|
||||
|
|
Ładowanie…
Reference in New Issue