show forum list

This commit is contained in:
byte[] 2019-11-27 21:57:25 -05:00
parent d91346c9b1
commit a22b397fc4
3 changed files with 29 additions and 0 deletions

View file

@ -0,0 +1,24 @@
defmodule PhilomenaWeb.ForumListPlug do
alias Plug.Conn
alias Philomena.Forums.Forum
alias Philomena.Repo
alias Canada.Can
import Ecto.Query
def init(opts), do: opts
def call(conn, _opts) do
forums = lookup_visible_forums(conn.assigns.current_user)
conn
|> Conn.assign(:forums, forums)
end
# fixme: add caching!
defp lookup_visible_forums(user) do
Forum
|> Repo.all()
|> Enum.filter(&Can.can?(user, :show, &1))
end
end

View file

@ -16,6 +16,7 @@ defmodule PhilomenaWeb.Router do
plug PhilomenaWeb.CurrentBanPlug
plug PhilomenaWeb.NotificationCountPlug
plug PhilomenaWeb.SiteNoticePlug
plug PhilomenaWeb.ForumListPlug
plug PhilomenaWeb.FilterSelectPlug
end

View file

@ -15,6 +15,10 @@
span data-click-preventdefault="true"
i.fa.fa-caret-down<
.dropdown__content
= for forum <- @conn.assigns.forums do
a.header__link href=Routes.forum_path(@conn, :show, forum)
= forum.name
a.header__link href='/posts'
i.fa.fa-fw.fa-search>
| Post Search