Просмотр исходного кода

Refactor skipped plugs into Pleroma.Web functions

Speeds up recompilation by reducing compile cycles
elixir-1.11-ci
Alex Gleason 3 лет назад
Родитель
Сommit
45b7325b9e
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 7211D1F99744FBB7
13 измененных файлов: 22 добавлений и 57 удалений
  1. +8
    -0
      lib/pleroma/web.ex
  2. +2
    -6
      lib/pleroma/web/masto_fe_controller.ex
  3. +2
    -3
      lib/pleroma/web/mastodon_api/controllers/account_controller.ex
  4. +1
    -7
      lib/pleroma/web/mastodon_api/controllers/app_controller.ex
  5. +1
    -5
      lib/pleroma/web/mastodon_api/controllers/custom_emoji_controller.ex
  6. +1
    -5
      lib/pleroma/web/mastodon_api/controllers/instance_controller.ex
  7. +1
    -5
      lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex
  8. +1
    -4
      lib/pleroma/web/mastodon_api/controllers/status_controller.ex
  9. +1
    -2
      lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex
  10. +1
    -4
      lib/pleroma/web/o_auth/o_auth_controller.ex
  11. +1
    -5
      lib/pleroma/web/pleroma_api/controllers/account_controller.ex
  12. +1
    -5
      lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex
  13. +1
    -6
      lib/pleroma/web/twitter_api/controller.ex

+ 8
- 0
lib/pleroma/web.ex Просмотреть файл

@@ -62,6 +62,14 @@ defmodule Pleroma.Web do
) )
end end


defp skip_auth(conn, _) do
skip_plug(conn, [OAuthScopesPlug, EnsurePublicOrAuthenticatedPlug])
end

defp skip_public_check(conn, _) do
skip_plug(conn, EnsurePublicOrAuthenticatedPlug)
end

# Executed just before actual controller action, invokes before-action hooks (callbacks) # Executed just before actual controller action, invokes before-action hooks (callbacks)
defp action(conn, params) do defp action(conn, params) do
with %{halted: false} = conn <- with %{halted: false} = conn <-


+ 2
- 6
lib/pleroma/web/masto_fe_controller.ex Просмотреть файл

@@ -8,13 +8,12 @@ defmodule Pleroma.Web.MastoFEController do
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.MastodonAPI.AuthController alias Pleroma.Web.MastodonAPI.AuthController
alias Pleroma.Web.OAuth.Token alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug


plug(OAuthScopesPlug, %{scopes: ["write:accounts"]} when action == :put_settings) plug(OAuthScopesPlug, %{scopes: ["write:accounts"]} when action == :put_settings)


# Note: :index action handles attempt of unauthenticated access to private instance with redirect # Note: :index action handles attempt of unauthenticated access to private instance with redirect
plug(:skip_plug, EnsurePublicOrAuthenticatedPlug when action == :index)
plug(:skip_public_check when action == :index)


plug( plug(
OAuthScopesPlug, OAuthScopesPlug,
@@ -22,10 +21,7 @@ defmodule Pleroma.Web.MastoFEController do
when action == :index when action == :index
) )


plug(
:skip_plug,
[OAuthScopesPlug, EnsurePublicOrAuthenticatedPlug] when action == :manifest
)
plug(:skip_auth when action == :manifest)


@doc "GET /web/*path" @doc "GET /web/*path"
def index(conn, _params) do def index(conn, _params) do


+ 2
- 3
lib/pleroma/web/mastodon_api/controllers/account_controller.ex Просмотреть файл

@@ -24,7 +24,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
alias Pleroma.Web.MastodonAPI.MastodonAPIController alias Pleroma.Web.MastodonAPI.MastodonAPIController
alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.Web.OAuth.OAuthController alias Pleroma.Web.OAuth.OAuthController
alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug
alias Pleroma.Web.Plugs.RateLimiter alias Pleroma.Web.Plugs.RateLimiter
alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.TwitterAPI
@@ -32,9 +31,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do


plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.ApiSpec.CastAndValidate)


plug(:skip_plug, [OAuthScopesPlug, EnsurePublicOrAuthenticatedPlug] when action == :create)
plug(:skip_auth when action == :create)


plug(:skip_plug, EnsurePublicOrAuthenticatedPlug when action in [:show, :statuses])
plug(:skip_public_check when action in [:show, :statuses])


plug( plug(
OAuthScopesPlug, OAuthScopesPlug,


+ 1
- 7
lib/pleroma/web/mastodon_api/controllers/app_controller.ex Просмотреть файл

@@ -14,16 +14,10 @@ defmodule Pleroma.Web.MastodonAPI.AppController do
alias Pleroma.Web.OAuth.App alias Pleroma.Web.OAuth.App
alias Pleroma.Web.OAuth.Scopes alias Pleroma.Web.OAuth.Scopes
alias Pleroma.Web.OAuth.Token alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
alias Pleroma.Web.Plugs.OAuthScopesPlug


action_fallback(Pleroma.Web.MastodonAPI.FallbackController) action_fallback(Pleroma.Web.MastodonAPI.FallbackController)


plug(
:skip_plug,
[OAuthScopesPlug, EnsurePublicOrAuthenticatedPlug]
when action in [:create, :verify_credentials]
)
plug(:skip_auth when action in [:create, :verify_credentials])


plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.ApiSpec.CastAndValidate)




+ 1
- 5
lib/pleroma/web/mastodon_api/controllers/custom_emoji_controller.ex Просмотреть файл

@@ -7,11 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.CustomEmojiController do


plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.ApiSpec.CastAndValidate)


