From 80a4e30be7f41142e2f64868d2af2c468d0bdf41 Mon Sep 17 00:00:00 2001 From: Oneric Date: Thu, 27 Jun 2024 18:27:18 +0200 Subject: [PATCH 01/10] Upgrade captach dep Fixes a deprecation warning showing up each mix call when using elixir 1.17 --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 7ffc450e2..b147f2681 100644 --- a/mix.exs +++ b/mix.exs @@ -180,7 +180,7 @@ defp deps do {:remote_ip, "~> 1.1.0"}, {:captcha, git: "https://git.pleroma.social/pleroma/elixir-libraries/elixir-captcha.git", - ref: "90f6ce7672f70f56708792a98d98bd05176c9176"}, + ref: "6630c42aaaab124e697b4e513190c89d8b64e410"}, {:restarter, path: "./restarter"}, {:majic, git: "https://akkoma.dev/AkkomaGang/majic.git", From 7cd395415210f5a981d45e26bc6e21e078ee96cd Mon Sep 17 00:00:00 2001 From: Oneric Date: Thu, 20 Jun 2024 19:52:31 +0200 Subject: [PATCH 02/10] Remove superfluous actor key suffix Fragments are already always stripped anyway so listing one specific fragment here is unnecessary and potentially confusing. This effectively reverts 4457928e325cf370a0d2e028232dbd0a542547e0 but keeps the added bridgy testcase. --- lib/pleroma/signature.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/signature.ex b/lib/pleroma/signature.ex index c4ac2c87e..3d33fcd62 100644 --- a/lib/pleroma/signature.ex +++ b/lib/pleroma/signature.ex @@ -10,7 +10,7 @@ defmodule Pleroma.Signature do alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub - @known_suffixes ["/publickey", "/main-key", "#key"] + @known_suffixes ["/publickey", "/main-key"] def key_id_to_actor_id(key_id) do uri = From 95ed4931f8660df352a4f80f9b4767dba94f1eea Mon Sep 17 00:00:00 2001 From: Oneric Date: Thu, 20 Jun 2024 19:52:34 +0200 Subject: [PATCH 03/10] docs: note frontend tasks need to be run as akkoma user Fixes: https://akkoma.dev/AkkomaGang/akkoma/issues/748 --- docs/docs/installation/frontends.include | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/docs/installation/frontends.include b/docs/docs/installation/frontends.include index 6da4018a9..094cfe4bd 100644 --- a/docs/docs/installation/frontends.include +++ b/docs/docs/installation/frontends.include @@ -6,7 +6,9 @@ probably install frontends. These are no longer bundled with the distribution and need an extra command to install. -For most installations, the following will suffice: +You **must** run frontend management tasks as the akkoma user, +the same way you downloaded the build or cloned the git repo before. +But otherwise, for most installations, the following will suffice: === "OTP" ```sh @@ -28,4 +30,3 @@ For most installations, the following will suffice: ``` For more customised installations, refer to [Frontend Management](../../configuration/frontend_management) - From 0ab2f2ab457d16894c3a4affb77cd66a33901437 Mon Sep 17 00:00:00 2001 From: Oneric Date: Thu, 20 Jun 2024 19:52:39 +0200 Subject: [PATCH 04/10] ci: retry failed tasks once We have a bunch of mysterious sporadic failures which usually disappear when rerunning failed jobs only. Ideally we should locate and fix the cause of those psoradic failures, but until we figure this out retrying once makes CI status less useless. --- .woodpecker/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml index 81c779b50..45cf7f93d 100644 --- a/.woodpecker/test.yml +++ b/.woodpecker/test.yml @@ -87,5 +87,5 @@ steps: - mix ecto.create - mix ecto.migrate - mkdir -p test/tmp - - mix test --preload-modules --exclude erratic --exclude federated --exclude mocked - - mix test --preload-modules --only mocked + - mix test --preload-modules --exclude erratic --exclude federated --exclude mocked || mix test --failed + - mix test --preload-modules --only mocked || mix test --failed From 07539f78257c366536341063c547a63eee6ef160 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 18 Jun 2024 10:50:31 -0400 Subject: [PATCH 05/10] Hide logs during test unless a test fails Currently `mix test` prints a slew of logs in the terminal with messages from different tests intermsparsed. Globally enabling capture log hides log messages unless a test fails reducing noise and making it easier to anylse the important (from failed tests) messages. Compiler warnings and a few messages not printed via Logger still show up but its much more readable than before. Ported from: https://git.pleroma.social/pleroma/pleroma/-/commit/3aed111a42472018f01899714305d4f3a5cbc911 --- test/mix/tasks/pleroma/config_test.exs | 1 - test/pleroma/object/fetcher_test.exs | 1 - test/pleroma/user_test.exs | 2 -- .../web/activity_pub/activity_pub_controller_test.exs | 4 ---- test/pleroma/web/activity_pub/relay_test.exs | 1 - .../activity_pub/transmogrifier/announce_handling_test.exs | 2 -- .../activity_pub/transmogrifier/delete_handling_test.exs | 1 - .../web/activity_pub/transmogrifier/note_handling_test.exs | 2 -- test/pleroma/web/activity_pub/transmogrifier_test.exs | 1 - .../web/mastodon_api/controllers/search_controller_test.exs | 1 - .../mastodon_api/controllers/timeline_controller_test.exs | 2 -- test/pleroma/web/push/impl_test.exs | 2 -- test/pleroma/web/web_finger_test.exs | 1 - test/test_helper.exs | 6 +++++- 14 files changed, 5 insertions(+), 22 deletions(-) diff --git a/test/mix/tasks/pleroma/config_test.exs b/test/mix/tasks/pleroma/config_test.exs index 3b09f656b..75c67efb4 100644 --- a/test/mix/tasks/pleroma/config_test.exs +++ b/test/mix/tasks/pleroma/config_test.exs @@ -51,7 +51,6 @@ test "error if file with custom settings doesn't exist" do clear_config(:configurable_from_database, true) end - @tag capture_log: true test "config migration refused when deprecated settings are found" do clear_config([:media_proxy, :whitelist], ["domain_without_scheme.com"]) assert config_records() == [] diff --git a/test/pleroma/object/fetcher_test.exs b/test/pleroma/object/fetcher_test.exs index 12154cb05..74f2cd31f 100644 --- a/test/pleroma/object/fetcher_test.exs +++ b/test/pleroma/object/fetcher_test.exs @@ -189,7 +189,6 @@ defp spoofed_object_with_ids( :ok end - @tag capture_log: true test "it works when fetching the OP actor errors out" do # Here we simulate a case where the author of the OP can't be read assert {:ok, _} = diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index de71f4b95..90cee1c65 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -814,7 +814,6 @@ test "gets an existing user by fully qualified nickname, case insensitive" do assert user == fetched_user end - @tag capture_log: true test "returns nil if no user could be fetched" do {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la") assert fetched_user == "not found nonexistant@social.heldscal.la" @@ -871,7 +870,6 @@ test "if nicknames clash, the old user gets a prefix with the old id to the nick assert orig_user.nickname == "#{orig_user.id}.admin@mastodon.example.org" end - @tag capture_log: true test "it returns the old user if stale, but unfetchable" do a_week_ago = NaiveDateTime.add(NaiveDateTime.utc_now(), -604_800) 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 b325bcb9a..4c134c8f2 100644 --- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs @@ -573,7 +573,6 @@ test "it inserts an incoming activity into the database", %{conn: conn} do assert Activity.get_by_ap_id(data["id"]) end - @tag capture_log: true test "it inserts an incoming activity into the database" <> "even if we can't fetch the user but have it in our db", %{conn: conn} do @@ -1074,7 +1073,6 @@ test "it clears `unreachable` federation status of the sender", %{conn: conn, da assert Instances.reachable?(sender_host) end - @tag capture_log: true test "it removes all follower collections but actor's", %{conn: conn} do [actor, recipient] = insert_pair(:user) @@ -1138,7 +1136,6 @@ test "it requires authentication", %{conn: conn} do assert json_response(ret_conn, 200) end - @tag capture_log: true test "forwarded report", %{conn: conn} do admin = insert(:user, is_admin: true) actor = insert(:user, local: false) @@ -1215,7 +1212,6 @@ test "forwarded report", %{conn: conn} do ) end - @tag capture_log: true test "forwarded report from mastodon", %{conn: conn} do admin = insert(:user, is_admin: true) actor = insert(:user, local: false) diff --git a/test/pleroma/web/activity_pub/relay_test.exs b/test/pleroma/web/activity_pub/relay_test.exs index 920aef9da..99cc2071e 100644 --- a/test/pleroma/web/activity_pub/relay_test.exs +++ b/test/pleroma/web/activity_pub/relay_test.exs @@ -114,7 +114,6 @@ test "returns error when activity not `Create` type" do assert Relay.publish(activity) == {:error, "Not implemented"} end - @tag capture_log: true test "returns error when activity not public" do activity = insert(:direct_note_activity) assert Relay.publish(activity) == {:error, false} diff --git a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs index 524acddaf..88f42cada 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs @@ -83,7 +83,6 @@ test "it works for incoming announces, fetching the announced object" do assert(Activity.get_create_by_object_ap_id(data["object"])) end - @tag capture_log: true test "it works for incoming announces with an existing activity" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "hey"}) @@ -136,7 +135,6 @@ test "it works for incoming announces with an inlined activity" do assert object.data["content"] == "this is a private toot" end - @tag capture_log: true test "it rejects incoming announces with an inlined activity from another origin" do Tesla.Mock.mock(fn %{method: :get} -> %Tesla.Env{status: 404, body: ""} diff --git a/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs index b7160bf58..e5d6f940a 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs @@ -86,7 +86,6 @@ test "it fails for incoming deletes with spoofed origin" do assert match?({:error, _}, Transmogrifier.handle_incoming(data)) end - @tag capture_log: true test "it works for incoming user deletes" do %{ap_id: ap_id} = insert(:user, ap_id: "http://mastodon.example.org/users/admin") diff --git a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs index 16ee31483..6a7bd3a43 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs @@ -57,7 +57,6 @@ test "it ignores an incoming notice if we already have it" do assert activity == returned_activity end - @tag capture_log: true test "it fetches reply-to activities if we don't have them" do data = File.read!("test/fixtures/mastodon-post-activity.json") @@ -537,7 +536,6 @@ test "returns object with inReplyTo when denied incoming reply", %{data: data} d assert modified_object["inReplyTo"] == [] end - @tag capture_log: true test "returns modified object when allowed incoming reply", %{data: data} do object_with_reply = Map.put( diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index dd7977593..1be69317c 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -561,7 +561,6 @@ test "returns nil when cannot normalize object" do end) =~ ":valid_uri_scheme" end - @tag capture_log: true test "returns {:ok, %Object{}} for success case" do assert {:ok, %Object{}} = Transmogrifier.get_obj_helper( diff --git a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs index 6a0d25058..64364cfb3 100644 --- a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs @@ -79,7 +79,6 @@ test "search", %{conn: conn} do assert status["id"] == to_string(activity.id) end - @tag capture_log: true test "constructs hashtags from search query", %{conn: conn} do results = conn diff --git a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs index 3e7b6730c..ccaf17fe4 100644 --- a/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/timeline_controller_test.exs @@ -152,7 +152,6 @@ test "filtering", %{conn: conn, user: user} do end describe "public" do - @tag capture_log: true test "the public timeline", %{conn: conn} do user = insert(:user) @@ -810,7 +809,6 @@ test "filtering", %{user: user, conn: conn} do describe "hashtag" do setup do: oauth_access(["n/a"]) - @tag capture_log: true test "hashtag timeline", %{conn: conn} do following = insert(:user) diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs index a40c4ff13..f9936095f 100644 --- a/test/pleroma/web/push/impl_test.exs +++ b/test/pleroma/web/push/impl_test.exs @@ -67,7 +67,6 @@ test "performs sending notifications" do assert Impl.perform(notif) == {:ok, [:ok, :ok]} end - @tag capture_log: true test "returns error if notif does not match " do assert Impl.perform(%{}) == {:error, :unknown_type} end @@ -76,7 +75,6 @@ test "successful message sending" do assert Impl.push_message(@message, @sub, @api_key, %Subscription{}) == :ok end - @tag capture_log: true test "fail message sending" do assert Impl.push_message( @message, diff --git a/test/pleroma/web/web_finger_test.exs b/test/pleroma/web/web_finger_test.exs index 2af084090..4fc2a8ffa 100644 --- a/test/pleroma/web/web_finger_test.exs +++ b/test/pleroma/web/web_finger_test.exs @@ -190,7 +190,6 @@ test "prevents spoofing" do end end - @tag capture_log: true test "prevents forgeries" do Tesla.Mock.mock(fn %{url: "https://bad.com/.well-known/webfinger?resource=acct:meanie@bad.com"} -> diff --git a/test/test_helper.exs b/test/test_helper.exs index dafa45099..6dcb87ff6 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -3,7 +3,11 @@ # SPDX-License-Identifier: AGPL-3.0-only os_exclude = if :os.type() == {:unix, :darwin}, do: [skip_on_mac: true], else: [] -ExUnit.start(exclude: [:federated, :erratic] ++ os_exclude) + +ExUnit.start( + capture_log: true, + exclude: [:federated, :erratic] ++ os_exclude +) Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, :manual) From cf19d4901f688016835e4b4f17a998a6b0816d56 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Tue, 18 Jun 2024 15:25:17 +0000 Subject: [PATCH 06/10] Disable Ecto query logging in tests The debug logs are very noisy and can be enabled during analysis of a specific error believed to be SQL-related -- Before log capturing those debug messages were still hidden, but with log capturing they show up in the output of failed tests unless disabled. Cherry-picked-from: https://git.pleroma.social/pleroma/pleroma/-/commit/e628d00a81ce18eaa54c6efb1e48a31d57216368 --- config/test.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/test.exs b/config/test.exs index 1df360ec7..556b9e78c 100644 --- a/config/test.exs +++ b/config/test.exs @@ -51,7 +51,8 @@ hostname: System.get_env("DB_HOST") || "localhost", pool: Ecto.Adapters.SQL.Sandbox, pool_size: 50, - queue_target: 5000 + queue_target: 5000, + log: false config :pleroma, :dangerzone, override_repo_pool_size: true From 495a1a71e89f3a3b67f9948f5e241a8b195f5ecf Mon Sep 17 00:00:00 2001 From: Oneric Date: Fri, 21 Jun 2024 18:30:47 +0200 Subject: [PATCH 07/10] strip_metadata: skip BMP files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not _yet_ supported as of exiftool 12.87, though at first glance it seems like standard BMP files can't store any metadata besides colour profiles Fixes the specific case from https://akkoma.dev/AkkomaGang/akkoma-fe/issues/396 although the frontend shouldn’t get bricked regardless. --- lib/pleroma/upload/filter/exiftool/strip_metadata.ex | 1 + .../upload/filter/exiftool/strip_location_test.exs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/pleroma/upload/filter/exiftool/strip_metadata.ex b/lib/pleroma/upload/filter/exiftool/strip_metadata.ex index 912ff6a92..a2604a682 100644 --- a/lib/pleroma/upload/filter/exiftool/strip_metadata.ex +++ b/lib/pleroma/upload/filter/exiftool/strip_metadata.ex @@ -18,6 +18,7 @@ defmodule Pleroma.Upload.Filter.Exiftool.StripMetadata do # Formats not compatible with exiftool at this time def filter(%Pleroma.Upload{content_type: "image/webp"}), do: {:ok, :noop} + def filter(%Pleroma.Upload{content_type: "image/bmp"}), do: {:ok, :noop} def filter(%Pleroma.Upload{content_type: "image/svg+xml"}), do: {:ok, :noop} def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do diff --git a/test/pleroma/upload/filter/exiftool/strip_location_test.exs b/test/pleroma/upload/filter/exiftool/strip_location_test.exs index 2e017cd7e..1f798556b 100644 --- a/test/pleroma/upload/filter/exiftool/strip_location_test.exs +++ b/test/pleroma/upload/filter/exiftool/strip_location_test.exs @@ -115,6 +115,15 @@ test "verify webp files are skipped" do assert Filter.Exiftool.StripMetadata.filter(upload) == {:ok, :noop} end + test "verify bmp files are skipped" do + upload = %Pleroma.Upload{ + name: "sample.bmp", + content_type: "image/bmp" + } + + assert Filter.Exiftool.StripMetadata.filter(upload) == {:ok, :noop} + end + test "verify svg files are skipped" do upload = %Pleroma.Upload{ name: "sample.svg", From ca182a0ae7cde1838b6f1c63b7348af7eb6b45b1 Mon Sep 17 00:00:00 2001 From: Oneric Date: Thu, 20 Jun 2024 19:52:43 +0200 Subject: [PATCH 08/10] Correctly parse content types with multiple profiles Multiple profiles can be specified as a space-separated list and the possibility of additional profiles is explicitly brought up in ActivityStream spec --- CHANGELOG.md | 1 + lib/pleroma/object/fetcher.ex | 8 ++++++-- test/pleroma/object/fetcher_test.exs | 22 +++++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c743e5bd..d1e3a42c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Fixed - Meilisearch: order of results returned from our REST API now actually matches how Meilisearch ranks results +- AP objects with additional JSON-LD profiles beyond ActivityStreams can now be fetched ## Changed - Refactored Rich Media to cache the content in the database. Fetching operations that could block status rendering have been eliminated. diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex index 937026e04..54ea9e74e 100644 --- a/lib/pleroma/object/fetcher.ex +++ b/lib/pleroma/object/fetcher.ex @@ -369,8 +369,12 @@ def get_object(id) do {"activity+json", _} -> {:ok, final_id, body} - {"ld+json", %{"profile" => "https://www.w3.org/ns/activitystreams"}} -> - {:ok, final_id, body} + {"ld+json", %{"profile" => profiles}} -> + if "https://www.w3.org/ns/activitystreams" in String.split(profiles) do + {:ok, final_id, body} + else + {:error, {:content_type, content_type}} + end _ -> {:error, {:content_type, content_type}} diff --git a/test/pleroma/object/fetcher_test.exs b/test/pleroma/object/fetcher_test.exs index 74f2cd31f..62dd64625 100644 --- a/test/pleroma/object/fetcher_test.exs +++ b/test/pleroma/object/fetcher_test.exs @@ -754,7 +754,7 @@ test "should return ok if the content type is application/activity+json" do assert {:ok, _, "{}"} = Fetcher.get_object("https://mastodon.social/2") end - test "should return ok if the content type is application/ld+json with a profile" do + test "should return ok if the content type is application/ld+json with the ActivityStream profile" do Tesla.Mock.mock(fn %{ method: :get, @@ -774,6 +774,26 @@ test "should return ok if the content type is application/ld+json with a profile assert {:ok, _, "{}"} = Fetcher.get_object("https://mastodon.social/2") end + test "should return ok if the content type is application/ld+json with several profiles" do + Tesla.Mock.mock(fn + %{ + method: :get, + url: "https://mastodon.social/2" + } -> + %Tesla.Env{ + status: 200, + url: "https://mastodon.social/2", + headers: [ + {"content-type", + "application/ld+json; profile=\"https://example.org/ns/superduperspec https://www.w3.org/ns/activitystreams\""} + ], + body: "{}" + } + end) + + assert {:ok, _, "{}"} = Fetcher.get_object("https://mastodon.social/2") + end + test "should not return ok with other content types" do Tesla.Mock.mock(fn %{ From d488cf476ea2ea662c5ec6acfa319331c3490d27 Mon Sep 17 00:00:00 2001 From: Oneric Date: Thu, 20 Jun 2024 19:52:47 +0200 Subject: [PATCH 09/10] Fix voters count field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mastodon API demands this be null unless it’s a multi-selection poll. Not abiding by this can mess up display in some clients. Fixes: https://akkoma.dev/AkkomaGang/akkoma/issues/190 --- CHANGELOG.md | 2 ++ lib/pleroma/web/api_spec/schemas/poll.ex | 4 +++- lib/pleroma/web/mastodon_api/views/poll_view.ex | 14 +++++++++++--- .../web/mastodon_api/views/poll_view_test.exs | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1e3a42c0..0d451dca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Fixed - Meilisearch: order of results returned from our REST API now actually matches how Meilisearch ranks results - AP objects with additional JSON-LD profiles beyond ActivityStreams can now be fetched +- Single-selection polls no longer expose the voter_count; MastoAPI demands it be null + and this confused some clients leading to vote distributions >100% ## Changed - Refactored Rich Media to cache the content in the database. Fetching operations that could block status rendering have been eliminated. diff --git a/lib/pleroma/web/api_spec/schemas/poll.ex b/lib/pleroma/web/api_spec/schemas/poll.ex index 943ad8bd4..13a5e8be2 100644 --- a/lib/pleroma/web/api_spec/schemas/poll.ex +++ b/lib/pleroma/web/api_spec/schemas/poll.ex @@ -32,7 +32,9 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Poll do }, voters_count: %Schema{ type: :integer, - description: "How many unique accounts have voted. Number." + nullable: true, + description: + "How many unique accounts have voted for a multi-selection poll. Number, or null if single-selection poll." }, voted: %Schema{ type: :boolean, diff --git a/lib/pleroma/web/mastodon_api/views/poll_view.ex b/lib/pleroma/web/mastodon_api/views/poll_view.ex index aa6443754..411cbd15a 100644 --- a/lib/pleroma/web/mastodon_api/views/poll_view.ex +++ b/lib/pleroma/web/mastodon_api/views/poll_view.ex @@ -19,7 +19,7 @@ def render("show.json", %{object: object, multiple: multiple, options: options} expired: expired, multiple: multiple, votes_count: votes_count, - voters_count: voters_count(object), + voters_count: voters_count(multiple, object), options: options, emojis: Pleroma.Web.MastodonAPI.StatusView.build_emojis(object.data["emoji"]) } @@ -68,11 +68,19 @@ defp options_and_votes_count(options) do end) end - defp voters_count(%{data: %{"voters" => voters}}) when is_list(voters) do + defp voters_count(false, _poll_data) do + # Mastodon always sets voter count to "null" unless multiple options were selectable + # Some clients may rely on this to detect multiple selection polls and it can mess + # up percentages for some clients if we never got a correct remote voter count and + # only count local voters here; see https://akkoma.dev/AkkomaGang/akkoma/issues/190 + nil + end + + defp voters_count(_multiple, %{data: %{"voters" => voters}}) when is_list(voters) do length(voters) end - defp voters_count(_), do: 0 + defp voters_count(_, _), do: 0 defp voted_and_own_votes(%{object: object} = params, options) do if params[:for] do 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 224b26cb9..91d95f229 100644 --- a/test/pleroma/web/mastodon_api/views/poll_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/poll_view_test.exs @@ -43,7 +43,7 @@ test "renders a poll" do %{title: "why are you even asking?", votes_count: 0} ], votes_count: 0, - voters_count: 0 + voters_count: nil } result = PollView.render("show.json", %{object: object}) From a3101a435bae8bba7da77bba52d80e06b85593a4 Mon Sep 17 00:00:00 2001 From: Oneric Date: Thu, 20 Jun 2024 19:53:03 +0200 Subject: [PATCH 10/10] Fix swagger-ui Ever since the browser frontend switcher was introduced in de64c6c54aaacc4123031f2e3d5bfb9fc9c517fe /akkoma counts as an API prefix and thus gets skipped by frontend plugs breaking the old swagger ui path of /akkoma/swagger-ui. Do the simple thing and change the frontend path to /pleroma/swaggerui which isn't an API path and can't collide with frontend user paths given pleroma is areserved nickname. Reported in https://meta.akkoma.dev/t/view-all-endpoints/269/7 https://meta.akkoma.dev/t/swagger-ui-not-loading/728 --- CHANGELOG.md | 1 + docs/docs/configuration/cheatsheet.md | 2 +- docs/docs/configuration/frontend_management.md | 2 +- lib/pleroma/web/endpoint.ex | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d451dca8..d2fcd752c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## BREAKING - Minimum PostgreSQL version is raised to 12 +- Swagger UI moved from `/akkoma/swaggerui/` to `/pleroma/swaggerui/` ## Added - Implement [FEP-67ff](https://codeberg.org/fediverse/fep/src/branch/main/fep/67ff/fep-67ff.md) (federation documentation) diff --git a/docs/docs/configuration/cheatsheet.md b/docs/docs/configuration/cheatsheet.md index 80f5c3577..916e1cc0c 100644 --- a/docs/docs/configuration/cheatsheet.md +++ b/docs/docs/configuration/cheatsheet.md @@ -338,7 +338,7 @@ config :pleroma, :frontends, * `:primary` - The frontend that will be served at `/` * `:admin` - The frontend that will be served at `/pleroma/admin` -* `:swagger` - Config for developers to act as an API reference to be served at `/akkoma/swaggerui/` (trailing slash _needed_). Disabled by default. +* `:swagger` - Config for developers to act as an API reference to be served at `/pleroma/swaggerui/` (trailing slash _needed_). Disabled by default. * `:mastodon` - The mastodon-fe configuration. This shouldn't need to be changed. This is served at `/web` when installed. ### :static\_fe diff --git a/docs/docs/configuration/frontend_management.md b/docs/docs/configuration/frontend_management.md index bc5344826..8875ee279 100644 --- a/docs/docs/configuration/frontend_management.md +++ b/docs/docs/configuration/frontend_management.md @@ -60,4 +60,4 @@ config :pleroma, :frontends, Then run the [pleroma.frontend cli task](../../administration/CLI_tasks/frontend) with the name of `swagger-ui` to install the distribution files. -You will now be able to view documentation at `/akkoma/swaggerui` +You will now be able to view documentation at `/pleroma/swaggerui` diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index 6628fcaf3..3c9fcb48c 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -66,10 +66,10 @@ defmodule Pleroma.Web.Endpoint do } ) - plug(Plug.Static.IndexHtml, at: "/akkoma/swaggerui") + plug(Plug.Static.IndexHtml, at: "/pleroma/swaggerui/") plug(Pleroma.Web.Plugs.FrontendStatic, - at: "/akkoma/swaggerui", + at: "/pleroma/swaggerui", frontend_type: :swagger, gzip: true, if: &Pleroma.Web.Swagger.ui_enabled?/0,