Fix nonexisting user will not generate metadata for search engine opt-out

This commit is contained in:
tusooa 2024-10-02 18:39:14 -04:00
parent d2eb4992e2
commit 35bd197733
No known key found for this signature in database
GPG key ID: 42AEC43D48433C51
9 changed files with 26 additions and 4 deletions

View file

@ -0,0 +1 @@
Fix nonexisting user will not generate metadata for search engine opt-out

View file

@ -46,7 +46,7 @@ def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id}
redirector_with_meta(conn, %{user: user})
else
nil ->
redirector(conn, params)
redirector_with_meta(conn, Map.delete(params, "maybe_nickname_or_id"))
end
end

View file

@ -15,11 +15,11 @@ defmodule Pleroma.Web.Feed.UserController do
action_fallback(:errors)
def feed_redirect(%{assigns: %{format: "html"}} = conn, %{"nickname" => nickname}) do
def feed_redirect(%{assigns: %{format: "html"}} = conn, %{"nickname" => nickname} = params) do
with {_, %User{} = user} <- {:fetch_user, User.get_cached_by_nickname_or_id(nickname)} do
Pleroma.Web.Fallback.RedirectController.redirector_with_meta(conn, %{user: user})
else
_ -> Pleroma.Web.Fallback.RedirectController.redirector(conn, nil)
_ -> Pleroma.Web.Fallback.RedirectController.redirector_with_meta(conn, params)
end
end

View file

@ -20,4 +20,7 @@ def build_tags(%{user: user}) do
], []}
]
end
@impl Provider
def build_tags(_), do: []
end

View file

@ -67,6 +67,9 @@ def build_tags(%{user: user}) do
end
end
@impl Provider
def build_tags(_), do: []
defp build_attachments(%{data: %{"attachment" => attachments}}) do
Enum.reduce(attachments, [], fn attachment, acc ->
rendered_tags =

View file

@ -20,6 +20,9 @@ def build_tags(%{user: user}) do
end)
end
@impl Provider
def build_tags(_), do: []
defp append_fields_tag(bio, fields) do
fields
|> Enum.reduce(bio, fn %{"value" => v}, res -> res <> v end)

View file

@ -44,6 +44,9 @@ def build_tags(%{user: user}) do
end
end
@impl Provider
def build_tags(_), do: []
defp title_tag(user) do
{:meta, [name: "twitter:title", content: Utils.user_name_string(user)], []}
end

View file

@ -32,7 +32,7 @@ test "GET /:maybe_nickname_or_id with missing user", %{conn: conn} do
resp = get(conn, "/foo")
assert html_response(resp, 200) =~ "<title>a cool title</title>"
refute html_response(resp, 200) =~ "initial-results"
assert html_response(resp, 200) =~ "<meta content=\"noindex, noarchive\" name=\"robots\">"
end
test "GET /*path", %{conn: conn} do

View file

@ -147,6 +147,15 @@ test "returns 404 for a missing feed", %{conn: conn} do
assert response(conn, 404)
end
test "returns noindex meta for missing user", %{conn: conn} do
conn =
conn
|> put_req_header("accept", "text/html")
|> get("/users/nonexisting")
assert html_response(conn, 200) =~ "<meta content=\"noindex, noarchive\" name=\"robots\">"
end
test "returns feed with public and unlisted activities", %{conn: conn} do
user = insert(:user)