mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2025-01-03 05:48:42 +00:00
Merge branch 'hashtag-feeds-restricted' into 'develop'
Repesct :restrict_unauthenticated for hashtag rss/atom feeds See merge request pleroma/pleroma!4266
This commit is contained in:
commit
ddedc575e7
3 changed files with 61 additions and 2 deletions
1
changelog.d/hashtag-feeds-restricted.add
Normal file
1
changelog.d/hashtag-feeds-restricted.add
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Repesct :restrict_unauthenticated for hashtag rss/atom feeds
|
|
@ -10,7 +10,7 @@ defmodule Pleroma.Web.Feed.TagController do
|
||||||
alias Pleroma.Web.Feed.FeedView
|
alias Pleroma.Web.Feed.FeedView
|
||||||
|
|
||||||
def feed(conn, params) do
|
def feed(conn, params) do
|
||||||
if Config.get!([:instance, :public]) do
|
if not Config.restrict_unauthenticated_access?(:timelines, :local) do
|
||||||
render_feed(conn, params)
|
render_feed(conn, params)
|
||||||
else
|
else
|
||||||
render_error(conn, :not_found, "Not found")
|
render_error(conn, :not_found, "Not found")
|
||||||
|
@ -18,10 +18,12 @@ defmodule Pleroma.Web.Feed.TagController do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp render_feed(conn, %{"tag" => raw_tag} = params) do
|
defp render_feed(conn, %{"tag" => raw_tag} = params) do
|
||||||
|
local_only = Config.restrict_unauthenticated_access?(:timelines, :federated)
|
||||||
|
|
||||||
{format, tag} = parse_tag(raw_tag)
|
{format, tag} = parse_tag(raw_tag)
|
||||||
|
|
||||||
activities =
|
activities =
|
||||||
%{type: ["Create"], tag: tag}
|
%{type: ["Create"], tag: tag, local_only: local_only}
|
||||||
|> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
|
|> Pleroma.Maps.put_if_present(:max_id, params["max_id"])
|
||||||
|> ActivityPub.fetch_public_activities()
|
|> ActivityPub.fetch_public_activities()
|
||||||
|
|
||||||
|
|
|
@ -191,4 +191,60 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
||||||
|> response(404)
|
|> response(404)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "restricted for unauthenticated" do
|
||||||
|
test "returns 404 when local timeline is disabled", %{conn: conn} do
|
||||||
|
clear_config([:restrict_unauthenticated, :timelines], %{local: true, federated: false})
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/rss+xml")
|
||||||
|
|> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
|
||||||
|
|> response(404)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns local posts only when federated timeline is disabled", %{conn: conn} do
|
||||||
|
clear_config([:restrict_unauthenticated, :timelines], %{local: false, federated: true})
|
||||||
|
|
||||||
|
local_user = insert(:user)
|
||||||
|
remote_user = insert(:user, local: false)
|
||||||
|
|
||||||
|
local_note =
|
||||||
|
insert(:note,
|
||||||
|
user: local_user,
|
||||||
|
data: %{
|
||||||
|
"content" => "local post #PleromaArt",
|
||||||
|
"summary" => "",
|
||||||
|
"tag" => ["pleromaart"]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
remote_note =
|
||||||
|
insert(:note,
|
||||||
|
user: remote_user,
|
||||||
|
data: %{
|
||||||
|
"content" => "remote post #PleromaArt",
|
||||||
|
"summary" => "",
|
||||||
|
"tag" => ["pleromaart"]
|
||||||
|
},
|
||||||
|
local: false
|
||||||
|
)
|
||||||
|
|
||||||
|
insert(:note_activity, user: local_user, note: local_note)
|
||||||
|
insert(:note_activity, user: remote_user, note: remote_note, local: false)
|
||||||
|
|
||||||
|
response =
|
||||||
|
conn
|
||||||
|
|> put_req_header("accept", "application/rss+xml")
|
||||||
|
|> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
|
||||||
|
|> response(200)
|
||||||
|
|
||||||
|
xml = parse(response)
|
||||||
|
|
||||||
|
assert xpath(xml, ~x"//channel/title/text()") == ~c"#pleromaart"
|
||||||
|
|
||||||
|
assert xpath(xml, ~x"//channel/item/title/text()"l) == [
|
||||||
|
~c"local post #PleromaArt"
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue