Fix private post card handling.
authorlain <lain@soykaf.club>
Fri, 22 Feb 2019 11:02:51 +0000 (12:02 +0100)
committerlain <lain@soykaf.club>
Fri, 22 Feb 2019 11:02:51 +0000 (12:02 +0100)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
test/web/mastodon_api/mastodon_api_controller_test.exs

index 7e153f3966c0ef4c15088be7b07668ef6ea0d537..fb0b7b68e335132b1d27469b151be6f2ca0601f1 100644 (file)
@@ -943,7 +943,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   def visible_for_user?(activity, user) do
     x = [user.ap_id | user.following]
-    y = activity.data["to"] ++ (activity.data["cc"] || [])
+    y = [activity.actor] ++ activity.data["to"] ++ (activity.data["cc"] || [])
     visible_for_user?(activity, nil) || Enum.any?(x, &(&1 in y))
   end
 
index 60738301b592b7a3bf5ca041c16af5ec62accc48..cf7458d5fe4f5c2927288c7535b0af390ccb97a7 100644 (file)
@@ -1518,9 +1518,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
     end
   end
 
-  def status_card(conn, %{"id" => status_id}) do
+  def status_card(%{assigns: %{user: user}} = conn, %{"id" => status_id}) do
     with %Activity{} = activity <- Repo.get(Activity, status_id),
-         true <- ActivityPub.is_public?(activity) do
+         true <- ActivityPub.visible_for_user?(activity, user) do
       data =
         StatusView.render(
           "card.json",
index 3dfbc8669fb270a1fa34a6b08d3cd0c9fa4090a0..b52c2b80570536b19b6658ebf385ba11b5642756 100644 (file)
@@ -1744,6 +1744,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
                }
              }
 
+      # works with private posts
+      {:ok, activity} =
+        CommonAPI.post(user, %{"status" => "http://example.com/ogp", "visibility" => "direct"})
+
+      response_two =
+        conn
+        |> assign(:user, user)
+        |> get("/api/v1/statuses/#{activity.id}/card")
+        |> json_response(200)
+
+      assert response_two == response
+
       Pleroma.Config.put([:rich_media, :enabled], false)
     end
   end