diff options
author | lain <lain@soykaf.club> | 2020-05-06 09:14:05 +0000 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-05-06 09:14:05 +0000 |
commit | 07e7c80bc9e919cd92ca9dda1e21384142e5bd77 (patch) | |
tree | e921b5664c8c2bd53057fda10318cb57aad17af1 /lib/pleroma/web/web.ex | |
parent | a716543267469642b326dc5061528d8307ea6633 (diff) | |
parent | 2c4844237f294d27f58737f9694f77b1cfcb10e7 (diff) | |
download | pleroma-07e7c80bc9e919cd92ca9dda1e21384142e5bd77.tar.gz |
Merge branch 'plug-if-unless-func-options-refactoring' into 'develop'
Refactoring of :if_func / :unless_func plug options
See merge request pleroma/pleroma!2446
Diffstat (limited to 'lib/pleroma/web/web.ex')
-rw-r--r-- | lib/pleroma/web/web.ex | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/pleroma/web/web.ex b/lib/pleroma/web/web.ex index 08e42a7e5..4f9281851 100644 --- a/lib/pleroma/web/web.ex +++ b/lib/pleroma/web/web.ex @@ -200,11 +200,17 @@ defmodule Pleroma.Web do @impl Plug @doc """ - If marked as skipped, returns `conn`, otherwise calls `perform/2`. + Before-plug hook that + * ensures the plug is not skipped + * processes `:if_func` / `:unless_func` functional pre-run conditions + * adds plug to the list of called plugs and calls `perform/2` if checks are passed + Note: multiple invocations of the same plug (with different or same options) are allowed. """ def call(%Plug.Conn{} = conn, options) do - if PlugHelper.plug_skipped?(conn, __MODULE__) do + if PlugHelper.plug_skipped?(conn, __MODULE__) || + (options[:if_func] && !options[:if_func].(conn)) || + (options[:unless_func] && options[:unless_func].(conn)) do conn else conn = |