diff options
author | kaniini <nenolod@gmail.com> | 2018-11-01 09:10:51 +0000 |
---|---|---|
committer | kaniini <nenolod@gmail.com> | 2018-11-01 09:10:51 +0000 |
commit | eba9a62024a6acd4722745850cb7c0ea0502304f (patch) | |
tree | 0718445dc136d70c7a3182c5e130062da0e3c26d /lib | |
parent | 40676d768307d43de075f6ced5231120bf89cbd1 (diff) | |
parent | 1e9ced5af478ba38c9e9d46140891a8f4473e02d (diff) | |
download | pleroma-eba9a62024a6acd4722745850cb7c0ea0502304f.tar.gz |
Merge branch 'feature/relay-tests' into 'develop'
relay tests
See merge request pleroma/pleroma!411
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/application.ex | 1 | ||||
-rw-r--r-- | lib/pleroma/config.ex | 15 | ||||
-rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub_controller.ex | 14 | ||||
-rw-r--r-- | lib/pleroma/web/federator/federator.ex | 5 | ||||
-rw-r--r-- | lib/pleroma/web/router.ex | 9 |
5 files changed, 36 insertions, 8 deletions
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index a6b921b45..f30fcd1e4 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -10,6 +10,7 @@ defmodule Pleroma.Application do # Define workers and child supervisors to be supervised children = [ + worker(Pleroma.Config, [Application.get_all_env(:pleroma)]), # Start the Ecto repository supervisor(Pleroma.Repo, []), # Start the endpoint when the application starts diff --git a/lib/pleroma/config.ex b/lib/pleroma/config.ex new file mode 100644 index 000000000..510d8d498 --- /dev/null +++ b/lib/pleroma/config.ex @@ -0,0 +1,15 @@ +defmodule Pleroma.Config do + use Agent + + def start_link(initial) do + Agent.start_link(fn -> initial end, name: __MODULE__) + end + + def get(path) do + Agent.get(__MODULE__, Kernel, :get_in, [path]) + end + + def put(path, value) do + Agent.update(__MODULE__, Kernel, :put_in, [path, value]) + end +end diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index a7b1c0079..531e98237 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -6,11 +6,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do alias Pleroma.Web.ActivityPub.Relay alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.Federator + alias Pleroma.Config require Logger action_fallback(:errors) + plug(:relay_active? when action in [:relay]) + + def relay_active?(conn, _) do + if Config.get([:instance, :allow_relay]) do + conn + else + conn + |> put_status(404) + |> json(%{error: "not found"}) + |> halt + end + end + def user(conn, %{"nickname" => nickname}) do with %User{} = user <- User.get_cached_by_nickname(nickname), {:ok, user} <- Pleroma.Web.WebFinger.ensure_keys_present(user) do diff --git a/lib/pleroma/web/federator/federator.ex b/lib/pleroma/web/federator/federator.ex index 078f3ec11..9ea2507a1 100644 --- a/lib/pleroma/web/federator/federator.ex +++ b/lib/pleroma/web/federator/federator.ex @@ -7,6 +7,7 @@ defmodule Pleroma.Web.Federator do alias Pleroma.Web.ActivityPub.Relay alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Config require Logger @websub Application.get_env(:pleroma, :websub) @@ -71,9 +72,9 @@ defmodule Pleroma.Web.Federator do Logger.info(fn -> "Sending #{activity.data["id"]} out via Salmon" end) Pleroma.Web.Salmon.publish(actor, activity) - if Mix.env() != :test do + if Config.get([:instance, :allow_relay]) do Logger.info(fn -> "Relaying #{activity.data["id"]} out" end) - Pleroma.Web.ActivityPub.Relay.publish(activity) + Relay.publish(activity) end end diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index b531b6188..7b7affe5e 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -5,7 +5,6 @@ defmodule Pleroma.Web.Router do @instance Application.get_env(:pleroma, :instance) @federating Keyword.get(@instance, :federating) - @allow_relay Keyword.get(@instance, :allow_relay) @public Keyword.get(@instance, :public) @registrations_open Keyword.get(@instance, :registrations_open) @@ -354,11 +353,9 @@ defmodule Pleroma.Web.Router do end if @federating do - if @allow_relay do - scope "/relay", Pleroma.Web.ActivityPub do - pipe_through(:ap_relay) - get("/", ActivityPubController, :relay) - end + scope "/relay", Pleroma.Web.ActivityPub do + pipe_through(:ap_relay) + get("/", ActivityPubController, :relay) end scope "/", Pleroma.Web.ActivityPub do |