mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +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,
|
persisted: true,
|
||||||
preload: [:roles]
|
preload: [:roles]
|
||||||
|
|
||||||
|
plug :prevent_deleting_nonexistent_users
|
||||||
plug :prevent_deleting_privileged_users
|
plug :prevent_deleting_privileged_users
|
||||||
plug :prevent_deleting_verified_users
|
plug :prevent_deleting_verified_users
|
||||||
|
|
||||||
|
@ -35,6 +36,17 @@ defmodule PhilomenaWeb.Admin.User.EraseController do
|
||||||
end
|
end
|
||||||
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
|
defp prevent_deleting_privileged_users(conn, _opts) do
|
||||||
if conn.assigns.user.role != "user" do
|
if conn.assigns.user.role != "user" do
|
||||||
conn
|
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(Image, [:sources, tags: :aliases]),
|
||||||
preload(Image, [:sources, tags: :aliases]),
|
preload(Image, [:sources, tags: :aliases]),
|
||||||
preload(Comment, user: [awards: :badge], image: [:sources, tags: :aliases]),
|
preload(Comment, [
|
||||||
preload(Post, user: [awards: :badge], topic: :forum)
|
:deleted_by,
|
||||||
|
user: [awards: :badge],
|
||||||
|
image: [:sources, tags: :aliases]
|
||||||
|
]),
|
||||||
|
preload(Post, [:deleted_by, user: [awards: :badge], topic: :forum])
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue