From d8a178274bd1eb642270e52f207849014cba12bc Mon Sep 17 00:00:00 2001 From: Maksim Pechnikov Date: Fri, 13 Sep 2019 07:12:34 +0300 Subject: [PATCH] fix Activity.get_by_id --- lib/pleroma/activity.ex | 15 +++++++++++---- .../mastodon_api/mastodon_api_controller_test.exs | 9 +++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 2d4e9da0c..56c51aef8 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -150,11 +150,18 @@ def get_by_ap_id_with_object(ap_id) 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 diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 7b337044c..35c2236c8 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -2864,6 +2864,15 @@ test "returns empty object when id invalid", %{conn: conn} 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