diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs index fc421375..e02b8f81 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/SlotsController.cs @@ -523,10 +523,10 @@ public class SlotsController : ControllerBase if (gameFilterType == "both") // Get game versions less than the current version // Needs support for LBP3 ("both" = LBP1+2) - whereSlots = this.database.Slots.Where(s => s.Type == SlotType.User && s.GameVersion <= gameVersion && s.FirstUploaded >= oldestTime); + whereSlots = this.database.Slots.Where(s => s.Type == SlotType.User && !s.Hidden && s.GameVersion <= gameVersion && s.FirstUploaded >= oldestTime); else // Get game versions exactly equal to gamefiltertype - whereSlots = this.database.Slots.Where(s => s.Type == SlotType.User && s.GameVersion == gameVersion && s.FirstUploaded >= oldestTime); + whereSlots = this.database.Slots.Where(s => s.Type == SlotType.User && !s.Hidden && s.GameVersion == gameVersion && s.FirstUploaded >= oldestTime); return whereSlots.Include(s => s.Creator).Include(s => s.Location); } diff --git a/ProjectLighthouse.Servers.Website/Controllers/Admin/AdminUserController.cs b/ProjectLighthouse.Servers.Website/Controllers/Admin/AdminUserController.cs index 18bf4566..61e65eda 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/Admin/AdminUserController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/Admin/AdminUserController.cs @@ -20,22 +20,6 @@ public class AdminUserController : ControllerBase this.database = database; } - [HttpGet("unban")] - public async Task UnbanUser([FromRoute] int id) - { - User? user = this.database.UserFromWebRequest(this.Request); - if (user == null || !user.IsModerator) return this.NotFound(); - - User? targetedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id); - if (targetedUser == null) return this.NotFound(); - - targetedUser.PermissionLevel = PermissionLevel.Default; - targetedUser.BannedReason = null; - - await this.database.SaveChangesAsync(); - return this.Redirect($"/user/{targetedUser.UserId}"); - } - /// /// Resets the user's earth decorations to a blank state. Useful for users who abuse audio for example. /// diff --git a/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml.cs index bd7c1707..9d1782f8 100644 --- a/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/LandingPage.cshtml.cs @@ -42,15 +42,18 @@ public class LandingPage : BaseLayout const int maxShownLevels = 5; - this.LatestTeamPicks = await this.Database.Slots.Where - (s => s.Type == SlotType.User) + this.LatestTeamPicks = await this.Database.Slots.Where(s => s.Type == SlotType.User && s.Type == SlotType.User) .Where(s => s.TeamPick) .OrderByDescending(s => s.FirstUploaded) .Take(maxShownLevels) .Include(s => s.Creator) .ToListAsync(); - this.NewestLevels = await this.Database.Slots.Where(s => s.Type == SlotType.User).OrderByDescending(s => s.FirstUploaded).Take(maxShownLevels).Include(s => s.Creator).ToListAsync(); + this.NewestLevels = await this.Database.Slots.Where(s => s.Type == SlotType.User && s.Type == SlotType.User) + .OrderByDescending(s => s.FirstUploaded) + .Take(maxShownLevels) + .Include(s => s.Creator) + .ToListAsync(); return this.Page(); } diff --git a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml index 2fa527cf..f2e57af7 100644 --- a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml @@ -17,6 +17,18 @@ bool isMobile = this.Request.IsMobile(); } +@if (Model.Slot.Hidden) +{ +
+

This level is currently hidden.

+

Only you and moderators may view this level.

+ + Reason: "@Model.Slot.HiddenReason" + +

For more information please contact a moderator.

