From 027173b9c7856ce7a7e16a13c5ce6c41033ffe3b Mon Sep 17 00:00:00 2001 From: koko Date: Mon, 7 Aug 2023 00:45:46 -0400 Subject: [PATCH] Redesign case creation page (#854) * Redesign case creation page * Fix user id placeholder text * Handle empty moderation history * Mod history dropdown nitpick * Fix styling issue with dropdown ui fluid dropdown inherits from ui form * Potentially fix NRE * Un-require reason/mod notes * Display username in moderation history view * Order mod history by creation time descending * Nitpick no moderation history string * Handle AffectedUser null check within controller * Fix styling issues * Move moderation history segment above create case button segment * Link back to affected user * Move expiration field in with the other entries * Grammatical consistency nitpick in history dropdown * Handle empty case reasons in mod history * This is the last nitpick, I swear! * I lied. Variable naming consistency :trollface: * Consolidate setPermanent function into button onclick * Use HTML details and Fomantic list instead of dropdown * Fix padding issue with details list * Format history and user/id nicely * Styling fixes and nitpicks of list items/links * Apply suggestions from code review * Clarification with code review suggestion --- .../Extensions/FormattingExtensions.cs | 16 ++++ .../Pages/Moderation/NewCasePage.cshtml | 83 +++++++++++++++---- .../Pages/Moderation/NewCasePage.cshtml.cs | 25 ++++-- 3 files changed, 103 insertions(+), 21 deletions(-) diff --git a/ProjectLighthouse.Servers.Website/Extensions/FormattingExtensions.cs b/ProjectLighthouse.Servers.Website/Extensions/FormattingExtensions.cs index 42ba1bea..d33e2eae 100644 --- a/ProjectLighthouse.Servers.Website/Extensions/FormattingExtensions.cs +++ b/ProjectLighthouse.Servers.Website/Extensions/FormattingExtensions.cs @@ -1,4 +1,5 @@ using LBPUnion.ProjectLighthouse.Types.Entities.Level; +using LBPUnion.ProjectLighthouse.Types.Moderation.Cases; using LBPUnion.ProjectLighthouse.Types.Users; namespace LBPUnion.ProjectLighthouse.Servers.Website.Extensions; @@ -7,6 +8,21 @@ public static class FormattingExtensions { public static string GetLevelLockIcon(this SlotEntity slot) => slot.InitiallyLocked ? "ui icon lock" : ""; + public static string GetCaseTypeIcon(this CaseType caseType) + { + return caseType switch + { + CaseType.UserBan => "ui icon ban", + CaseType.UserRestriction => "ui icon user alternate slash", + CaseType.UserSilence => "ui icon volume off", + CaseType.UserDisableComments => "ui icon comment slash", + CaseType.LevelHide => "ui icon eye slash", + CaseType.LevelLock => "ui icon lock", + CaseType.LevelDisableComments => "ui icon comment slash", + _ => "ui icon question", + }; + } + public static string ToHtmlColor(this PermissionLevel permissionLevel) { return permissionLevel switch diff --git a/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml b/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml index 4e6214fe..cfcdb438 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml @@ -1,13 +1,18 @@ @page "/moderation/newCase" @using LBPUnion.ProjectLighthouse.Localization.StringLists +@using LBPUnion.ProjectLighthouse.Servers.Website.Extensions +@using LBPUnion.ProjectLighthouse.Types.Entities.Moderation @model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Moderation.NewCasePage @{ Layout = "Layouts/BaseLayout"; - Model.Title = $"New {Model.Type.ToString()} Case"; + Model.Title = "New Moderation Case"; + + string timeZone = (string?)ViewData["TimeZone"] ?? TimeZoneInfo.Local.Id; + TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone); } -
+ @Html.AntiForgeryToken() @if (!string.IsNullOrWhiteSpace(Model.Error)) @@ -18,20 +23,68 @@ -
- - -


+
+
+ Case Type: @Model.Type.ToString() +
+
+ Affected User: @Model.AffectedUser!.Username (id: @Model.AffectedId) +
+
-
- - -


+
+
+ + +
+
+ + +
+
+ + +
+ +
-
- - -


+
+
+ Moderation history for user @Model.AffectedUser!.Username +
+ @if (Model.AffectedHistory.Count != 0) + { + @foreach (ModerationCaseEntity moderationCase in Model.AffectedHistory) + { +
+ +
+ @moderationCase.Type.ToString() by @moderationCase.CreatorUsername + on @TimeZoneInfo.ConvertTime(moderationCase.CreatedAt, timeZoneInfo).ToString("M/d/yyyy @ h:mm tt") + with reason @(!string.IsNullOrWhiteSpace(moderationCase.Reason) ? moderationCase.Reason : "No reason provided") +
+
+ } + } + else + { +
+ +
+ No moderation history found for user @Model.AffectedUser!.Username +
+
+ } +
+
+
-
+
+
+ Remember to dismiss your case after expiration otherwise it will remain in effect! +
+ +
\ No newline at end of file diff --git a/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml.cs index a44e032d..19f3387c 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml.cs @@ -12,14 +12,17 @@ namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Moderation; public class NewCasePage : BaseLayout { public NewCasePage(DatabaseContext database) : base(database) - {} + { } public CaseType Type { get; set; } + public int AffectedId { get; set; } + public UserEntity? AffectedUser { get; set; } + public List AffectedHistory { get; set; } = new(); public string? Error { get; private set; } - public IActionResult OnGet([FromQuery] CaseType? type, [FromQuery] int? affectedId) + public async Task OnGet([FromQuery] CaseType? type, [FromQuery] int? affectedId) { UserEntity? user = this.Database.UserFromWebRequest(this.Request); if (user == null || !user.IsModerator) return this.Redirect("/login"); @@ -28,8 +31,16 @@ public class NewCasePage : BaseLayout if (affectedId == null) return this.BadRequest(); this.Type = type.Value; + this.AffectedId = affectedId.Value; + this.AffectedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == this.AffectedId); + if (this.AffectedUser == null) return this.BadRequest(); + + this.AffectedHistory = await this.Database.Cases.Where(c => c.AffectedId == this.AffectedId) + .OrderByDescending(c => c.CreatedAt) + .ToListAsync(); + return this.Page(); } @@ -43,14 +54,16 @@ public class NewCasePage : BaseLayout reason ??= string.Empty; modNotes ??= string.Empty; - + // if id is invalid then return bad request if (!await type.Value.IsIdValid((int)affectedId, this.Database)) return this.BadRequest(); - UserEntity? affectedUserEntity = + UserEntity? affectedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == affectedId.Value); - if (affectedUserEntity?.IsModerator ?? false) + if (affectedUser == null) return this.NotFound(); + + if (affectedUser.IsModerator) { this.Error = this.Translate(ErrorStrings.ActionNoPermission); return this.Page(); @@ -70,7 +83,7 @@ public class NewCasePage : BaseLayout this.Database.Cases.Add(@case); await this.Database.SaveChangesAsync(); - + return this.Redirect("/moderation/cases/0"); } } \ No newline at end of file