mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
add filter override param
This commit is contained in:
parent
12fb45170c
commit
a9c276ae2f
2 changed files with 21 additions and 0 deletions
20
lib/philomena_web/plugs/filter_id_plug.ex
Normal file
20
lib/philomena_web/plugs/filter_id_plug.ex
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
defmodule PhilomenaWeb.FilterIdPlug do
|
||||||
|
alias Philomena.Filters.Filter
|
||||||
|
alias Philomena.Repo
|
||||||
|
|
||||||
|
# No options
|
||||||
|
def init([]), do: false
|
||||||
|
|
||||||
|
def call(conn, _opts) do
|
||||||
|
filter = load_filter(conn.params)
|
||||||
|
user = conn.assigns.current_user
|
||||||
|
|
||||||
|
case Canada.Can.can?(user, :show, filter) do
|
||||||
|
true -> Plug.Conn.assign(conn, :current_filter, filter)
|
||||||
|
false -> conn
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp load_filter(%{"filter_id" => filter_id}), do: Repo.get(Filter, filter_id)
|
||||||
|
defp load_filter(_params), do: nil
|
||||||
|
end
|
|
@ -25,6 +25,7 @@ defmodule PhilomenaWeb.Router do
|
||||||
plug PhilomenaWeb.ApiTokenPlug
|
plug PhilomenaWeb.ApiTokenPlug
|
||||||
plug PhilomenaWeb.EnsureUserEnabledPlug
|
plug PhilomenaWeb.EnsureUserEnabledPlug
|
||||||
plug PhilomenaWeb.CurrentFilterPlug
|
plug PhilomenaWeb.CurrentFilterPlug
|
||||||
|
plug PhilomenaWeb.FilterIdPlug
|
||||||
plug PhilomenaWeb.ImageFilterPlug
|
plug PhilomenaWeb.ImageFilterPlug
|
||||||
plug PhilomenaWeb.PaginationPlug
|
plug PhilomenaWeb.PaginationPlug
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue