[#2497] Specified SHELL in .gitlab-ci.yml as required for `exexec`.
[akkoma] / lib / pleroma / web / controller_helper.ex
index 4780081b26868bb3ba08f6b508ed14782fbe3999..5a1316a5f166f5871be0cb75e059de9299f96735 100644 (file)
@@ -5,8 +5,6 @@
 defmodule Pleroma.Web.ControllerHelper do
   use Pleroma.Web, :controller
 
-  alias Pleroma.Config
-
   # As in Mastodon API, per https://api.rubyonrails.org/classes/ActiveModel/Type/Boolean.html
   @falsy_param_values [false, 0, "0", "f", "F", "false", "False", "FALSE", "off", "OFF"]
 
@@ -82,8 +80,9 @@ defmodule Pleroma.Web.ControllerHelper do
     end
   end
 
-  def assign_account_by_id(%{params: %{"id" => id}} = conn, _) do
-    case Pleroma.User.get_cached_by_id(id) do
+  def assign_account_by_id(conn, _) do
+    # TODO: use `conn.params[:id]` only after moving to OpenAPI
+    case Pleroma.User.get_cached_by_id(conn.params[:id] || conn.params["id"]) do
       %Pleroma.User{} = account -> assign(conn, :account, account)
       nil -> Pleroma.Web.MastodonAPI.FallbackController.call(conn, {:error, :not_found}) |> halt()
     end
@@ -105,13 +104,16 @@ defmodule Pleroma.Web.ControllerHelper do
 
   def put_if_exist(map, key, value), do: Map.put(map, key, value)
 
-  @doc "Whether to skip rendering `[:account][:pleroma][:relationship]`for statuses/notifications"
-  def skip_relationships?(params) do
-    if Config.get([:extensions, :output_relationships_in_statuses_by_default]) do
-      false
-    else
-      # BREAKING: older PleromaFE versions do not send this param but _do_ expect relationships.
-      not truthy_param?(params["with_relationships"])
-    end
+  @doc """
+  Returns true if request specifies to include embedded relationships in account objects.
+  May only be used in selected account-related endpoints; has no effect for status- or
+    notification-related endpoints.
+  """
+  # Intended for PleromaFE: https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838
+  def embed_relationships?(params) do
+    # To do once OpenAPI transition mess is over: just `truthy_param?(params[:with_relationships])`
+    params
+    |> Map.get(:with_relationships, params["with_relationships"])
+    |> truthy_param?()
   end
 end