Verified Commit 1e583cd5 authored by Agate's avatar Agate 💬

Redirect to HTML version on Actor representations

parent 08f4dd70
Pipeline #9898 passed with stages
in 5 minutes
......@@ -61,6 +61,16 @@ class ActorViewSet(FederationMixin, mixins.RetrieveModelMixin, viewsets.GenericV
queryset = models.Actor.objects.local().select_related("user")
serializer_class = serializers.ActorSerializer
def retrieve(self, request, *args, **kwargs):
instance = self.get_object()
if utils.should_redirect_ap_to_html(request.headers.get("accept")):
if instance.get_channel():
return redirect_to_html(instance.channel.get_absolute_url())
return redirect_to_html(instance.get_absolute_url())
serializer = self.get_serializer(instance)
return response.Response(serializer.data)
@action(methods=["get", "post"], detail=True)
def inbox(self, request, *args, **kwargs):
inbox_actor = self.get_object()
......@@ -222,7 +232,7 @@ class MusicLibraryViewSet(
def retrieve(self, request, *args, **kwargs):
lb = self.get_object()
if utils.should_redirect_ap_to_html(request.headers.get("accept")):
# XXX: implement this for actors, albums, tracks, artists
# XXX: implement this for albums, tracks, artists
return redirect_to_html(lb.get_absolute_url())
conf = {
"id": lb.get_federation_id(),
......
......@@ -387,3 +387,43 @@ def test_music_library_retrieve_redirects_to_html_if_header_set(
)
assert response.status_code == 302
assert response["Location"] == expected_url
def test_actor_retrieve_redirects_to_html_if_header_set(
factories, api_client, settings
):
actor = factories["federation.Actor"](local=True)
url = reverse(
"federation:actors-detail",
kwargs={"preferred_username": actor.preferred_username},
)
response = api_client.get(url, HTTP_ACCEPT="text/html")
expected_url = utils.join_url(
settings.FUNKWHALE_URL,
utils.spa_reverse(
"actor_detail", kwargs={"username": actor.preferred_username}
),
)
assert response.status_code == 302
assert response["Location"] == expected_url
def test_channel_actor_retrieve_redirects_to_html_if_header_set(
factories, api_client, settings
):
channel = factories["audio.Channel"](local=True)
url = reverse(
"federation:actors-detail",
kwargs={"preferred_username": channel.actor.preferred_username},
)
response = api_client.get(url, HTTP_ACCEPT="text/html")
expected_url = utils.join_url(
settings.FUNKWHALE_URL,
utils.spa_reverse(
"channel_detail", kwargs={"username": channel.actor.preferred_username}
),
)
assert response.status_code == 302
assert response["Location"] == expected_url
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment