From 8893ad98997197bd89e98f7dd18825dcb1206aa4 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 29 Jul 2024 09:59:35 -0400 Subject: [PATCH] Fix cancelling jobs --- lib/pleroma/web/common_api.ex | 4 ++-- test/pleroma/web/common_api_test.exs | 32 ++++++++++++++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index 06faf845e..b90b6a6d9 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -714,11 +714,11 @@ def get_user(ap_id, fake_record_fallback \\ true) do end end - defp maybe_cancel_jobs(%Activity{data: %{"id" => ap_id}}) do + defp maybe_cancel_jobs(%Activity{id: activity_id}) do Oban.Job |> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.args["op"] == "publish_one") - |> where([j], j.args["params"]["id"] == ^ap_id) + |> where([j], j.args["params"]["activity_id"] == ^activity_id) |> Oban.cancel_all_jobs() end diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index b6fba6999..4cdd3cffa 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1957,7 +1957,7 @@ test "when deleting posts", %{ {:ok, _, _} = Pleroma.User.follow(remote_one, local_user) {:ok, _, _} = Pleroma.User.follow(remote_two, local_user) - {:ok, %{data: %{"id" => ap_id}} = activity} = + {:ok, %{id: activity_id} = _activity} = CommonAPI.post(local_user, %{status: "Happy Friday everyone!"}) # Generate the publish_one jobs @@ -1971,7 +1971,7 @@ test "when deleting posts", %{ state: "available", queue: "federator_outgoing", worker: "Pleroma.Workers.PublisherWorker", - args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} + args: %{"op" => "publish_one", "params" => %{"activity_id" => ^activity_id}} }, job ) @@ -1980,7 +1980,7 @@ test "when deleting posts", %{ assert length(publish_one_jobs) == 2 # The delete should have triggered cancelling the publish_one jobs - assert {:ok, _delete} = CommonAPI.delete(activity.id, local_user) + assert {:ok, _delete} = CommonAPI.delete(activity_id, local_user) # all_enqueued/1 will not return cancelled jobs cancelled_jobs = @@ -1988,7 +1988,7 @@ test "when deleting posts", %{ |> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.state == "cancelled") |> where([j], j.args["op"] == "publish_one") - |> where([j], j.args["params"]["id"] == ^ap_id) + |> where([j], j.args["params"]["activity_id"] == ^activity_id) |> Pleroma.Repo.all() assert length(cancelled_jobs) == 2 @@ -2001,7 +2001,7 @@ test "when unfavoriting posts", %{ {:ok, activity} = CommonAPI.post(remote_user, %{status: "I like turtles!"}) - {:ok, %{data: %{"id" => ap_id}} = _favorite} = + {:ok, %{id: favorite_id} = _favorite} = CommonAPI.favorite(activity.id, local_user) # Generate the publish_one jobs @@ -2015,7 +2015,7 @@ test "when unfavoriting posts", %{ state: "available", queue: "federator_outgoing", worker: "Pleroma.Workers.PublisherWorker", - args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} + args: %{"op" => "publish_one", "params" => %{"activity_id" => ^favorite_id}} }, job ) @@ -2032,7 +2032,7 @@ test "when unfavoriting posts", %{ |> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.state == "cancelled") |> where([j], j.args["op"] == "publish_one") - |> where([j], j.args["params"]["id"] == ^ap_id) + |> where([j], j.args["params"]["activity_id"] == ^favorite_id) |> Pleroma.Repo.all() assert length(cancelled_jobs) == 1 @@ -2049,7 +2049,7 @@ test "when unboosting posts", %{ {:ok, activity} = CommonAPI.post(remote_one, %{status: "This is an unpleasant post"}) - {:ok, %{data: %{"id" => ap_id}} = _repeat} = + {:ok, %{id: repeat_id} = _repeat} = CommonAPI.repeat(activity.id, local_user) # Generate the publish_one jobs @@ -2063,7 +2063,7 @@ test "when unboosting posts", %{ state: "available", queue: "federator_outgoing", worker: "Pleroma.Workers.PublisherWorker", - args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} + args: %{"op" => "publish_one", "params" => %{"activity_id" => ^repeat_id}} }, job ) @@ -2080,7 +2080,7 @@ test "when unboosting posts", %{ |> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.state == "cancelled") |> where([j], j.args["op"] == "publish_one") - |> where([j], j.args["params"]["id"] == ^ap_id) + |> where([j], j.args["params"]["activity_id"] == ^repeat_id) |> Pleroma.Repo.all() assert length(cancelled_jobs) == 2 @@ -2094,11 +2094,11 @@ test "when unreacting to posts", %{ {:ok, _, _} = Pleroma.User.follow(remote_one, local_user) {:ok, _, _} = Pleroma.User.follow(remote_two, local_user) - {:ok, activity} = + {:ok, %{id: activity_id}} = CommonAPI.post(remote_one, %{status: "Gang gang!!!!"}) - {:ok, %{data: %{"id" => ap_id}} = _react} = - CommonAPI.react_with_emoji(activity.id, local_user, "👍") + {:ok, %{id: react_id} = _react} = + CommonAPI.react_with_emoji(activity_id, local_user, "👍") # Generate the publish_one jobs ObanHelpers.perform_all() @@ -2111,7 +2111,7 @@ test "when unreacting to posts", %{ state: "available", queue: "federator_outgoing", worker: "Pleroma.Workers.PublisherWorker", - args: %{"op" => "publish_one", "params" => %{"id" => ^ap_id}} + args: %{"op" => "publish_one", "params" => %{"activity_id" => ^react_id}} }, job ) @@ -2120,7 +2120,7 @@ test "when unreacting to posts", %{ assert length(publish_one_jobs) == 2 # The unreact should have triggered cancelling the publish_one jobs - assert {:ok, _unreact} = CommonAPI.unreact_with_emoji(activity.id, local_user, "👍") + assert {:ok, _unreact} = CommonAPI.unreact_with_emoji(activity_id, local_user, "👍") # all_enqueued/1 will not return cancelled jobs cancelled_jobs = @@ -2128,7 +2128,7 @@ test "when unreacting to posts", %{ |> where([j], j.worker == "Pleroma.Workers.PublisherWorker") |> where([j], j.state == "cancelled") |> where([j], j.args["op"] == "publish_one") - |> where([j], j.args["params"]["id"] == ^ap_id) + |> where([j], j.args["params"]["activity_id"] == ^react_id) |> Pleroma.Repo.all() assert length(cancelled_jobs) == 2