Merge branch 'develop' into chore/elixir-1.11
authorMark Felder <feld@FreeBSD.org>
Tue, 13 Oct 2020 14:54:53 +0000 (09:54 -0500)
committerMark Felder <feld@FreeBSD.org>
Tue, 13 Oct 2020 14:54:53 +0000 (09:54 -0500)
1  2 
config/config.exs
lib/phoenix/transports/web_socket/raw.ex
lib/pleroma/application.ex
lib/pleroma/web.ex
lib/pleroma/web/activity_pub/activity_pub_controller.ex
lib/pleroma/web/common_api/utils.ex
lib/pleroma/web/mastodon_api/controllers/auth_controller.ex
lib/pleroma/web/mastodon_api/controllers/status_controller.ex
lib/pleroma/web/media_proxy/invalidation/http.ex

diff --combined config/config.exs
index 47fc7957b5c28e58d1e70561073b8f89e1dfaf50,273da5bb6728faf2daf12f5bee3e66c01347d12b..3d1f4d4ba10dc59c3e36559951c292653674f0d6
@@@ -123,6 -123,7 +123,6 @@@ websocket_config = 
  
  # Configures the endpoint
  config :pleroma, Pleroma.Web.Endpoint,
 -  instrumenters: [Pleroma.Web.Endpoint.Instrumenter],
    url: [host: "localhost"],
    http: [
      ip: {127, 0, 0, 1},
    secret_key_base: "aK4Abxf29xU9TTDKre9coZPUgevcVCFQJe/5xP/7Lt4BEif6idBIbjupVbOrbKxl",
    signing_salt: "CqaoopA2",
    render_errors: [view: Pleroma.Web.ErrorView, accepts: ~w(json)],
 -  pubsub: [name: Pleroma.PubSub, adapter: Phoenix.PubSub.PG2],
 +  pubsub_server: Pleroma.PubSub,
    secure_cookie_flag: true,
    extra_cookie_attrs: [
      "SameSite=Lax"
@@@ -676,7 -677,18 +676,18 @@@ config :pleroma, :rate_limit
  
  config :pleroma, Pleroma.Workers.PurgeExpiredActivity, enabled: true, min_lifetime: 600
  
- config :pleroma, Pleroma.Plugs.RemoteIp, enabled: true
+ config :pleroma, Pleroma.Web.Plugs.RemoteIp,
+   enabled: true,
+   headers: ["x-forwarded-for"],
+   proxies: [],
+   reserved: [
+     "127.0.0.0/8",
+     "::1/128",
+     "fc00::/7",
+     "10.0.0.0/8",
+     "172.16.0.0/12",
+     "192.168.0.0/16"
+   ]
  
  config :pleroma, :static_fe, enabled: false
  
index c3665bebe95ad9deb9d2a6f2a251519f74688279,aab7fad99cc14cc2061571bf3a437226d74b581a..c3665bebe95ad9deb9d2a6f2a251519f74688279
@@@ -31,12 -31,7 +31,12 @@@ defmodule Phoenix.Transports.WebSocket.
  
      case conn do
        %{halted: false} = conn ->
 -        case Transport.connect(endpoint, handler, transport, __MODULE__, nil, conn.params) do
 +        case handler.connect(%{
 +               endpoint: endpoint,
 +               transport: transport,
 +               options: [serializer: nil],
 +               params: conn.params
 +             }) do
            {:ok, socket} ->
              {:ok, conn, {__MODULE__, {socket, opts}}}
  
index fe94b56f4af129af269507cc89270857ec52fcc9,958e32db248075c33db6211e6aa4f9651b543f92..4b2512acd1012f6798518c98c93f706e2846bd2b
@@@ -52,7 -52,7 +52,7 @@@ defmodule Pleroma.Application d
      Pleroma.HTML.compile_scrubbers()
      Pleroma.Config.Oban.warn()
      Config.DeprecationWarnings.warn()
-     Pleroma.Plugs.HTTPSecurityPlug.warn_if_disabled()
+     Pleroma.Web.Plugs.HTTPSecurityPlug.warn_if_disabled()
      Pleroma.ApplicationRequirements.verify!()
      setup_instrumenters()
      load_custom_modules()
@@@ -88,7 -88,7 +88,7 @@@
          Pleroma.Repo,
          Config.TransferTask,
          Pleroma.Emoji,
-         Pleroma.Plugs.RateLimiter.Supervisor
+         Pleroma.Web.Plugs.RateLimiter.Supervisor
        ] ++
          cachex_children() ++
          http_children(adapter, @env) ++
@@@ -99,7 -99,7 +99,7 @@@
          ] ++
          task_children(@env) ++
          dont_run_in_test(@env) ++
 -        chat_child(@env, chat_enabled?()) ++
 +        chat_child(chat_enabled?()) ++
          [
            Pleroma.Web.Endpoint,
            Pleroma.Gopher.Server
      ]
    end
  
 -  defp chat_child(_env, true) do
 -    [Pleroma.Web.ChatChannel.ChatChannelState]
 +  defp chat_child(true) do
 +    [
 +      Pleroma.Web.ChatChannel.ChatChannelState,
 +      {Phoenix.PubSub, [name: Pleroma.PubSub, adapter: Phoenix.PubSub.PG2]}
 +    ]
    end
  
 -  defp chat_child(_, _), do: []
 +  defp chat_child(_), do: []
  
    defp task_children(:test) do
      [
diff --combined lib/pleroma/web.ex
index c319d223c89b2bbc6195a047c1c09068ea3bde51,7779826e3e1a6a1696e35e0c81be517d23e91939..6ed19d3dd9dfdf5c345564a680c0073992c6bd91
@@@ -2,11 -2,6 +2,6 @@@
  # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  # SPDX-License-Identifier: AGPL-3.0-only
  
- defmodule Pleroma.Web.Plug do
-   # Substitute for `call/2` which is defined with `use Pleroma.Web, :plug`
-   @callback perform(Plug.Conn.t(), Plug.opts()) :: Plug.Conn.t()
- end
  defmodule Pleroma.Web do
    @moduledoc """
    A module that keeps using definitions for controllers,
    below.
    """
  
-   alias Pleroma.Plugs.EnsureAuthenticatedPlug
-   alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
-   alias Pleroma.Plugs.ExpectAuthenticatedCheckPlug
-   alias Pleroma.Plugs.ExpectPublicOrAuthenticatedCheckPlug
-   alias Pleroma.Plugs.OAuthScopesPlug
-   alias Pleroma.Plugs.PlugHelper
+   alias Pleroma.Web.Plugs.EnsureAuthenticatedPlug
+   alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
+   alias Pleroma.Web.Plugs.ExpectAuthenticatedCheckPlug
+   alias Pleroma.Web.Plugs.ExpectPublicOrAuthenticatedCheckPlug
+   alias Pleroma.Web.Plugs.OAuthScopesPlug
+   alias Pleroma.Web.Plugs.PlugHelper
  
    def controller do
      quote do
    def channel do
      quote do
        # credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
 -      use Phoenix.Channel
 +      import Phoenix.Channel
        import Pleroma.Web.Gettext
      end
    end
index 8916aba5fbda726d6812b0d9e7ae3a1a091c8eef,6bf7421bb6e9df004577262dd22c919f0543c489..c3fce711de6c97e15c2120bf4a9f842cc3504938
@@@ -9,7 -9,6 +9,6 @@@ defmodule Pleroma.Web.ActivityPub.Activ
    alias Pleroma.Delivery
    alias Pleroma.Object
    alias Pleroma.Object.Fetcher
-   alias Pleroma.Plugs.EnsureAuthenticatedPlug
    alias Pleroma.User
    alias Pleroma.Web.ActivityPub.ActivityPub
    alias Pleroma.Web.ActivityPub.Builder
@@@ -23,8 -22,9 +22,9 @@@
    alias Pleroma.Web.ActivityPub.Visibility
    alias Pleroma.Web.ControllerHelper
    alias Pleroma.Web.Endpoint
-   alias Pleroma.Web.FederatingPlug
    alias Pleroma.Web.Federator
+   alias Pleroma.Web.Plugs.EnsureAuthenticatedPlug
+   alias Pleroma.Web.Plugs.FederatingPlug
  
    require Logger
  
@@@ -46,7 -46,7 +46,7 @@@
    )
  
    plug(
-     Pleroma.Plugs.Cache,
+     Pleroma.Web.Plugs.Cache,
      [query_params: false, tracking_fun: &__MODULE__.track_object_fetch/2]
      when action in [:activity, :object]
    )
        object =
          object
          |> Map.merge(Map.take(params, ["to", "cc"]))
 -        |> Map.put("attributedTo", user.ap_id())
 +        |> Map.put("attributedTo", user.ap_id)
          |> Transmogrifier.fix_object()
  
        ActivityPub.create(%{
          %{assigns: %{user: %User{nickname: nickname} = user}} = conn,
          %{"nickname" => nickname} = params
        ) do
 -    actor = user.ap_id()
 +    actor = user.ap_id
  
      params =
        params
index 85dcd89dc999915258a7cd5c46c1831b6c375dff,21f4d43e9be78d13293f4b7acb130f97b0854267..3b71adf0e577b1fdabaa50c5b7917968c7f02681
@@@ -12,12 -12,12 +12,12 @@@ defmodule Pleroma.Web.CommonAPI.Utils d
    alias Pleroma.Conversation.Participation
    alias Pleroma.Formatter
    alias Pleroma.Object
-   alias Pleroma.Plugs.AuthenticationPlug
    alias Pleroma.Repo
    alias Pleroma.User
    alias Pleroma.Web.ActivityPub.Utils
    alias Pleroma.Web.ActivityPub.Visibility
    alias Pleroma.Web.MediaProxy
+   alias Pleroma.Web.Plugs.AuthenticationPlug
  
    require Logger
    require Pleroma.Constants
    def format_input(text, format, options \\ [])
  
    @doc """
 -  Formatting text to plain text.
 +  Formatting text to plain text, BBCode, HTML, or Markdown
    """
    def format_input(text, "text/plain", options) do
      text
          end).()
    end
  
 -  @doc """
 -  Formatting text as BBCode.
 -  """
    def format_input(text, "text/bbcode", options) do
      text
      |> String.replace(~r/\r/, "")
      |> Formatter.linkify(options)
    end
  
 -  @doc """
 -  Formatting text to html.
 -  """
    def format_input(text, "text/html", options) do
      text
      |> Formatter.html_escape("text/html")
      |> Formatter.linkify(options)
    end
  
 -  @doc """
 -  Formatting text to markdown.
 -  """
    def format_input(text, "text/markdown", options) do
      text
      |> Formatter.mentions_escape(options)
