diff --git a/ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationCaseController.cs b/ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationCaseController.cs index 00464a47..23673697 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationCaseController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationCaseController.cs @@ -27,26 +27,11 @@ public class ModerationCaseController : ControllerBase @case.DismissedAt = DateTime.Now; @case.DismisserId = user.UserId; + + @case.Processed = false; await this.database.SaveChangesAsync(); return this.Ok(); } - - [HttpGet("undoDismiss")] - public async Task UndoDismissCase([FromRoute] int id) - { - User? user = this.database.UserFromWebRequest(this.Request); - if (user == null || !user.IsModerator) return this.StatusCode(403, ""); - - ModerationCase? @case = await this.database.Cases.FirstOrDefaultAsync(c => c.CaseId == id); - if (@case == null) return this.NotFound(); - - @case.DismissedAt = null; - @case.DismisserId = null; - - await this.database.SaveChangesAsync(); - - return this.Ok(); - } } \ No newline at end of file diff --git a/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml.cs index 6501de1b..2d130923 100644 --- a/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml.cs @@ -35,7 +35,7 @@ public class CasePage : BaseLayout .Include(c => c.Dismisser) .OrderByDescending(c => c.CaseId) .ToListAsync(); - this.CaseCount = await this.Database.Cases.CountAsync(c => c.Description.Contains(this.SearchValue)); + this.CaseCount = await this.Database.Cases.CountAsync(c => c.Reason.Contains(this.SearchValue)); this.PageNumber = pageNumber; this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.CaseCount / ServerStatics.PageSize)); diff --git a/ProjectLighthouse.Servers.Website/Pages/Debug/NewCasePage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Debug/NewCasePage.cshtml.cs index 503121d0..f9ea1bf8 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Debug/NewCasePage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Debug/NewCasePage.cshtml.cs @@ -23,7 +23,7 @@ public class NewCasePage : BaseLayout ModerationCase @case = new() { Type = (CaseType)type, - Description = description, + Reason = description, ExpiresAt = expires, CreatedAt = DateTime.Now, CreatorId = 1, diff --git a/ProjectLighthouse.Servers.Website/Pages/Partials/ModerationCasePartial.cshtml b/ProjectLighthouse.Servers.Website/Pages/Partials/ModerationCasePartial.cshtml index 4d4fb437..b028ed8a 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Partials/ModerationCasePartial.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/Partials/ModerationCasePartial.cshtml @@ -49,14 +49,24 @@

Affected user: @user.Username

} - @if (!string.IsNullOrWhiteSpace(Model.Description)) +

Reason

+ @if (!string.IsNullOrWhiteSpace(Model.Reason)) { -

Description

-
@Model.Description
+
@Model.Reason
} else { - No description was provided. +
No reason was provided.
+ } + +

Moderator Notes

