Redirect to standard FE if logged in
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Wed, 7 Dec 2022 13:35:00 +0000 (13:35 +0000)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Wed, 7 Dec 2022 13:35:00 +0000 (13:35 +0000)
lib/pleroma/web/plugs/static_fe_plug.ex
lib/pleroma/web/router.ex
lib/pleroma/web/static_fe/static_fe_controller.ex

index 9ba9dc5ffbba66a235472d93a596c7dc01980b16..049a4ffbe351ac8fc861f309d7288ef839aa1be8 100644 (file)
@@ -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 @@ defmodule Pleroma.Web.Plugs.StaticFEPlug do
   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
index 22a35e8e2cd20a6c0c3da982082a54ede7cb872f..f2ea679a0ef8f3792ceb100dbb29bd7ed8259f14 100644 (file)
@@ -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
 
index 6f73b575e2a751245256d634d54b0f08287f46c6..0a4327a563930e9209219c94968b76c00fcbfab6 100644 (file)
@@ -180,15 +180,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEController 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 @@ defmodule Pleroma.Web.StaticFE.StaticFEController 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)