+
+} + @await Html.PartialAsync("Partials/SlotCardPartial", Model.Slot, new ViewDataDictionary(ViewData) { { @@ -210,5 +222,15 @@ Delete + + @if (!(bool)Model.Slot?.Hidden) + { + +
+ + Hide +
+
+ } } \ No newline at end of file diff --git a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs index c870bfc1..9128a58a 100644 --- a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs @@ -26,8 +26,7 @@ public class SlotPage : BaseLayout public async Task OnGet([FromRoute] int id) { - Slot? slot = await this.Database.Slots.Include - (s => s.Creator) + Slot? slot = await this.Database.Slots.Include(s => s.Creator) .Where(s => s.Type == SlotType.User) .FirstOrDefaultAsync(s => s.SlotId == id); if (slot == null) return this.NotFound(); @@ -55,6 +54,8 @@ public class SlotPage : BaseLayout } } + if (slot.Hidden && (this.User != slot.Creator && !(bool)this.User?.IsModerator)) return this.NotFound(); + this.Slot = slot; if (this.CommentsEnabled) diff --git a/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml b/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml index 5f022378..785184b9 100644 --- a/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml @@ -24,12 +24,8 @@ Reason: "@Model.ProfileUser.BannedReason"

- Note: Only you and other admins may view the ban reason. + Note: Only you and other moderators may view the ban reason.

- - - Unban User - } else { diff --git a/ProjectLighthouse/Administration/CaseType.cs b/ProjectLighthouse/Administration/CaseType.cs index eac1c574..23c7a0ea 100644 --- a/ProjectLighthouse/Administration/CaseType.cs +++ b/ProjectLighthouse/Administration/CaseType.cs @@ -15,7 +15,7 @@ public enum CaseType UserBan = 2, UserCommentsDisabled = 3, - LevelLock = 4, + LevelHide = 4, LevelCommentsDisabled = 5, } @@ -37,7 +37,7 @@ public static class CaseTypeExtensions { return type switch { - CaseType.LevelLock => true, + CaseType.LevelHide => true, CaseType.LevelCommentsDisabled => true, _ => false, }; diff --git a/ProjectLighthouse/Administration/Maintenance/RepeatingTasks/PerformCaseActionsTask.cs b/ProjectLighthouse/Administration/Maintenance/RepeatingTasks/PerformCaseActionsTask.cs index 3bd86f13..8dcc46cf 100644 --- a/ProjectLighthouse/Administration/Maintenance/RepeatingTasks/PerformCaseActionsTask.cs +++ b/ProjectLighthouse/Administration/Maintenance/RepeatingTasks/PerformCaseActionsTask.cs @@ -41,7 +41,14 @@ public class PerformCaseActionsTask : IRepeatingTask break; }; case CaseType.UserCommentsDisabled: break; - case CaseType.LevelLock: break; + + case CaseType.LevelHide: + { + slot!.Hidden = false; + slot.HiddenReason = ""; + + break; + } case CaseType.LevelCommentsDisabled: break; default: throw new ArgumentOutOfRangeException(); } @@ -70,7 +77,14 @@ public class PerformCaseActionsTask : IRepeatingTask break; } case CaseType.UserCommentsDisabled: break; - case CaseType.LevelLock: break; + + case CaseType.LevelHide: + { + slot!.Hidden = true; + slot.HiddenReason = @case.Reason; + + break; + } case CaseType.LevelCommentsDisabled: break; default: throw new ArgumentOutOfRangeException(); } diff --git a/ProjectLighthouse/Levels/Slot.cs b/ProjectLighthouse/Levels/Slot.cs index caf72beb..deb40fb7 100644 --- a/ProjectLighthouse/Levels/Slot.cs +++ b/ProjectLighthouse/Levels/Slot.cs @@ -245,6 +245,12 @@ public class Slot [XmlElement("vitaCrossControlRequired")] public bool CrossControllerRequired { get; set; } + + [JsonIgnore] + public bool Hidden { get; set; } + + [JsonIgnore] + public string HiddenReason { get; set; } public string SerializeResources() { diff --git a/ProjectLighthouse/Migrations/20220806013840_AddHiddenSlots.cs b/ProjectLighthouse/Migrations/20220806013840_AddHiddenSlots.cs new file mode 100644 index 00000000..68e16ea7 --- /dev/null +++ b/ProjectLighthouse/Migrations/20220806013840_AddHiddenSlots.cs @@ -0,0 +1,41 @@ +using LBPUnion.ProjectLighthouse; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ProjectLighthouse.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20220806013840_AddHiddenSlots")] + public partial class AddHiddenSlots : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Hidden", + table: "Slots", + type: "tinyint(1)", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "HiddenReason", + table: "Slots", + type: "longtext", + nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Hidden", + table: "Slots"); + + migrationBuilder.DropColumn( + name: "HiddenReason", + table: "Slots"); + } + } +} diff --git a/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs b/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs index 1ebb7479..41940fd2 100644 --- a/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs +++ b/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs @@ -250,6 +250,13 @@ namespace ProjectLighthouse.Migrations b.Property("GameVersion") .HasColumnType("int"); + b.Property("Hidden") + .HasColumnType("tinyint(1)"); + + b.Property("HiddenReason") + .IsRequired() + .HasColumnType("longtext"); + b.Property("IconHash") .IsRequired() .HasColumnType("longtext");