diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 541e5a559..97289635e 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -2409,7 +2409,10 @@ defp maybe_validate_rel_me_field(changeset, %User{ap_id: _ap_id} = struct) do defp maybe_validate_rel_me_field(changeset, _), do: changeset @spec validate_rel_me_field(Changeset.t(), [Map.t()], [Map.t()], User.t()) :: Changeset.t() - defp validate_rel_me_field(changeset, fields, raw_fields, %User{ap_id: ap_id}) do + defp validate_rel_me_field(changeset, fields, raw_fields, %User{ + nickname: nickname, + ap_id: ap_id + }) do fields = fields |> Enum.with_index() @@ -2417,7 +2420,16 @@ defp validate_rel_me_field(changeset, fields, raw_fields, %User{ap_id: ap_id}) d raw_value = Enum.at(raw_fields, index)["value"] if is_url(raw_value) do - with "me" <- RelMe.maybe_put_rel_me(raw_value, [ap_id]) do + frontend_url = + Pleroma.Web.Router.Helpers.redirect_url( + Pleroma.Web.Endpoint, + :redirector_with_meta, + nickname + ) + + possible_urls = [ap_id, frontend_url] + + with "me" <- RelMe.maybe_put_rel_me(raw_value, possible_urls) do %{ "name" => name, "value" => value, diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index c5b105cba..e9b8825bf 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -465,7 +465,7 @@ test "update fields", %{conn: conn} do ] end - test "update fields with a link to content with rel=me", %{user: user, conn: conn} do + test "update fields with a link to content with rel=me, with ap id", %{user: user, conn: conn} do Tesla.Mock.mock(fn %{url: "http://example.com/rel_me/ap_id"} -> %Tesla.Env{ @@ -481,12 +481,49 @@ test "update fields with a link to content with rel=me", %{user: user, conn: con |> patch("/api/v1/accounts/update_credentials", %{fields_attributes: [field]}) |> json_response_and_validate_schema(200) - assert [%{ - "name" => "Website", - "value" => - ~s[http://example.com/rel_me/ap_id], - "verified_at" => verified_at - }] = account_data["fields"] + assert [ + %{ + "name" => "Website", + "value" => + ~s[http://example.com/rel_me/ap_id], + "verified_at" => verified_at + } + ] = account_data["fields"] + + {:ok, verified_at, _} = DateTime.from_iso8601(verified_at) + assert DateTime.diff(DateTime.utc_now(), verified_at) < 10 + end + + test "update fields with a link to content with rel=me, with frontend path", %{ + user: user, + conn: conn + } do + fe_url = "#{Pleroma.Web.Endpoint.url()}/#{user.nickname}" + + Tesla.Mock.mock(fn + %{url: "http://example.com/rel_me/fe_path"} -> + %Tesla.Env{ + status: 200, + body: ~s[] + } + end) + + field = %{name: "Website", value: "http://example.com/rel_me/fe_path"} + + account_data = + conn + |> patch("/api/v1/accounts/update_credentials", %{fields_attributes: [field]}) + |> json_response_and_validate_schema(200) + + assert [ + %{ + "name" => "Website", + "value" => + ~s[http://example.com/rel_me/fe_path], + "verified_at" => verified_at + } + ] = account_data["fields"] + {:ok, verified_at, _} = DateTime.from_iso8601(verified_at) assert DateTime.diff(DateTime.utc_now(), verified_at) < 10 end