Fix preloads

This commit is contained in:
Liam 2024-08-25 21:10:34 -04:00
parent d78201d05f
commit 5da5d086c8
2 changed files with 18 additions and 2 deletions

View file

@ -13,6 +13,7 @@ defmodule PhilomenaWeb.Admin.User.EraseController do
persisted: true,
preload: [:roles]
plug :prevent_deleting_nonexistent_users
plug :prevent_deleting_privileged_users
plug :prevent_deleting_verified_users
@ -35,6 +36,17 @@ defmodule PhilomenaWeb.Admin.User.EraseController do
end
end
defp prevent_deleting_nonexistent_users(conn, _opts) do
if is_nil(conn.assigns.user) do
conn
|> put_flash(:error, "Couldn't find that username. Was it already erased?")
|> redirect(to: ~p"/admin/users")
|> Plug.Conn.halt()
else
conn
end
end
defp prevent_deleting_privileged_users(conn, _opts) do
if conn.assigns.user.role != "user" do
conn

View file

@ -125,8 +125,12 @@ defmodule PhilomenaWeb.ProfileController do
preload(Image, [:sources, tags: :aliases]),
preload(Image, [:sources, tags: :aliases]),
preload(Image, [:sources, tags: :aliases]),
preload(Comment, user: [awards: :badge], image: [:sources, tags: :aliases]),
preload(Post, user: [awards: :badge], topic: :forum)
preload(Comment, [
:deleted_by,
user: [awards: :badge],
image: [:sources, tags: :aliases]
]),
preload(Post, [:deleted_by, user: [awards: :badge], topic: :forum])
]
)