index a278ca622e06e09caab64dccc01113e161e19cec,75b809aabf7c1767a64f05c38387130a92ea8ee0..9cc3984d0cd33fafaf9ccbd0229a5a0e082a4331
@@@ -15,7 -15,7 +15,7 @@@ defmodule Pleroma.Web.MastodonAPI.AuthC
  
    action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
  
-   plug(Pleroma.Plugs.RateLimiter, [name: :password_reset] when action == :password_reset)
+   plug(Pleroma.Web.Plugs.RateLimiter, [name: :password_reset] when action == :password_reset)
  
    @local_mastodon_name "Mastodon-Local"
  
@@@ -24,7 -24,7 +24,7 @@@
      redirect(conn, to: local_mastodon_root_path(conn))
    end
  
 -  @doc "Local Mastodon FE login init action"
 +  # Local Mastodon FE login init action
    def login(conn, %{"code" => auth_token}) do
      with {:ok, app} <- get_or_make_app(),
           {:ok, auth} <- Authorization.get_by_token(app, auth_token),
@@@ -35,7 -35,7 +35,7 @@@
      end
    end
  
 -  @doc "Local Mastodon FE callback action"
 +  # Local Mastodon FE callback action
    def login(conn, _) do
      with {:ok, app} <- get_or_make_app() do
        path =
