diff options
author | lain <lain@soykaf.club> | 2020-07-08 10:55:03 +0000 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-07-08 10:55:03 +0000 |
commit | 6335b32aa8f5c54cf5f09638189a77cad5785077 (patch) | |
tree | 5b30a357982a9a04cadf0ea7f1ccb905f50db270 /lib | |
parent | a8447c3803b9d618f8c1d1910698c8cca6e908e4 (diff) | |
parent | a6495f4a686feb3d4728432dd075f425c04c32dd (diff) | |
download | pleroma-6335b32aa8f5c54cf5f09638189a77cad5785077.tar.gz pleroma-6335b32aa8f5c54cf5f09638189a77cad5785077.zip |
Merge branch '1895-hashtag-timeline-restrict-unauthenticated-fix' into 'develop'
[#1895] Made hashtag timeline respect `:restrict_unauthenticated` instance setting
Closes #1895
See merge request pleroma/pleroma!2731
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex index 4bdd46d7e..ab7b1d6aa 100644 --- a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex @@ -88,21 +88,20 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do ) end + defp restrict_unauthenticated?(true = _local_only) do + Pleroma.Config.get([:restrict_unauthenticated, :timelines, :local]) + end + + defp restrict_unauthenticated?(_) do + Pleroma.Config.get([:restrict_unauthenticated, :timelines, :federated]) + end + # GET /api/v1/timelines/public def public(%{assigns: %{user: user}} = conn, params) do local_only = params[:local] - cfg_key = - if local_only do - :local - else - :federated - end - - restrict? = Pleroma.Config.get([:restrict_unauthenticated, :timelines, cfg_key]) - - if restrict? and is_nil(user) do - render_error(conn, :unauthorized, "authorization required for timeline view") + if is_nil(user) and restrict_unauthenticated?(local_only) do + fail_on_bad_auth(conn) else activities = params @@ -123,6 +122,10 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do end end + defp fail_on_bad_auth(conn) do + render_error(conn, :unauthorized, "authorization required for timeline view") + end + defp hashtag_fetching(params, user, local_only) do tags = [params[:tag], params[:any]] @@ -157,15 +160,20 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do # GET /api/v1/timelines/tag/:tag def hashtag(%{assigns: %{user: user}} = conn, params) do local_only = params[:local] - activities = hashtag_fetching(params, user, local_only) - conn - |> add_link_headers(activities, %{"local" => local_only}) - |> render("index.json", - activities: activities, - for: user, - as: :activity - ) + if is_nil(user) and restrict_unauthenticated?(local_only) do + fail_on_bad_auth(conn) + else + activities = hashtag_fetching(params, user, local_only) + + conn + |> add_link_headers(activities, %{"local" => local_only}) + |> render("index.json", + activities: activities, + for: user, + as: :activity + ) + end end # GET /api/v1/timelines/list/:list_id |