From 872a161459460e4328390ad0289a7273f4c57378 Mon Sep 17 00:00:00 2001
From: koko
Date: Wed, 5 Jul 2023 17:15:34 -0400
Subject: [PATCH] Fix null case bug in BannedUserPage and properly add no
expiration text (#825)
* Fix null case bug in BannedUserPage and properly add no expiration text
* Correct maximum expiration hour to 23 (uses 24-hour)
* Improve wording for do not expire string
* Handle empty case reason string
* Move list to it's own div per HTML spec
* Move maximum expiration DateTime to the model
* Correct linq statement chaining style
* Use lambda operator instead of explicit accessor for MaximumExpiration
---
.../Moderation.resx | 2 +-
.../Pages/Login/BannedUserPage.cshtml | 26 +++++++++++++++----
.../Pages/Login/BannedUserPage.cshtml.cs | 13 ++++++++--
3 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/ProjectLighthouse.Localization/Moderation.resx b/ProjectLighthouse.Localization/Moderation.resx
index b6366ba7..95df38c6 100644
--- a/ProjectLighthouse.Localization/Moderation.resx
+++ b/ProjectLighthouse.Localization/Moderation.resx
@@ -37,7 +37,7 @@
LittleBigPlanet™ Online multiplayer
- Does not expire
+ manually dismissed
Profile visibility
diff --git a/ProjectLighthouse.Servers.Website/Pages/Login/BannedUserPage.cshtml b/ProjectLighthouse.Servers.Website/Pages/Login/BannedUserPage.cshtml
index 0607ec48..e05ed22d 100644
--- a/ProjectLighthouse.Servers.Website/Pages/Login/BannedUserPage.cshtml
+++ b/ProjectLighthouse.Servers.Website/Pages/Login/BannedUserPage.cshtml
@@ -1,6 +1,7 @@
@page "/banned"
@using LBPUnion.ProjectLighthouse.Configuration
@using LBPUnion.ProjectLighthouse.Localization.StringLists
+@using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Login
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Login.BannedUserPage
@{
@@ -20,7 +21,7 @@
@if (Model.ModCase != null)
{
- @if (Model.ModCase.ExpiresAt != null)
+ @if (Model.ModCase.ExpiresAt < BannedUserPage.MaximumExpiration)
{
@Model.Translate(ModerationStrings.SuspensionExpiration, TimeZoneInfo.ConvertTime(Model.ModCase.ExpiresAt.Value, timeZoneInfo).ToString("M/d/yyyy @ h:mm tt"))
}
@@ -30,19 +31,34 @@
}
}
-
+ else
+ {
+
+ @Model.Translate(ModerationStrings.SuspensionExpiration, Model.Translate(GeneralStrings.Unknown))
+
+ }
+
+
+
- @Model.Translate(ModerationStrings.LbpOnlineMultiplayer)
- @Model.Translate(ModerationStrings.WebsiteInteractions)
- @Model.Translate(ModerationStrings.ProfileVisibility)
- @Model.Translate(ModerationStrings.AccountProfileManagement)
-
-
+
+
@if (Model.ModCase != null)
{
- @Model.Translate(ModerationStrings.SuspensionReason, Model.ModCase.Reason)
+ @if (!string.IsNullOrWhiteSpace(Model.ModCase.Reason))
+ {
+ @Model.Translate(ModerationStrings.SuspensionReason, Model.ModCase.Reason)
+ }
+ else
+ {
+ @Model.Translate(ModerationStrings.SuspensionReason, "No reason was provided.")
+ }
}
diff --git a/ProjectLighthouse.Servers.Website/Pages/Login/BannedUserPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Login/BannedUserPage.cshtml.cs
index 4ddcbb1f..e340fc6d 100644
--- a/ProjectLighthouse.Servers.Website/Pages/Login/BannedUserPage.cshtml.cs
+++ b/ProjectLighthouse.Servers.Website/Pages/Login/BannedUserPage.cshtml.cs
@@ -17,6 +17,14 @@ public class BannedUserPage : BaseLayout
{ }
public ModerationCaseEntity? ModCase;
+
+ /*
+ * Used for deciding when to show the permanent ban string rather than the expiration time
+ *
+ * The DateTime.MaxValue expression wouldn't work in this case because the it exceeds the
+ * maximum value the case creation form lets you enter.
+ */
+ public static DateTime MaximumExpiration => new(9999, 12, 31, 23, 59, 00, DateTimeKind.Utc);
[UsedImplicitly]
public async Task OnGet()
@@ -26,10 +34,11 @@ public class BannedUserPage : BaseLayout
if (user == null) return this.Redirect("~/login");
if (!user.IsBanned) return this.Redirect("~/");
- ModerationCaseEntity? modCase = await this.Database.Cases.OrderByDescending(c => c.CreatedAt)
+ ModerationCaseEntity? modCase = await this.Database.Cases
+ .OrderByDescending(c => c.CreatedAt)
.Where(c => c.AffectedId == user.UserId)
.Where(c => c.Type == CaseType.UserBan)
- .Where(c => c.DismissedAt != null)
+ .Where(c => c.ExpiresAt != null)
.FirstOrDefaultAsync();
if (modCase == null) Logger.Warn($"User {user.UserId} is banned but has no mod case?", LogArea.Login);