index a47a7af95702205c412afcf52750aee0ca49d1aa,08d6c1c22daba11208775b28121239110b4f9919..6848adace711aab8ee9b496d2eea58c4e2604181
@@@ -13,8 -13,6 +13,6 @@@ defmodule Pleroma.Web.MastodonAPI.Statu
    alias Pleroma.Activity
    alias Pleroma.Bookmark
    alias Pleroma.Object
-   alias Pleroma.Plugs.OAuthScopesPlug
-   alias Pleroma.Plugs.RateLimiter
    alias Pleroma.Repo
    alias Pleroma.ScheduledActivity
    alias Pleroma.User
    alias Pleroma.Web.CommonAPI
    alias Pleroma.Web.MastodonAPI.AccountView
    alias Pleroma.Web.MastodonAPI.ScheduledActivityView
+   alias Pleroma.Web.Plugs.OAuthScopesPlug
+   alias Pleroma.Web.Plugs.RateLimiter
  
    plug(Pleroma.Web.ApiSpec.CastAndValidate)
-   plug(:skip_plug, Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug when action in [:index, :show])
+   plug(
+     :skip_plug,
+     Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug when action in [:index, :show]
+   )
  
    @unauthenticated_access %{fallback: :proceed_unauthenticated, scopes: []}
  
  
    @doc """
    POST /api/v1/statuses
 -
 -  Creates a scheduled status when `scheduled_at` param is present and it's far enough
    """
 +  # Creates a scheduled status when `scheduled_at` param is present and it's far enough
    def create(
          %{
            assigns: %{user: user},
      end
    end
  
 -  @doc """
 -  POST /api/v1/statuses
 -
 -  Creates a regular status
 -  """
 +  # Creates a regular status
    def create(%{assigns: %{user: user}, body_params: %{status: _} = params} = conn, _) do
      params = Map.put(params, :in_reply_to_status_id, params[:in_reply_to_id])
  
index 0b0cde68c39ce38d6ebd64c67504330221264f59,bb81d8888365d2e88b50e215f3d418bacd69e8fd..0b0cde68c39ce38d6ebd64c67504330221264f59
@@@ -30,7 -30,7 +30,7 @@@ defmodule Pleroma.Web.MediaProxy.Invali
        {:ok, %{status: status} = env} when 400 <= status and status < 500 ->
          {:error, env}
  
 -      {:error, error} = error ->
 +      {:error, _} = error ->
          error
  
        _ ->