mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 05:37:59 +01:00
Fix preloads
This commit is contained in:
parent
d78201d05f
commit
5da5d086c8
2 changed files with 18 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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])
|
||||
]
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue