Redirect non-local activities when /notice/:id is used
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Wed, 3 Feb 2021 16:53:09 +0000 (17:53 +0100)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Thu, 4 Feb 2021 14:17:40 +0000 (15:17 +0100)
Related-to: https://git.pleroma.social/pleroma/pleroma/-/issues/2496
CHANGELOG.md
lib/pleroma/web/o_status/o_status_controller.ex
test/pleroma/web/o_status/o_status_controller_test.exs

index 3f439d3a44db8bbc571f04f35b438c024277d0b7..e9dfac97ea6b30da6559af0c5418c9dc7f70d922 100644 (file)
@@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Deprecated `Pleroma.Uploaders.S3, :public_endpoint`. Now `Pleroma.Upload, :base_url` is the standard configuration key for all uploaders.
 - Improved Apache webserver support: updated sample configuration, MediaProxy cache invalidation verified with the included sample script
 - Improve OAuth 2.0 provider support. A missing `fqn` field was added to the response, but does not expose the user's email address.
+- Provide redirect of external posts from `/notice/:id` to their original URL
 
 ### Added
 
index 450aae0426889e704657e45da4821a6b99938a2f..da3264149b792c644266659ab063d70910a465d5 100644 (file)
@@ -73,12 +73,8 @@ defmodule Pleroma.Web.OStatus.OStatusController do
          %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
       cond do
         format in ["json", "activity+json"] ->
-          if activity.local do
-            %{data: %{"id" => redirect_url}} = Object.normalize(activity, fetch: false)
-            redirect(conn, external: redirect_url)
-          else
-            {:error, :not_found}
-          end
+          %{data: %{"id" => redirect_url}} = Object.normalize(activity, fetch: false)
+          redirect(conn, external: redirect_url)
 
         activity.data["type"] == "Create" ->
           %Object{} = object = Object.normalize(activity, fetch: false)
index 5cdca019a0ccc033bedf79d5e210bbe903b10de4..2038f4ddd12bd654062a9484695892f59ba381b9 100644 (file)
@@ -144,13 +144,19 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
       assert redirect_url == expected_redirect_url
     end
 
-    test "returns a 404 on remote notice when json requested", %{conn: conn} do
+    test "redirects to a proper object URL when json requested and the object is remote", %{
+      conn: conn
+    } do
       note_activity = insert(:note_activity, local: false)
+      expected_redirect_url = Object.normalize(note_activity, fetch: false).data["id"]
 
-      conn
-      |> put_req_header("accept", "application/activity+json")
-      |> get("/notice/#{note_activity.id}")
-      |> response(404)
+      redirect_url =
+        conn
+        |> put_req_header("accept", "application/activity+json")
+        |> get("/notice/#{note_activity.id}")
+        |> redirected_to()
+
+      assert redirect_url == expected_redirect_url
     end
 
     test "500s when actor not found", %{conn: conn} do