plug(
:skip_plug,
[Pleroma.Web.Plugs.OAuthScopesPlug, Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug]
when action == :index
)
plug(:skip_auth when action == :index)


defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.CustomEmojiOperation defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.CustomEmojiOperation




+ 1
- 5
lib/pleroma/web/mastodon_api/controllers/instance_controller.ex Просмотреть файл

@@ -7,11 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceController do


plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.ApiSpec.CastAndValidate)


plug(
:skip_plug,
[Pleroma.Web.Plugs.OAuthScopesPlug, Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug]
when action in [:show, :peers]
)
plug(:skip_auth when action in [:show, :peers])


defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.InstanceOperation defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.InstanceOperation




+ 1
- 5
lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex Просмотреть файл

@@ -15,11 +15,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do


require Logger require Logger


plug(
:skip_plug,
[Pleroma.Web.Plugs.OAuthScopesPlug, Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug]
when action in [:empty_array, :empty_object]
)
plug(:skip_auth when action in [:empty_array, :empty_object])


action_fallback(Pleroma.Web.MastodonAPI.FallbackController) action_fallback(Pleroma.Web.MastodonAPI.FallbackController)




+ 1
- 4
lib/pleroma/web/mastodon_api/controllers/status_controller.ex Просмотреть файл

@@ -27,10 +27,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do


plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.ApiSpec.CastAndValidate)


plug(
:skip_plug,
Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug when action in [:index, :show]
)
plug(:skip_public_check when action in [:index, :show])


@unauthenticated_access %{fallback: :proceed_unauthenticated, scopes: []} @unauthenticated_access %{fallback: :proceed_unauthenticated, scopes: []}




+ 1
- 2
lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex Просмотреть файл

@@ -12,12 +12,11 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
alias Pleroma.Pagination alias Pleroma.Pagination
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug
alias Pleroma.Web.Plugs.RateLimiter alias Pleroma.Web.Plugs.RateLimiter


plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.ApiSpec.CastAndValidate)
plug(:skip_plug, EnsurePublicOrAuthenticatedPlug when action in [:public, :hashtag])
plug(:skip_public_check when action in [:public, :hashtag])


# TODO: Replace with a macro when there is a Phoenix release with the following commit in it: # TODO: Replace with a macro when there is a Phoenix release with the following commit in it:
# https://github.com/phoenixframework/phoenix/commit/2e8c63c01fec4dde5467dbbbf9705ff9e780735e # https://github.com/phoenixframework/phoenix/commit/2e8c63c01fec4dde5467dbbbf9705ff9e780735e


+ 1
- 4
lib/pleroma/web/o_auth/o_auth_controller.ex Просмотреть файл

@@ -32,10 +32,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
plug(:fetch_session) plug(:fetch_session)
plug(:fetch_flash) plug(:fetch_flash)


plug(:skip_plug, [
Pleroma.Web.Plugs.OAuthScopesPlug,
Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
])
plug(:skip_auth)


plug(RateLimiter, [name: :authentication] when action == :create_authorization) plug(RateLimiter, [name: :authentication] when action == :create_authorization)




+ 1
- 5
lib/pleroma/web/pleroma_api/controllers/account_controller.ex Просмотреть файл

@@ -11,7 +11,6 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug
alias Pleroma.Web.Plugs.RateLimiter alias Pleroma.Web.Plugs.RateLimiter


@@ -29,10 +28,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do


plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.ApiSpec.CastAndValidate)


plug(
:skip_plug,
[OAuthScopesPlug, EnsurePublicOrAuthenticatedPlug] when action == :confirmation_resend
)
plug(:skip_auth when action == :confirmation_resend)


plug( plug(
OAuthScopesPlug, OAuthScopesPlug,


+ 1
- 5
lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex Просмотреть файл

@@ -22,11 +22,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackController do
] ]
) )


@skip_plugs [
Pleroma.Web.Plugs.OAuthScopesPlug,
Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
]
plug(:skip_plug, @skip_plugs when action in [:index, :archive, :show])
plug(:skip_auth when action in [:index, :archive, :show])


defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaEmojiPackOperation defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaEmojiPackOperation




+ 1
- 6
lib/pleroma/web/twitter_api/controller.ex Просмотреть файл

@@ -7,17 +7,12 @@ defmodule Pleroma.Web.TwitterAPI.Controller do


alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.OAuth.Token alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug
alias Pleroma.Web.TwitterAPI.TokenView alias Pleroma.Web.TwitterAPI.TokenView


require Logger require Logger


plug(
:skip_plug,
[OAuthScopesPlug, EnsurePublicOrAuthenticatedPlug] when action == :confirm_email
)

plug(:skip_auth when action == :confirm_email)
plug(:skip_plug, OAuthScopesPlug when action in [:oauth_tokens, :revoke_token]) plug(:skip_plug, OAuthScopesPlug when action in [:oauth_tokens, :revoke_token])


action_fallback(:errors) action_fallback(:errors)


Загрузка…
Отмена
Сохранить