+ @if (!string.IsNullOrWhiteSpace(Model.ModeratorNotes)) + { +
@Model.ModeratorNotes
+ } + else + { +
No notes were provided.
} @if (!Model.Dismissed) @@ -66,11 +76,4 @@ Dismiss } - else - { - - - Undo dismission @* TODO: fix english here lol wtf is this *@ - - } \ No newline at end of file diff --git a/ProjectLighthouse/Administration/CaseType.cs b/ProjectLighthouse/Administration/CaseType.cs index 4f1494da..31e608fd 100644 --- a/ProjectLighthouse/Administration/CaseType.cs +++ b/ProjectLighthouse/Administration/CaseType.cs @@ -13,7 +13,6 @@ public enum CaseType LevelLock = 4, LevelCommentsDisabled = 5, - LevelDetailsEdited = 6, } public static class CaseTypeExtensions @@ -36,7 +35,6 @@ public static class CaseTypeExtensions { CaseType.LevelLock => true, CaseType.LevelCommentsDisabled => true, - CaseType.LevelDetailsEdited => true, _ => false, }; } diff --git a/ProjectLighthouse/Administration/Maintenance/RepeatingTasks/PerformCaseActionsTask.cs b/ProjectLighthouse/Administration/Maintenance/RepeatingTasks/PerformCaseActionsTask.cs new file mode 100644 index 00000000..8ac529cf --- /dev/null +++ b/ProjectLighthouse/Administration/Maintenance/RepeatingTasks/PerformCaseActionsTask.cs @@ -0,0 +1,80 @@ +#nullable enable +using System; +using System.Linq; +using System.Threading.Tasks; +using LBPUnion.ProjectLighthouse.Levels; +using LBPUnion.ProjectLighthouse.PlayerData.Profiles; +using Microsoft.EntityFrameworkCore; + +namespace LBPUnion.ProjectLighthouse.Administration.Maintenance.RepeatingTasks; + +public class PerformCaseActionsTask : IRepeatingTask +{ + public string Name => "Perform actions on moderation cases"; + public TimeSpan RepeatInterval => TimeSpan.FromSeconds(10); + public DateTime LastRan { get; set; } + public async Task Run(Database database) + { + foreach (ModerationCase @case in await database.Cases.Where(c => !c.Processed).ToListAsync()) + { + User? user = null; + Slot? slot = null; + + if (@case.Type.AffectsUser()) + { + user = await @case.GetUserAsync(database); + } + else if(@case.Type.AffectsLevel()) + { + slot = await @case.GetSlotAsync(database); + } + + if (@case.Expired || @case.Dismissed) + { + switch (@case.Type) + { + case CaseType.UserBan: + case CaseType.UserRestriction: + case CaseType.UserSilence: + { + user!.PermissionLevel = PermissionLevel.Default; + break; + }; + case CaseType.UserCommentsDisabled: break; + case CaseType.LevelLock: break; + case CaseType.LevelCommentsDisabled: break; + default: throw new ArgumentOutOfRangeException(); + } + } + else + { + switch (@case.Type) + { + case CaseType.UserSilence: + { + user!.PermissionLevel = PermissionLevel.Silenced; + break; + } + case CaseType.UserRestriction: + { + user!.PermissionLevel = PermissionLevel.Restricted; + break; + } + case CaseType.UserBan: + { + user!.PermissionLevel = PermissionLevel.Banned; + break; + } + case CaseType.UserCommentsDisabled: break; + case CaseType.LevelLock: break; + case CaseType.LevelCommentsDisabled: break; + default: throw new ArgumentOutOfRangeException(); + } + } + + @case.Processed = true; + } + + await database.SaveChangesAsync(); + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Administration/ModerationCase.cs b/ProjectLighthouse/Administration/ModerationCase.cs index 2f82b631..ff6981fe 100644 --- a/ProjectLighthouse/Administration/ModerationCase.cs +++ b/ProjectLighthouse/Administration/ModerationCase.cs @@ -16,8 +16,12 @@ public class ModerationCase public int CaseId { get; set; } public CaseType Type { get; set; } - - public string Description { get; set; } + + public string Reason { get; set; } = ""; + + public string ModeratorNotes { get; set; } = ""; + + public bool Processed { get; set; } = false; public DateTime CreatedAt { get; set; } @@ -61,7 +65,7 @@ public class ModerationCase => new() { Type = CaseType.UserBan, - Description = $"Banned for reason '{reason}'\nModeration notes: {modNotes}", + Reason = $"Banned for reason '{reason}'\nModeration notes: {modNotes}", CreatorId = caseCreator, CreatedAt = DateTime.Now, ExpiresAt = caseExpires, diff --git a/ProjectLighthouse/Administration/RepeatingTaskHandler.cs b/ProjectLighthouse/Administration/RepeatingTaskHandler.cs index 9d194310..af1388df 100644 --- a/ProjectLighthouse/Administration/RepeatingTaskHandler.cs +++ b/ProjectLighthouse/Administration/RepeatingTaskHandler.cs @@ -53,9 +53,9 @@ public static class RepeatingTaskHandler taskQueue.Enqueue(task); Thread.Sleep(500); // Doesn't need to be that precise. } - catch + catch(Exception e) { - // ignored + Logger.Warn($"Error occured while processing repeating tasks: \n{e}", LogArea.Maintenace); } } } diff --git a/ProjectLighthouse/Migrations/20220805234507_AddModNotesToCase.cs b/ProjectLighthouse/Migrations/20220805234507_AddModNotesToCase.cs new file mode 100644 index 00000000..ed986089 --- /dev/null +++ b/ProjectLighthouse/Migrations/20220805234507_AddModNotesToCase.cs @@ -0,0 +1,51 @@ +using LBPUnion.ProjectLighthouse; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ProjectLighthouse.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20220805234507_AddModNotesToCase")] + public partial class AddModNotesToCase : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "Description", + table: "Cases", + newName: "Reason"); + + migrationBuilder.AddColumn( + name: "ModeratorNotes", + table: "Cases", + type: "longtext", + nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AddColumn( + name: "Processed", + table: "Cases", + type: "tinyint(1)", + nullable: false, + defaultValue: false); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ModeratorNotes", + table: "Cases"); + + migrationBuilder.DropColumn( + name: "Processed", + table: "Cases"); + + migrationBuilder.RenameColumn( + name: "Reason", + table: "Cases", + newName: "Description"); + } + } +} diff --git a/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs b/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs index 73335081..1ebb7479 100644 --- a/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs +++ b/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs @@ -47,10 +47,6 @@ namespace ProjectLighthouse.Migrations b.Property("CreatorId") .HasColumnType("int"); - b.Property("Description") - .IsRequired() - .HasColumnType("longtext"); - b.Property("DismissedAt") .HasColumnType("datetime(6)"); @@ -60,6 +56,17 @@ namespace ProjectLighthouse.Migrations b.Property("ExpiresAt") .HasColumnType("datetime(6)"); + b.Property("ModeratorNotes") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Processed") + .HasColumnType("tinyint(1)"); + + b.Property("Reason") + .IsRequired() + .HasColumnType("longtext"); + b.Property("Type") .HasColumnType("int");