Merge branch 'fix/mix-task-caching' into 'develop'
[akkoma] / lib / pleroma / web / activity_pub / activity_pub_controller.ex
index 12f61f5f0760b1072d9de8d25b02d8164b736bb9..d337532d0ef46417a45f863cf84c552f709b6bb0 100644 (file)
@@ -1,7 +1,7 @@
 defmodule Pleroma.Web.ActivityPub.ActivityPubController do
   use Pleroma.Web, :controller
-  alias Pleroma.{User, Repo, Object, Activity}
-  alias Pleroma.Web.ActivityPub.{ObjectView, UserView, Transmogrifier}
+  alias Pleroma.{User, Object}
+  alias Pleroma.Web.ActivityPub.{ObjectView, UserView}
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.Federator
 
@@ -15,15 +15,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
       conn
       |> put_resp_header("content-type", "application/activity+json")
       |> json(UserView.render("user.json", %{user: user}))
+    else
+      nil -> {:error, :not_found}
     end
   end
 
   def object(conn, %{"uuid" => uuid}) do
     with ap_id <- o_status_url(conn, :object, uuid),
-         %Object{} = object <- Object.get_cached_by_ap_id(ap_id) do
+         %Object{} = object <- Object.get_cached_by_ap_id(ap_id),
+         {_, true} <- {:public?, ActivityPub.is_public?(object)} do
       conn
       |> put_resp_header("content-type", "application/activity+json")
       |> json(ObjectView.render("object.json", %{object: object}))
+    else
+      {:public?, false} ->
+        {:error, :not_found}
     end
   end
 
@@ -93,7 +99,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
       Logger.info("Signature not from author, relayed message, fetching from source")
       ActivityPub.fetch_object_from_id(params["object"]["id"])
     else
-      Logger.info("Signature error")
+      Logger.info("Signature error - make sure you are forwarding the HTTP Host header!")
       Logger.info("Could not validate #{params["actor"]}")
       Logger.info(inspect(conn.req_headers))
     end
@@ -101,6 +107,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
     json(conn, "ok")
   end
 
+  def errors(conn, {:error, :not_found}) do
+    conn
+    |> put_status(404)
+    |> json("Not found")
+  end
+
   def errors(conn, _e) do
     conn
     |> put_status(500)