Pleroma/lib/pleroma/web/plugs/federating_plug.ex

33 lines
731 B
Elixir
Raw Normal View History

# Pleroma: A lightweight social networking server
2020-03-03 23:44:49 +01:00
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
2020-06-24 09:41:09 +02:00
defmodule Pleroma.Web.Plugs.FederatingPlug do
2018-11-05 15:19:03 +01:00
import Plug.Conn
def init(options) do
options
end
2018-12-09 10:12:48 +01:00
def call(conn, _opts) do
if federating?() do
2018-11-05 15:19:03 +01:00
conn
else
fail(conn)
2018-11-05 15:19:03 +01:00
end
end
def federating?, do: Pleroma.Config.get([:instance, :federating])
# Definition for the use in :if_func / :unless_func plug options
def federating?(_conn), do: federating?()
defp fail(conn) do
conn
|> put_status(404)
|> Phoenix.Controller.put_view(Pleroma.Web.ErrorView)
|> Phoenix.Controller.render("404.json")
|> halt()
end
2018-11-05 15:19:03 +01:00
end