fix Activity.get_by_id
authorMaksim Pechnikov <parallel588@gmail.com>
Fri, 13 Sep 2019 04:12:34 +0000 (07:12 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Fri, 13 Sep 2019 04:12:34 +0000 (07:12 +0300)
lib/pleroma/activity.ex
test/web/mastodon_api/mastodon_api_controller_test.exs

index 2d4e9da0c7e9c8b269d24fd2ebace82e8f4442c6..56c51aef8653c86f0c13af24da04115468464917 100644 (file)
@@ -150,11 +150,18 @@ defmodule Pleroma.Activity do
     )
   end
 
+  @spec get_by_id(String.t()) :: Activity.t() | nil
   def get_by_id(id) do
-    Activity
-    |> where([a], a.id == ^id)
-    |> restrict_deactivated_users()
-    |> Repo.one()
+    case Pleroma.FlakeId.is_flake_id?(id) do
+      true ->
+        Activity
+        |> where([a], a.id == ^id)
+        |> restrict_deactivated_users()
+        |> Repo.one()
+
+      _ ->
+        nil
+    end
   end
 
   def get_by_id_with_object(id) do
index 7b337044c7a6ec4b40d80010dabaab9bc02427e5..35c2236c8d7d6df7aa90ae75209bf5ecb6fda0e7 100644 (file)
@@ -2864,6 +2864,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
 
       assert response == %{}
     end
+
+    test "returns empty object when id isn't FlakeID", %{conn: conn} do
+      response =
+        conn
+        |> get("/api/v1/statuses/3ebbadd1-eb14-4e20-8118/card")
+        |> json_response(200)
+
+      assert response == %{}
+    end
   end
 
   test "bookmarks" do