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
This commit is contained in:
koko 2023-07-05 17:15:34 -04:00 committed by GitHub
parent 3115030c11
commit 872a161459
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 8 deletions

View file

@ -37,7 +37,7 @@
<value>LittleBigPlanet™ Online multiplayer</value>
</data>
<data name="does_not_expire" xml:space="preserve">
<value>Does not expire</value>
<value>manually dismissed</value>
</data>
<data name="profile_visibility" xml:space="preserve">
<value>Profile visibility</value>

View file

@ -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)
{
<span>
@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 @@
}
</span>
}
else
{
<span>
@Model.Translate(ModerationStrings.SuspensionExpiration, Model.Translate(GeneralStrings.Unknown))
</span>
}
</p>
<div>
<ul>
<li>@Model.Translate(ModerationStrings.LbpOnlineMultiplayer)</li>
<li>@Model.Translate(ModerationStrings.WebsiteInteractions)</li>
<li>@Model.Translate(ModerationStrings.ProfileVisibility)</li>
<li>@Model.Translate(ModerationStrings.AccountProfileManagement)</li>
</ul>
</p>
</div>
@if (Model.ModCase != null)
{
<p>
@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.")
}
</p>
}

View file

@ -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<IActionResult> 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);