From f602813d314533a50ab7cadf64f1f0fbbb863cc6 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Mon, 22 Jul 2024 17:49:30 -0400 Subject: [PATCH] Fix order of args for update/2 --- lib/pleroma/web/common_api.ex | 4 ++-- .../mastodon_api/controllers/status_controller.ex | 2 +- test/pleroma/integration/mastodon_websocket_test.exs | 2 +- test/pleroma/notification_test.exs | 4 ++-- .../article_note_page_validator_test.exs | 2 +- .../object_validators/update_handling_test.exs | 2 +- .../pleroma/web/activity_pub/transmogrifier_test.exs | 2 +- test/pleroma/web/common_api_test.exs | 12 ++++++------ .../mastodon_api/views/notification_view_test.exs | 2 +- .../web/mastodon_api/views/status_view_test.exs | 2 +- test/pleroma/web/metadata/utils_test.exs | 2 +- test/pleroma/web/push/impl_test.exs | 2 +- test/pleroma/web/rich_media/card_test.exs | 2 +- test/pleroma/web/streamer_test.exs | 10 +++++----- 14 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index f8a03680ac..cfb36bc1c7 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -461,8 +461,8 @@ def post(user, %{status: _} = data) do end end - @spec update(User.t(), Activity.t(), map()) :: {:ok, Activity.t()} | {:error, any()} - def update(user, orig_activity, changes) do + @spec update(Activity.t(), User.t(), map()) :: {:ok, Activity.t()} | {:error, any()} + def update(orig_activity, %User{} = user, changes) do with orig_object <- Object.normalize(orig_activity), {:ok, new_object} <- make_update_data(user, orig_object, changes), {:ok, update_data, _} <- Builder.update(user, new_object), diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index 80386dc45e..f75efd00df 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -276,7 +276,7 @@ def update( actor <- Activity.user_actor(activity), {_, true} <- {:own_status, actor.id == user.id}, changes <- body_params |> put_application(conn), - {_, {:ok, _update_activity}} <- {:pipeline, CommonAPI.update(user, activity, changes)}, + {_, {:ok, _update_activity}} <- {:pipeline, CommonAPI.update(activity, user, changes)}, {_, %Activity{}} = {_, activity} <- {:refetched, Activity.get_by_id_with_object(id)} do try_render(conn, "show.json", activity: activity, diff --git a/test/pleroma/integration/mastodon_websocket_test.exs b/test/pleroma/integration/mastodon_websocket_test.exs index a0ffddf8d0..49edeb91e5 100644 --- a/test/pleroma/integration/mastodon_websocket_test.exs +++ b/test/pleroma/integration/mastodon_websocket_test.exs @@ -440,7 +440,7 @@ test "receives edits", %{user: reading_user, token: token} do assert_receive {:text, _raw_json}, 1_000 - {:ok, _} = CommonAPI.update(user, activity, %{status: "mew mew", visibility: "private"}) + {:ok, _} = CommonAPI.update(activity, user, %{status: "mew mew", visibility: "private"}) assert_receive {:text, raw_json}, 1_000 diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index e9923cb56c..c7ed18bbaf 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -165,7 +165,7 @@ test "it sends edited notifications to those who repeated a status" do {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user) {:ok, _edit_activity} = - CommonAPI.update(user, activity_one, %{ + CommonAPI.update(activity_one, user, %{ status: "hey @#{other_user.nickname}! mew mew" }) @@ -748,7 +748,7 @@ test "it sends edited notifications to those who repeated a status" do {:ok, _activity_two} = CommonAPI.repeat(activity_one.id, repeated_user) {:ok, edit_activity} = - CommonAPI.update(user, activity_one, %{ + CommonAPI.update(activity_one, user, %{ status: "hey @#{other_user.nickname}! mew mew" }) diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs index 2b33950d6b..e1dbb20c3e 100644 --- a/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/article_note_page_validator_test.exs @@ -43,7 +43,7 @@ test "a note from factory validates" do setup do user = insert(:user) {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"}) - {:ok, edit} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "edited :blank:"}) + {:ok, edit} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "edited :blank:"}) {:ok, %{"object" => external_rep}} = Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data) diff --git a/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs b/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs index a09dbf5c60..c88339d14d 100644 --- a/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs @@ -132,7 +132,7 @@ test "returns object_data in meta for a remote Update" do setup do user = insert(:user) {:ok, activity} = Pleroma.Web.CommonAPI.post(user, %{status: "mew mew :dinosaur:"}) - {:ok, edit} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "edited :blank:"}) + {:ok, edit} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "edited :blank:"}) {:ok, external_rep} = Pleroma.Web.ActivityPub.Transmogrifier.prepare_outgoing(edit.data) %{external_rep: external_rep} end diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index 2fb0cd079b..6da7e4a89c 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -353,7 +353,7 @@ test "Updates of Notes are handled" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"}) - {:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew :blank:"}) + {:ok, update} = CommonAPI.update(activity, user, %{status: "mew mew :blank:"}) {:ok, prepared} = Transmogrifier.prepare_outgoing(update.data) diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 4f3bc69213..433278d394 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1753,7 +1753,7 @@ test "updates a post" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1"}) - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "updated 2" @@ -1767,7 +1767,7 @@ test "does not change visibility" do {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1", visibility: "private"}) - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "updated 2" @@ -1784,7 +1784,7 @@ test "updates a post with emoji" do {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "title 1 :#{emoji1}:"}) - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2 :#{emoji2}:"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2 :#{emoji2}:"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "updated 2 :#{emoji2}:" @@ -1803,7 +1803,7 @@ test "updates a post with emoji and federate properly" do with_mock Pleroma.Web.Federator, publish: fn _p -> nil end do - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2 :#{emoji2}:"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2 :#{emoji2}:"}) assert updated.data["object"]["content"] == "updated 2 :#{emoji2}:" assert %{^emoji2 => _} = updated.data["object"]["emoji"] @@ -1847,7 +1847,7 @@ test "editing a post that copied a remote title with remote emoji should keep th assert reply.object.data["emoji"]["remoteemoji"] == remote_emoji_uri {:ok, edit} = - CommonAPI.update(user, reply, %{status: "reply mew mew", spoiler_text: ":remoteemoji:"}) + CommonAPI.update(reply, user, %{status: "reply mew mew", spoiler_text: ":remoteemoji:"}) edited_note = Pleroma.Object.normalize(edit) @@ -1863,7 +1863,7 @@ test "respects MRF" do {:ok, activity} = CommonAPI.post(user, %{status: "foo1", spoiler_text: "updated 1"}) assert Object.normalize(activity).data["summary"] == "mewmew 1" - {:ok, updated} = CommonAPI.update(user, activity, %{status: "updated 2"}) + {:ok, updated} = CommonAPI.update(activity, user, %{status: "updated 2"}) updated_object = Object.normalize(updated) assert updated_object.data["content"] == "mewmew 2" diff --git a/test/pleroma/web/mastodon_api/views/notification_view_test.exs b/test/pleroma/web/mastodon_api/views/notification_view_test.exs index 003ac8c36a..3ad5e1606c 100644 --- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/notification_view_test.exs @@ -290,7 +290,7 @@ test "Edit notification" do {:ok, activity} = CommonAPI.post(user, %{status: "mew"}) {:ok, _} = CommonAPI.repeat(activity.id, repeat_user) - {:ok, update} = CommonAPI.update(user, activity, %{status: "mew mew"}) + {:ok, update} = CommonAPI.update(activity, user, %{status: "mew mew"}) user = Pleroma.User.get_by_ap_id(user.ap_id) activity = Pleroma.Activity.normalize(activity) diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index f42d9d1c63..cfcb8cfb22 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -938,7 +938,7 @@ test "it shows edited_at" do status = StatusView.render("show.json", activity: post) refute status.edited_at - {:ok, _} = CommonAPI.update(poster, post, %{status: "mew mew"}) + {:ok, _} = CommonAPI.update(post, poster, %{status: "mew mew"}) edited = Pleroma.Activity.normalize(post) status = StatusView.render("show.json", activity: edited) diff --git a/test/pleroma/web/metadata/utils_test.exs b/test/pleroma/web/metadata/utils_test.exs index 9bc02dadf6..f986d3fd5d 100644 --- a/test/pleroma/web/metadata/utils_test.exs +++ b/test/pleroma/web/metadata/utils_test.exs @@ -81,7 +81,7 @@ test "it does not return old content after editing" do object = Pleroma.Object.normalize(activity) assert Utils.scrub_html_and_truncate(object) == "mew mew #def" - {:ok, update} = Pleroma.Web.CommonAPI.update(user, activity, %{status: "mew mew #abc"}) + {:ok, update} = Pleroma.Web.CommonAPI.update(activity, user, %{status: "mew mew #abc"}) update = Pleroma.Activity.normalize(update) object = Pleroma.Object.normalize(update) assert Utils.scrub_html_and_truncate(object) == "mew mew #abc" diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs index 5e2b20ab56..dcd909f1cc 100644 --- a/test/pleroma/web/push/impl_test.exs +++ b/test/pleroma/web/push/impl_test.exs @@ -225,7 +225,7 @@ test "renders title and body for update activity" do {:ok, activity} = CommonAPI.post(user, %{status: "lorem ipsum"}) - {:ok, activity} = CommonAPI.update(user, activity, %{status: "edited status"}) + {:ok, activity} = CommonAPI.update(activity, user, %{status: "edited status"}) object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: activity, type: "update"}, user, object) == diff --git a/test/pleroma/web/rich_media/card_test.exs b/test/pleroma/web/rich_media/card_test.exs index 9541627c18..387defc8ce 100644 --- a/test/pleroma/web/rich_media/card_test.exs +++ b/test/pleroma/web/rich_media/card_test.exs @@ -70,7 +70,7 @@ test "recrawls URLs on status edits/updates" do Card.get_by_activity(activity) ) - {:ok, _} = CommonAPI.update(user, activity, %{status: "I like this site #{updated_url}"}) + {:ok, _} = CommonAPI.update(activity, user, %{status: "I like this site #{updated_url}"}) activity = Pleroma.Activity.get_by_id(activity.id) diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs index 978e8a8234..e53c6adc46 100644 --- a/test/pleroma/web/streamer_test.exs +++ b/test/pleroma/web/streamer_test.exs @@ -541,7 +541,7 @@ test "it streams edits in the 'user' stream", %{user: user, token: oauth_token} {:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) Streamer.get_topic_and_add_socket("user", user, oauth_token) - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"}) create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"]) assert_receive {:render_with_user, _, "status_update.json", ^create, _} @@ -552,7 +552,7 @@ test "it streams own edits in the 'user' stream", %{user: user, token: oauth_tok {:ok, activity} = CommonAPI.post(user, %{status: "hey"}) Streamer.get_topic_and_add_socket("user", user, oauth_token) - {:ok, edited} = CommonAPI.update(user, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, user, %{status: "mew mew"}) create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"]) assert_receive {:render_with_user, _, "status_update.json", ^create, _} @@ -608,7 +608,7 @@ test "it streams edits in the 'public' stream" do {:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) assert_receive {:text, _} - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"}) edited = Pleroma.Activity.normalize(edited) @@ -627,7 +627,7 @@ test "it streams multiple edits in the 'public' stream correctly" do {:ok, activity} = CommonAPI.post(sender, %{status: "hey"}) assert_receive {:text, _} - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew"}) edited = Pleroma.Activity.normalize(edited) @@ -638,7 +638,7 @@ test "it streams multiple edits in the 'public' stream correctly" do assert %{"id" => ^activity_id} = Jason.decode!(payload) refute Streamer.filtered_by_user?(sender, edited) - {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew 2"}) + {:ok, edited} = CommonAPI.update(activity, sender, %{status: "mew mew 2"}) edited = Pleroma.Activity.normalize(edited)