forked from AkkomaGang/akkoma
Do not serve RSS/Atom feeds when instance is private
This commit is contained in:
parent
44ced17634
commit
a85ed6defb
5 changed files with 59 additions and 10 deletions
|
@ -9,7 +9,15 @@ defmodule Pleroma.Web.Feed.TagController do
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||||
alias Pleroma.Web.Feed.FeedView
|
alias Pleroma.Web.Feed.FeedView
|
||||||
|
|
||||||
def feed(conn, %{"tag" => raw_tag} = params) do
|
def feed(conn, params) do
|
||||||
|
if Pleroma.Config.get!([:instance, :public]) do
|
||||||
|
render_feed(conn, params)
|
||||||
|
else
|
||||||
|
render_error(conn, :not_found, "Not found")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_feed(conn, %{"tag" => raw_tag} = params) do
|
||||||
{format, tag} = parse_tag(raw_tag)
|
{format, tag} = parse_tag(raw_tag)
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
|
|
|
@ -37,7 +37,15 @@ def feed_redirect(conn, %{"nickname" => nickname}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def feed(conn, %{"nickname" => nickname} = params) do
|
def feed(conn, params) do
|
||||||
|
if Pleroma.Config.get!([:instance, :public]) do
|
||||||
|
render_feed(conn, params)
|
||||||
|
else
|
||||||
|
errors(conn, {:error, :not_found})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def render_feed(conn, %{"nickname" => nickname} = params) do
|
||||||
format = get_format(conn)
|
format = get_format(conn)
|
||||||
|
|
||||||
format =
|
format =
|
||||||
|
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.Metadata.Providers.Feed do
|
||||||
|
|
||||||
@impl Provider
|
@impl Provider
|
||||||
def build_tags(%{user: user}) do
|
def build_tags(%{user: user}) do
|
||||||
|
if Pleroma.Config.get!([:instance, :public]) do
|
||||||
[
|
[
|
||||||
{:link,
|
{:link,
|
||||||
[
|
[
|
||||||
|
@ -19,5 +20,8 @@ def build_tags(%{user: user}) do
|
||||||
href: Helpers.user_feed_path(Endpoint, :feed, user.nickname) <> ".atom"
|
href: Helpers.user_feed_path(Endpoint, :feed, user.nickname) <> ".atom"
|
||||||
], []}
|
], []}
|
||||||
]
|
]
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -181,4 +181,17 @@ test "gets a feed (RSS)", %{conn: conn} do
|
||||||
'yeah #PleromaArt'
|
'yeah #PleromaArt'
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "private instance" do
|
||||||
|
setup do: clear_config([:instance, :public])
|
||||||
|
|
||||||
|
test "returns 404 for tags feed", %{conn: conn} do
|
||||||
|
Config.put([:instance, :public], false)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/rss+xml")
|
||||||
|
|> get(tag_feed_path(conn, :feed, "pleromaart"))
|
||||||
|
|> response(404)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -246,4 +246,20 @@ test "with non-html / non-json format, it returns error when user is not found",
|
||||||
assert response == ~S({"error":"Not found"})
|
assert response == ~S({"error":"Not found"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "private instance" do
|
||||||
|
setup do: clear_config([:instance, :public])
|
||||||
|
|
||||||
|
test "returns 404 for user feed", %{conn: conn} do
|
||||||
|
Config.put([:instance, :public], false)
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, _} = CommonAPI.post(user, %{status: "test"})
|
||||||
|
|
||||||
|
assert conn
|
||||||
|
|> put_req_header("accept", "application/atom+xml")
|
||||||
|
|> get(user_feed_path(conn, :feed, user.nickname))
|
||||||
|
|> response(404)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue