From 2899feb4d9de61947ede66a1c0bcc3d07030cccc Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 26 Nov 2022 13:57:08 -0600 Subject: [PATCH 1/4] Fix remote follow redirect --- .../twitter_api/controllers/remote_follow_controller.ex | 6 +++--- .../web/twitter_api/remote_follow_controller_test.exs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/web/twitter_api/controllers/remote_follow_controller.ex b/lib/pleroma/web/twitter_api/controllers/remote_follow_controller.ex index 6229d5d05b..656d59a775 100644 --- a/lib/pleroma/web/twitter_api/controllers/remote_follow_controller.ex +++ b/lib/pleroma/web/twitter_api/controllers/remote_follow_controller.ex @@ -74,7 +74,7 @@ defp is_status?(acct) do def do_follow(%{assigns: %{user: %User{} = user}} = conn, %{"user" => %{"id" => id}}) do with {:fetch_user, %User{} = followee} <- {:fetch_user, User.get_cached_by_id(id)}, {:ok, _, _, _} <- CommonAPI.follow(user, followee) do - redirect(conn, to: "/users/#{followee.id}") + redirect(conn, to: "/users/#{followee.nickname}") else error -> handle_follow_error(conn, error) @@ -91,7 +91,7 @@ def do_follow(conn, %{"authorization" => %{"name" => _, "password" => _, "id" => {_, {:ok, user}, _} <- {:auth, WrapperAuthenticator.get_user(conn), followee}, {_, _, _, false} <- {:mfa_required, followee, user, MFA.require?(user)}, {:ok, _, _, _} <- CommonAPI.follow(user, followee) do - redirect(conn, to: "/users/#{followee.id}") + redirect(conn, to: "/users/#{followee.nickname}") else error -> handle_follow_error(conn, error) @@ -109,7 +109,7 @@ def do_follow(conn, %{"mfa" => %{"code" => code, "token" => token, "id" => id}}) {_, _, _, {:ok, _}} <- {:verify_mfa_code, followee, token, TOTPAuthenticator.verify(code, user)}, {:ok, _, _, _} <- CommonAPI.follow(user, followee) do - redirect(conn, to: "/users/#{followee.id}") + redirect(conn, to: "/users/#{followee.nickname}") else error -> handle_follow_error(conn, error) diff --git a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs index 1194e0afea..9b266840f5 100644 --- a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs +++ b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs @@ -167,7 +167,7 @@ test "follows user", %{conn: conn} do |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:follows"])) |> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}}) - assert redirected_to(conn) == "/users/#{user2.id}" + assert redirected_to(conn) == "/users/#{user2.nickname}" end test "returns error when user is deactivated", %{conn: conn} do @@ -222,7 +222,7 @@ test "returns success result when user already in followers", %{conn: conn} do |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:follows"])) |> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}}) - assert redirected_to(conn) == "/users/#{user2.id}" + assert redirected_to(conn) == "/users/#{user2.nickname}" end end @@ -304,7 +304,7 @@ test "follows", %{conn: conn} do } ) - assert redirected_to(conn) == "/users/#{user2.id}" + assert redirected_to(conn) == "/users/#{user2.nickname}" assert user2.follower_address in User.following(user) end @@ -350,7 +350,7 @@ test "follows", %{conn: conn} do "authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id} }) - assert redirected_to(conn) == "/users/#{user2.id}" + assert redirected_to(conn) == "/users/#{user2.nickname}" assert user2.follower_address in User.following(user) end From 0ab061f37592d7b9ec1c89f9a8c7654ac81f72ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Fri, 2 Dec 2022 11:20:48 +0000 Subject: [PATCH 2/4] Add missing rel_me cache --- lib/pleroma/application.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 5f9b35860c..2ac001a84b 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -213,7 +213,8 @@ defp cachex_children do expiration: chat_message_id_idempotency_key_expiration(), limit: 500_000 ), - build_cachex("translations", default_ttl: :timer.hours(24), limit: 5_000) + build_cachex("translations", default_ttl: :timer.hours(24), limit: 5_000), + build_cachex("rel_me", default_ttl: :timer.minutes(30), limit: 2_500) ] end From d4904b392a468797d3d0c08d1ac34e2904dc801f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Fri, 2 Dec 2022 17:41:38 +0100 Subject: [PATCH 3/4] Actually fix verified_at MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- lib/pleroma/user.ex | 5 +++-- .../web/mastodon_api/controllers/account_controller.ex | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 91dd9eeec7..3479232252 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -2713,10 +2713,11 @@ def sanitize_html(%User{} = user) do # - display name def sanitize_html(%User{} = user, filter) do fields = - Enum.map(user.fields, fn %{"name" => name, "value" => value} -> + Enum.map(user.fields, fn %{"name" => name, "value" => value} = field -> %{ "name" => name, - "value" => HTML.filter_tags(value, Pleroma.HTML.Scrubber.LinksOnly) + "value" => HTML.filter_tags(value, Pleroma.HTML.Scrubber.LinksOnly), + "verified_at" => Map.get(field, "verified_at") } end) diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index f54e0589e0..11ed75bda8 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -259,7 +259,9 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p defp normalize_fields_attributes(fields) do if Enum.all?(fields, &is_tuple/1) do - Enum.map(fields, fn {_, v} -> v end) + Enum.map(fields, fn {_, %{} = field} -> + %{"name" => field["name"], "value" => field["value"]} + end) else Enum.map(fields, fn %{} = field -> %{"name" => field.name, "value" => field.value} From 5bc41489525bc8ae94393424f3a33e5f37862a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Fri, 2 Dec 2022 18:03:07 +0100 Subject: [PATCH 4/4] fix tests? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../mastodon_api/update_credentials_test.exs | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index abc984fdb7..ba183adc29 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -351,8 +351,12 @@ test "updates profile emojos", %{user: user, conn: conn} do test "update fields", %{conn: conn} do fields = [ - %{"name" => "foo", "value" => ""}, - %{"name" => "link.io", "value" => "cofe.io"} + %{ + "name" => "foo", + "value" => "", + "verified_at" => nil + }, + %{"name" => "link.io", "value" => "cofe.io", "verified_at" => nil} ] account_data = @@ -361,10 +365,15 @@ test "update fields", %{conn: conn} do |> json_response_and_validate_schema(200) assert account_data["fields"] == [ - %{"name" => "foo", "value" => "bar"}, + %{ + "name" => "foo", + "value" => "bar", + "verified_at" => nil + }, %{ "name" => "link.io", - "value" => ~S(cofe.io) + "value" => ~S(cofe.io), + "verified_at" => nil } ] @@ -433,8 +442,8 @@ test "emojis in fields labels", %{conn: conn} do |> json_response_and_validate_schema(200) assert account_data["fields"] == [ - %{"name" => ":firefox:", "value" => "is best 2hu"}, - %{"name" => "they wins", "value" => ":blank:"} + %{"name" => ":firefox:", "value" => "is best 2hu", "verified_at" => nil}, + %{"name" => "they wins", "value" => ":blank:", "verified_at" => nil} ] assert account_data["source"]["fields"] == [ @@ -462,10 +471,11 @@ test "update fields via x-www-form-urlencoded", %{conn: conn} do |> json_response_and_validate_schema(200) assert account["fields"] == [ - %{"name" => "foo", "value" => "bar"}, + %{"name" => "foo", "value" => "bar", "verified_at" => nil}, %{ "name" => "link", - "value" => ~S(http://cofe.io) + "value" => ~S(http://cofe.io), + "verified_at" => nil } ] @@ -487,7 +497,7 @@ test "update fields with empty name", %{conn: conn} do |> json_response_and_validate_schema(200) assert account["fields"] == [ - %{"name" => "foo", "value" => ""} + %{"name" => "foo", "value" => "", "verified_at" => nil} ] end