diff --git a/lib/pleroma/web/plugs/static_fe_plug.ex b/lib/pleroma/web/plugs/static_fe_plug.ex index 9ba9dc5ff..049a4ffbe 100644 --- a/lib/pleroma/web/plugs/static_fe_plug.ex +++ b/lib/pleroma/web/plugs/static_fe_plug.ex @@ -9,7 +9,7 @@ defmodule Pleroma.Web.Plugs.StaticFEPlug do def init(options), do: options def call(conn, _) do - if enabled?() and requires_html?(conn) do + if enabled?() and requires_html?(conn) and not_logged_in?(conn) do conn |> StaticFEController.call(:show) |> halt() @@ -23,4 +23,7 @@ defp enabled?, do: Pleroma.Config.get([:static_fe, :enabled], false) defp requires_html?(conn) do Phoenix.Controller.get_format(conn) == "html" end + + defp not_logged_in?(%{assigns: %{user: %Pleroma.User{}}}), do: false + defp not_logged_in?(_), do: true end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 2a4768d3a..22ff5326f 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -150,6 +150,8 @@ defmodule Pleroma.Web.Router do end pipeline :static_fe do + plug(:fetch_session) + plug(:authenticate) plug(Pleroma.Web.Plugs.StaticFEPlug) end diff --git a/lib/pleroma/web/static_fe/static_fe_controller.ex b/lib/pleroma/web/static_fe/static_fe_controller.ex index 6f73b575e..0a4327a56 100644 --- a/lib/pleroma/web/static_fe/static_fe_controller.ex +++ b/lib/pleroma/web/static_fe/static_fe_controller.ex @@ -180,15 +180,7 @@ defp represent(%Activity{object: %Object{data: data}} = activity, selected) do nil end - reply_to_user = - if data["inReplyTo"] do - activity - |> Activity.get_in_reply_to_activity() - |> Map.get(:actor) - |> User.get_cached_by_ap_id() - else - nil - end + reply_to_user = in_reply_to_user(activity) total_votes = if data["oneOf"] do @@ -217,6 +209,20 @@ defp represent(%Activity{object: %Object{data: data}} = activity, selected) do } end + defp in_reply_to_user(%Activity{object: %Object{data: %{"inReplyTo" => inReplyTo}}} = activity) when is_binary(inReplyTo) do + in_reply_to_activity = Activity.get_in_reply_to_activity(activity) + + if in_reply_to_activity do + in_reply_to_activity + |> Map.get(:actor) + |> User.get_cached_by_ap_id() + else + nil + end + end + + defp in_reply_to_user(_), do: nil + defp assign_id(%{path_info: ["notice", notice_id]} = conn, _opts), do: assign(conn, :notice_id, notice_id)