diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs index 8c861062..15d06544 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs @@ -50,8 +50,13 @@ public class CommentController : ControllerBase { GameTokenEntity token = this.GetToken(); + UserEntity? user = await this.database.UserFromGameToken(token); + if (user == null) return this.Unauthorized(); + if ((slotId == 0 || SlotHelper.IsTypeInvalid(slotType)) == (username == null)) return this.BadRequest(); + int originalSlotId = slotId; + if (slotType == "developer") slotId = await SlotHelper.GetPlaceholderSlotId(this.database, slotId, SlotType.Developer); int targetId; @@ -89,6 +94,17 @@ public class CommentController : ControllerBase .ApplyPagination(pageData) .ToListAsync()).ToSerializableList(c => GameComment.CreateFromEntity(c, token.UserId)); + if (type == CommentType.Level && slotType == "developer" && user.IsModerator && pageData.PageStart == 1) + { + comments.Insert(0, new GameComment + { + CommentId = 0, + Timestamp = 0, + AuthorUsername = "LH", + Message = $"Slot ID: {targetId}, Story level ID: {originalSlotId}", + }); + } + return this.Ok(new CommentListResponse(comments)); } diff --git a/ProjectLighthouse.Servers.Website/Controllers/Moderator/ModerationPageController.cs b/ProjectLighthouse.Servers.Website/Controllers/Moderator/ModerationPageController.cs new file mode 100644 index 00000000..d9d950be --- /dev/null +++ b/ProjectLighthouse.Servers.Website/Controllers/Moderator/ModerationPageController.cs @@ -0,0 +1,35 @@ +using LBPUnion.ProjectLighthouse.Database; +using LBPUnion.ProjectLighthouse.Types.Entities.Profile; +using LBPUnion.ProjectLighthouse.Types.Levels; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Moderator; + +[ApiController] +[Route("moderation")] +public class ModerationPageController : ControllerBase +{ + private readonly DatabaseContext database; + + public ModerationPageController(DatabaseContext database) + { + this.database = database; + } + + [HttpPost("findStoryLevel")] + public async Task FindStorySlot([FromForm] int placeholderSlotId) + { + UserEntity? user = this.database.UserFromWebRequest(this.Request); + if (user == null) return this.Redirect("~/login"); + + if (!user.IsModerator) return this.Redirect("~/"); + + int slotId = await this.database.Slots.Where(s => s.Type == SlotType.Developer) + .Where(s => s.InternalSlotId == placeholderSlotId) + .Select(s => s.SlotId) + .FirstOrDefaultAsync(); + + return this.Redirect(slotId == 0 ? "~/" : $"~/slot/{slotId}"); + } +} \ No newline at end of file diff --git a/ProjectLighthouse.Servers.Website/Pages/Moderation/ModPanelPage.cshtml b/ProjectLighthouse.Servers.Website/Pages/Moderation/ModPanelPage.cshtml index 00d1851f..e2cb3a72 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Moderation/ModPanelPage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/Moderation/ModPanelPage.cshtml @@ -50,4 +50,15 @@ else View hidden levels - \ No newline at end of file + + +
+
+ @Html.AntiForgeryToken() +
+ + +
+
\ 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 dc5d06ef..ebdd9076 100644 --- a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs @@ -29,7 +29,7 @@ public class SlotPage : BaseLayout public async Task OnGet([FromRoute] int id) { SlotEntity? slot = await this.Database.Slots.Include(s => s.Creator) - .Where(s => s.Type == SlotType.User) + .Where(s => s.Type == SlotType.User || (this.User != null && this.User.PermissionLevel >= PermissionLevel.Moderator)) .FirstOrDefaultAsync(s => s.SlotId == id); if (slot == null) return this.NotFound(); System.Diagnostics.Debug.Assert(slot.Creator != null); diff --git a/ProjectLighthouse/Types/Serialization/GameComment.cs b/ProjectLighthouse/Types/Serialization/GameComment.cs index a2c0b5bc..07919f5e 100644 --- a/ProjectLighthouse/Types/Serialization/GameComment.cs +++ b/ProjectLighthouse/Types/Serialization/GameComment.cs @@ -53,6 +53,8 @@ public class GameComment : ILbpSerializable, INeedsPreparationForSerialization public async Task PrepareSerialization(DatabaseContext database) { + if (this.CommentId == 0 || this.PosterUserId == 0) return; + this.AuthorUsername = await database.Users.Where(u => u.UserId == this.PosterUserId) .Select(u => u.Username) .FirstOrDefaultAsync();