Fix nonexisting user will not generate metadata for search engine opt-out
This commit is contained in:
parent
d2eb4992e2
commit
35bd197733
9 changed files with 26 additions and 4 deletions
1
changelog.d/se-opt-out.change
Normal file
1
changelog.d/se-opt-out.change
Normal file
|
@ -0,0 +1 @@
|
|||
Fix nonexisting user will not generate metadata for search engine opt-out
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -20,4 +20,7 @@ def build_tags(%{user: user}) do
|
|||
], []}
|
||||
]
|
||||
end
|
||||
|
||||
@impl Provider
|
||||
def build_tags(_), do: []
|
||||
end
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue