[#1427] Fixed :admin option handling in OAuthScopesPlug, added tests.

This commit is contained in:
Ivan Tashkinov 2019-12-11 11:42:02 +03:00
commit 3920244be5
3 changed files with 56 additions and 10 deletions

View file

@ -17,13 +17,7 @@ defmodule Pleroma.Plugs.OAuthScopesPlug do
op = options[:op] || :|
token = assigns[:token]
scopes =
if options[:admin] do
Config.oauth_admin_scopes(scopes)
else
scopes
end
scopes = transform_scopes(scopes, options)
matched_scopes = token && filter_descendants(scopes, token.scopes)
cond do
@ -69,6 +63,15 @@ defmodule Pleroma.Plugs.OAuthScopesPlug do
)
end
@doc "Transforms scopes by applying supported options (e.g. :admin)"
def transform_scopes(scopes, options) do
if options[:admin] do
Config.oauth_admin_scopes(scopes)
else
scopes
end
end
defp maybe_perform_instance_privacy_check(%Plug.Conn{} = conn, options) do
if options[:skip_instance_privacy_check] do
conn