From 5da5d086c8a8273e5ad380a390da95a6f473eda0 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 25 Aug 2024 21:10:34 -0400 Subject: [PATCH] Fix preloads --- .../controllers/admin/user/erase_controller.ex | 12 ++++++++++++ lib/philomena_web/controllers/profile_controller.ex | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/philomena_web/controllers/admin/user/erase_controller.ex b/lib/philomena_web/controllers/admin/user/erase_controller.ex index b481068e..f0a926df 100644 --- a/lib/philomena_web/controllers/admin/user/erase_controller.ex +++ b/lib/philomena_web/controllers/admin/user/erase_controller.ex @@ -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 diff --git a/lib/philomena_web/controllers/profile_controller.ex b/lib/philomena_web/controllers/profile_controller.ex index af5b0ac3..d3e375f4 100644 --- a/lib/philomena_web/controllers/profile_controller.ex +++ b/lib/philomena_web/controllers/profile_controller.ex @@ -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]) ] )