diff --git a/ProjectLighthouse.Servers.Website/Controllers/Admin/AdminReportController.cs b/ProjectLighthouse.Servers.Website/Controllers/Admin/AdminReportController.cs index d72c85b9..d394a82e 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/Admin/AdminReportController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/Admin/AdminReportController.cs @@ -48,7 +48,7 @@ public class AdminReportController : ControllerBase await this.database.SaveChangesAsync(); - return this.Redirect("~/admin/reports/0"); + return this.Redirect("~/modPanel/reports/0"); } [HttpGet("dismiss")] diff --git a/ProjectLighthouse.Servers.Website/Pages/Admin/ModPanelPage.cshtml b/ProjectLighthouse.Servers.Website/Pages/Admin/ModPanelPage.cshtml index 7268ba0b..293646f1 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Admin/ModPanelPage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/Admin/ModPanelPage.cshtml @@ -5,7 +5,7 @@ @{ Layout = "Layouts/BaseLayout"; - Model.Title = "Moderator Panel"; + Model.Title = "Moderation Panel"; } @if (!this.Request.IsMobile()) diff --git a/ProjectLighthouse.Servers.Website/Pages/Admin/ModPanelPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Admin/ModPanelPage.cshtml.cs index 1b91ed67..d722eb02 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Admin/ModPanelPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Admin/ModPanelPage.cshtml.cs @@ -20,6 +20,7 @@ public class ModPanelPage : BaseLayout if (!user.IsModerator) return this.NotFound(); this.Statistics.Add(new AdminPanelStatistic("Reports", await StatisticsHelper.ReportCount(), "/modPanel/reports/0")); + this.Statistics.Add(new AdminPanelStatistic("Cases", await StatisticsHelper.CaseCount(), "/modPanel/cases/0")); return this.Page(); } diff --git a/ProjectLighthouse.Servers.Website/Pages/ReportsPage.cshtml b/ProjectLighthouse.Servers.Website/Pages/Admin/ReportsPage.cshtml similarity index 99% rename from ProjectLighthouse.Servers.Website/Pages/ReportsPage.cshtml rename to ProjectLighthouse.Servers.Website/Pages/Admin/ReportsPage.cshtml index 5cfba37a..ebec1e28 100644 --- a/ProjectLighthouse.Servers.Website/Pages/ReportsPage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/Admin/ReportsPage.cshtml @@ -1,6 +1,6 @@ @page "/modPanel/reports/{pageNumber:int}" @using LBPUnion.ProjectLighthouse.Administration.Reports -@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.ReportsPage +@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin.ReportsPage @{ Layout = "Layouts/BaseLayout"; diff --git a/ProjectLighthouse.Servers.Website/Pages/ReportsPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Admin/ReportsPage.cshtml.cs similarity index 91% rename from ProjectLighthouse.Servers.Website/Pages/ReportsPage.cshtml.cs rename to ProjectLighthouse.Servers.Website/Pages/Admin/ReportsPage.cshtml.cs index 50f21c3c..9318dc3e 100644 --- a/ProjectLighthouse.Servers.Website/Pages/ReportsPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Admin/ReportsPage.cshtml.cs @@ -4,15 +4,13 @@ using LBPUnion.ProjectLighthouse.Administration.Reports; using LBPUnion.ProjectLighthouse.Configuration; using LBPUnion.ProjectLighthouse.PlayerData.Profiles; using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts; -using LBPUnion.ProjectLighthouse.Types; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages; +namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin; public class ReportsPage : BaseLayout { - public int PageAmount; public int PageNumber; @@ -42,7 +40,7 @@ public class ReportsPage : BaseLayout this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.ReportCount / ServerStatics.PageSize)); if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) - return this.Redirect($"/admin/reports/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}"); + return this.Redirect($"/modPanel/reports/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}"); this.Reports = await this.Database.Reports.Include(r => r.ReportingPlayer) .Where(r => r.ReportingPlayer.Username.Contains(this.SearchValue)) diff --git a/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml b/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml new file mode 100644 index 00000000..410424af --- /dev/null +++ b/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml @@ -0,0 +1,13 @@ +@page "/modPanel/cases/{pageNumber:int}" +@using LBPUnion.ProjectLighthouse.Administration +@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.CasePage + +@{ + Layout = "Layouts/BaseLayout"; + Model.Title = "Cases"; +} + +@foreach (ModerationCase @case in Model.Cases) +{ + @(await Html.PartialAsync("Partials/ModerationCasePartial", @case)) +} \ No newline at end of file diff --git a/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml.cs new file mode 100644 index 00000000..e5457a3e --- /dev/null +++ b/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml.cs @@ -0,0 +1,36 @@ +using LBPUnion.ProjectLighthouse.Administration; +using LBPUnion.ProjectLighthouse.PlayerData.Profiles; +using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages; + +public class CasePage : BaseLayout +{ + public CasePage(Database database) : base(database) + {} + + public List Cases = new(); + + public async Task OnGet(int pageNumber) + { + User? user = this.Database.UserFromWebRequest(this.Request); + if (user == null) return this.NotFound(); + if (!user.IsModerator) return this.NotFound(); + + this.Cases.Add(new ModerationCase + { + CaseId = 1, + CaseCreated = DateTime.Now, + CaseExpires = new DateTime(2023, 11, 17), + CaseCreatorId = user.UserId, + CaseCreator = user, + CaseDescription = "Being a dumbass", + CaseType = CaseType.UserBan, + AffectedId = user.UserId, + }); + + return this.Page(); + } +} \ No newline at end of file diff --git a/ProjectLighthouse.Servers.Website/Pages/Partials/ModerationCasePartial.cshtml b/ProjectLighthouse.Servers.Website/Pages/Partials/ModerationCasePartial.cshtml new file mode 100644 index 00000000..9915aa06 --- /dev/null +++ b/ProjectLighthouse.Servers.Website/Pages/Partials/ModerationCasePartial.cshtml @@ -0,0 +1,35 @@ +@using LBPUnion.ProjectLighthouse +@using LBPUnion.ProjectLighthouse.Administration +@using LBPUnion.ProjectLighthouse.Configuration +@using LBPUnion.ProjectLighthouse.Levels +@using LBPUnion.ProjectLighthouse.PlayerData.Profiles +@model LBPUnion.ProjectLighthouse.Administration.ModerationCase + +@{ + Database database = new(); +} + +
+

