From 1cccc0fc2193b7ba0a87bf0902abce429748153e Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 18:38:02 -0400 Subject: [PATCH] Fix order of args for vote/3 --- lib/pleroma/web/common_api.ex | 4 ++-- lib/pleroma/web/mastodon_api/controllers/poll_controller.ex | 6 +++--- test/pleroma/notification_test.exs | 4 ++-- .../web/activity_pub/activity_pub_controller_test.exs | 2 +- test/pleroma/web/activity_pub/utils_test.exs | 4 ++-- test/pleroma/web/common_api_test.exs | 4 ++-- test/pleroma/web/mastodon_api/views/poll_view_test.exs | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index f26cd8c1e..2eb2bcc82 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -329,8 +329,8 @@ defmodule Pleroma.Web.CommonAPI do end end - @spec vote(User.t(), Object.t(), list()) :: {:ok, list(), Object.t()} | {:error, any()} - def vote(user, %{data: %{"type" => "Question"}} = object, choices) do + @spec vote(Object.t(), User.t(), list()) :: {:ok, list(), Object.t()} | {:error, any()} + def vote(%Object{data: %{"type" => "Question"}} = object, %User{} = user, choices) do with :ok <- validate_not_author(object, user), :ok <- validate_existing_votes(user, object), {:ok, options, choices} <- normalize_and_validate_choices(choices, object) do diff --git a/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex b/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex index b074ee405..a2af8148c 100644 --- a/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex @@ -51,7 +51,7 @@ defmodule Pleroma.Web.MastodonAPI.PollController do with %Object{data: %{"type" => "Question"}} = object <- Object.get_by_id(id), %Activity{} = activity <- Activity.get_create_by_object_ap_id(object.data["id"]), true <- Visibility.visible_for_user?(activity, user), - {:ok, _activities, object} <- get_cached_vote_or_vote(user, object, choices) do + {:ok, _activities, object} <- get_cached_vote_or_vote(object, user, choices) do try_render(conn, "show.json", %{object: object, for: user}) else nil -> render_error(conn, :not_found, "Record not found") @@ -60,11 +60,11 @@ defmodule Pleroma.Web.MastodonAPI.PollController do end end - defp get_cached_vote_or_vote(user, object, choices) do + defp get_cached_vote_or_vote(object, user, choices) do idempotency_key = "polls:#{user.id}:#{object.data["id"]}" @cachex.fetch!(:idempotency_cache, idempotency_key, fn _ -> - case CommonAPI.vote(user, object, choices) do + case CommonAPI.vote(object, user, choices) do {:error, _message} = res -> {:ignore, res} res -> {:commit, res} end diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index 8b3d01270..d476ad3f7 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -180,8 +180,8 @@ defmodule Pleroma.NotificationTest do question = insert(:question, user: user1) activity = insert(:question_activity, question: question) - {:ok, _, _} = CommonAPI.vote(user2, question, [0]) - {:ok, _, _} = CommonAPI.vote(user3, question, [1]) + {:ok, _, _} = CommonAPI.vote(question, user2, [0]) + {:ok, _, _} = CommonAPI.vote(question, user3, [1]) {:ok, notifications} = Notification.create_poll_notifications(activity) diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs index cc67b72d2..8adde8730 100644 --- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs @@ -1402,7 +1402,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do assert question = Object.normalize(activity, fetch: false) - {:ok, [activity], _object} = CommonAPI.vote(voter, question, [1]) + {:ok, [activity], _object} = CommonAPI.vote(question, voter, [1]) assert outbox_get = conn diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs index 47eea9a25..833c7fbf3 100644 --- a/test/pleroma/web/activity_pub/utils_test.exs +++ b/test/pleroma/web/activity_pub/utils_test.exs @@ -201,7 +201,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do }) object = Object.normalize(activity, fetch: false) - {:ok, votes, object} = CommonAPI.vote(other_user, object, [0, 1]) + {:ok, votes, object} = CommonAPI.vote(object, other_user, [0, 1]) assert Enum.sort(Utils.get_existing_votes(other_user.ap_id, object)) == Enum.sort(votes) end @@ -219,7 +219,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do }) object = Object.normalize(activity, fetch: false) - {:ok, [vote], object} = CommonAPI.vote(other_user, object, [0]) + {:ok, [vote], object} = CommonAPI.vote(object, other_user, [0]) {:ok, _activity} = CommonAPI.favorite(activity.id, user) [fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object) assert fetched_vote.id == vote.id diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index cc4482efe..381a8f37b 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1559,9 +1559,9 @@ defmodule Pleroma.Web.CommonAPITest do object = Object.normalize(activity, fetch: false) - {:ok, _, object} = CommonAPI.vote(other_user, object, [0]) + {:ok, _, object} = CommonAPI.vote(object, other_user, [0]) - assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1]) + assert {:error, "Already voted"} == CommonAPI.vote(object, other_user, [1]) end end diff --git a/test/pleroma/web/mastodon_api/views/poll_view_test.exs b/test/pleroma/web/mastodon_api/views/poll_view_test.exs index 3aa73c224..6de001421 100644 --- a/test/pleroma/web/mastodon_api/views/poll_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/poll_view_test.exs @@ -74,7 +74,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do object = Object.normalize(activity, fetch: false) - {:ok, _votes, object} = CommonAPI.vote(voter, object, [0, 1]) + {:ok, _votes, object} = CommonAPI.vote(object, voter, [0, 1]) assert match?( %{ @@ -119,7 +119,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do object = Object.normalize(activity, fetch: false) - {:ok, _, object} = CommonAPI.vote(other_user, object, [1, 2]) + {:ok, _, object} = CommonAPI.vote(object, other_user, [1, 2]) result = PollView.render("show.json", %{object: object, for: other_user})