2019-12-03 10:29:51 +00:00
|
|
|
# Portions of this file are derived from Pleroma:
|
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-01-26 20:36:50 +00:00
|
|
|
defmodule Mobilizon.Web.Plugs.Federating do
|
2019-12-03 10:29:51 +00:00
|
|
|
@moduledoc """
|
|
|
|
Restrict ActivityPub routes when not federating
|
|
|
|
"""
|
2020-01-22 23:55:07 +00:00
|
|
|
|
2019-12-03 10:29:51 +00:00
|
|
|
import Plug.Conn
|
|
|
|
|
2021-09-28 17:40:37 +00:00
|
|
|
@spec init(any()) :: any()
|
2019-12-03 10:29:51 +00:00
|
|
|
def init(options) do
|
|
|
|
options
|
|
|
|
end
|
|
|
|
|
2021-09-28 17:40:37 +00:00
|
|
|
@spec call(Plug.Conn.t(), Keyword.t()) :: Plug.Conn.t()
|
2019-12-03 10:29:51 +00:00
|
|
|
def call(conn, _opts) do
|
|
|
|
if Mobilizon.Config.get([:instance, :federating]) do
|
|
|
|
conn
|
|
|
|
else
|
|
|
|
conn
|
|
|
|
|> put_status(404)
|
2020-01-26 20:36:50 +00:00
|
|
|
|> Phoenix.Controller.put_view(Mobilizon.Web.ErrorView)
|
2019-12-03 10:29:51 +00:00
|
|
|
|> Phoenix.Controller.render("404.json")
|
|
|
|
|> halt()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|