Case #@Model.CaseId: @Model.CaseType

+

Created by @Model.CaseCreator?.Username

+

Description: @Model.CaseDescription

+ @if (Model.CaseType.AffectsLevel()) + { + Slot slot = await Model.GetSlotAsync(database); +

Affected level: @slot.Name

+ } + @if (Model.CaseType.AffectsUser()) + { + User user = await Model.GetUserAsync(database); +

Affected user: @user.Username

+ } + + @if (ServerStatics.IsDebug) + { +

+ DEBUG SHIT
+ Affects level: @Model.CaseType.AffectsLevel()
+ Affects user: @Model.CaseType.AffectsUser() +

+ } +
\ No newline at end of file diff --git a/ProjectLighthouse.sln.DotSettings b/ProjectLighthouse.sln.DotSettings index 524940d2..42222e1c 100644 --- a/ProjectLighthouse.sln.DotSettings +++ b/ProjectLighthouse.sln.DotSettings @@ -113,6 +113,7 @@ True True True + True True True True diff --git a/ProjectLighthouse/Administration/CaseType.cs b/ProjectLighthouse/Administration/CaseType.cs index bc96b572..929ea0eb 100644 --- a/ProjectLighthouse/Administration/CaseType.cs +++ b/ProjectLighthouse/Administration/CaseType.cs @@ -28,4 +28,36 @@ public enum CaseType HashModeration = 14, IpAddressBan = 15, +} + +public static class CaseTypeExtensions +{ + public static bool AffectsUser(this CaseType type) + { + return type switch + { + CaseType.UserSilence => true, + CaseType.UserRestriction => true, + CaseType.UserBan => true, + CaseType.UserDeletion => true, + CaseType.UserCommentsDisabled => true, + CaseType.UserDetailsEdited => true, + CaseType.UserEarthDeletion => true, + _ => false, + }; + } + + public static bool AffectsLevel(this CaseType type) + { + return type switch + { + CaseType.LevelDeletion => true, + CaseType.LevelLock => true, + CaseType.LevelCommentsDisabled => true, + CaseType.LevelDetailsEdited => true, + CaseType.LevelTeamPickAdded => true, + CaseType.LevelTeamPickRemoved => true, + _ => false, + }; + } } \ No newline at end of file diff --git a/ProjectLighthouse/Administration/ModerationCase.cs b/ProjectLighthouse/Administration/ModerationCase.cs index 1a6969c2..6d4b6760 100644 --- a/ProjectLighthouse/Administration/ModerationCase.cs +++ b/ProjectLighthouse/Administration/ModerationCase.cs @@ -1,7 +1,11 @@ using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; +using System.Threading.Tasks; +using LBPUnion.ProjectLighthouse.Levels; using LBPUnion.ProjectLighthouse.PlayerData.Profiles; +using Microsoft.EntityFrameworkCore; namespace LBPUnion.ProjectLighthouse.Administration; #nullable enable @@ -23,4 +27,20 @@ public class ModerationCase [ForeignKey(nameof(CaseCreatorId))] public User? CaseCreator { get; set; } + + public int AffectedId { get; set; } + + #region Get affected id result + public Task GetUserAsync(Database database) + { + Debug.Assert(CaseType.AffectsUser()); + return database.Users.FirstOrDefaultAsync(u => u.UserId == this.AffectedId)!; + } + + public Task GetSlotAsync(Database database) + { + Debug.Assert(CaseType.AffectsLevel()); + return database.Slots.FirstOrDefaultAsync(u => u.SlotId == this.AffectedId)!; + } + #endregion } \ No newline at end of file diff --git a/ProjectLighthouse/Helpers/StatisticsHelper.cs b/ProjectLighthouse/Helpers/StatisticsHelper.cs index a44c6fbc..d060f007 100644 --- a/ProjectLighthouse/Helpers/StatisticsHelper.cs +++ b/ProjectLighthouse/Helpers/StatisticsHelper.cs @@ -13,8 +13,7 @@ public static class StatisticsHelper public static async Task RecentMatches() => await database.LastContacts.Where(l => TimeHelper.Timestamp - l.Timestamp < 300).CountAsync(); - public static async Task RecentMatchesForGame - (GameVersion gameVersion) + public static async Task RecentMatchesForGame(GameVersion gameVersion) => await database.LastContacts.Where(l => TimeHelper.Timestamp - l.Timestamp < 300 && l.GameVersion == gameVersion).CountAsync(); public static async Task SlotCount() => await database.Slots.CountAsync(); @@ -24,6 +23,9 @@ public static class StatisticsHelper public static async Task TeamPickCount() => await database.Slots.CountAsync(s => s.TeamPick); public static async Task PhotoCount() => await database.Photos.CountAsync(); - + + #region Moderator/Admin specific public static async Task ReportCount() => await database.Reports.CountAsync(); + public static async Task CaseCount() => await database.Cases.CountAsync(); + #endregion } \ No newline at end of file diff --git a/ProjectLighthouse/Migrations/20220611012037_AddAffectedIdToCases.cs b/ProjectLighthouse/Migrations/20220611012037_AddAffectedIdToCases.cs new file mode 100644 index 00000000..4f906d80 --- /dev/null +++ b/ProjectLighthouse/Migrations/20220611012037_AddAffectedIdToCases.cs @@ -0,0 +1,30 @@ +using LBPUnion.ProjectLighthouse; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ProjectLighthouse.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20220611012037_AddAffectedIdToCases")] + public class AddAffectedIdToCases : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "AffectedId", + table: "Cases", + type: "int", + nullable: false, + defaultValue: 0); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "AffectedId", + table: "Cases"); + } + } +} diff --git a/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs b/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs index aa8a3b1b..28b23b45 100644 --- a/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs +++ b/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs @@ -38,6 +38,9 @@ namespace ProjectLighthouse.Migrations .ValueGeneratedOnAdd() .HasColumnType("int"); + b.Property("AffectedId") + .HasColumnType("int"); + b.Property("CaseCreated") .HasColumnType("datetime(6)");