X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fconfig.ex;h=2e15a37193ada875eeb73746d30b2bc37e464a68;hb=32d263cb905dd7fffd43a4955295af0b2b378537;hp=98099ca58a906955dd06191e564473a433948fad;hpb=6f60ac9f41d9511afa71986f000a2fc6c637b0c5;p=akkoma diff --git a/lib/pleroma/config.ex b/lib/pleroma/config.ex index 98099ca58..2e15a3719 100644 --- a/lib/pleroma/config.ex +++ b/lib/pleroma/config.ex @@ -1,16 +1,20 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors +# Copyright © 2017-2021 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Config do + @behaviour Pleroma.Config.Getting defmodule Error do defexception [:message] end + @impl true def get(key), do: get(key, nil) + @impl true def get([key], default), do: get(key, default) + @impl true def get([_ | _] = path, default) do case fetch(path) do {:ok, value} -> value @@ -18,6 +22,7 @@ defmodule Pleroma.Config do end end + @impl true def get(key, default) do Application.get_env(:pleroma, key, default) end @@ -32,6 +37,8 @@ defmodule Pleroma.Config do end end + def fetch(key) when is_atom(key), do: fetch([key]) + def fetch([root_key | keys]) do Enum.reduce_while(keys, Application.fetch_env(:pleroma, root_key), fn key, {:ok, config} when is_map(config) or is_list(config) -> @@ -79,19 +86,17 @@ defmodule Pleroma.Config do Application.delete_env(:pleroma, key) end - def oauth_consumer_strategies, do: get([:auth, :oauth_consumer_strategies], []) + def restrict_unauthenticated_access?(resource, kind) do + setting = get([:restrict_unauthenticated, resource, kind]) - def oauth_consumer_enabled?, do: oauth_consumer_strategies() != [] + if setting in [nil, :if_instance_is_private] do + !get!([:instance, :public]) + else + setting + end + end - def enforce_oauth_admin_scope_usage?, do: !!get([:auth, :enforce_oauth_admin_scope_usage]) + def oauth_consumer_strategies, do: get([:auth, :oauth_consumer_strategies], []) - def oauth_admin_scopes(scopes) when is_list(scopes) do - Enum.flat_map( - scopes, - fn scope -> - ["admin:#{scope}"] ++ - if enforce_oauth_admin_scope_usage?(), do: [], else: [scope] - end - ) - end + def oauth_consumer_enabled?, do: oauth_consumer_strategies() != [] end