mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-13 00:31:28 +00:00
Allow moderators to moderate story levels (#809)
* Allow moderators to view story levels on website Show comments to moderators on in-game story levels that show the levels id * Only show LH ID comment on the first page
This commit is contained in:
parent
6e92ddc89f
commit
14ebad07f3
5 changed files with 66 additions and 2 deletions
|
@ -50,8 +50,13 @@ public class CommentController : ControllerBase
|
||||||
{
|
{
|
||||||
GameTokenEntity token = this.GetToken();
|
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();
|
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);
|
if (slotType == "developer") slotId = await SlotHelper.GetPlaceholderSlotId(this.database, slotId, SlotType.Developer);
|
||||||
|
|
||||||
int targetId;
|
int targetId;
|
||||||
|
@ -89,6 +94,17 @@ public class CommentController : ControllerBase
|
||||||
.ApplyPagination(pageData)
|
.ApplyPagination(pageData)
|
||||||
.ToListAsync()).ToSerializableList(c => GameComment.CreateFromEntity(c, token.UserId));
|
.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));
|
return this.Ok(new CommentListResponse(comments));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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<IActionResult> 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}");
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,4 +50,15 @@ else
|
||||||
<a href="/moderation/hiddenLevels/0" class="ui yellow button">
|
<a href="/moderation/hiddenLevels/0" class="ui yellow button">
|
||||||
<i class="globe americas icon"></i>
|
<i class="globe americas icon"></i>
|
||||||
<span>View hidden levels</span>
|
<span>View hidden levels</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<div class="ui divider"></div>
|
||||||
|
<form method="post" action="/moderation/findStoryLevel">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<div class="ui left action input">
|
||||||
|
<button type="submit" class="ui blue button">
|
||||||
|
<span>Find Story Level</span>
|
||||||
|
</button>
|
||||||
|
<input type="text" name="placeholderSlotId" placeholder="Level ID">
|
||||||
|
</div>
|
||||||
|
</form>
|
|
@ -29,7 +29,7 @@ public class SlotPage : BaseLayout
|
||||||
public async Task<IActionResult> OnGet([FromRoute] int id)
|
public async Task<IActionResult> OnGet([FromRoute] int id)
|
||||||
{
|
{
|
||||||
SlotEntity? slot = await this.Database.Slots.Include(s => s.Creator)
|
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);
|
.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||||
if (slot == null) return this.NotFound();
|
if (slot == null) return this.NotFound();
|
||||||
System.Diagnostics.Debug.Assert(slot.Creator != null);
|
System.Diagnostics.Debug.Assert(slot.Creator != null);
|
||||||
|
|
|
@ -53,6 +53,8 @@ public class GameComment : ILbpSerializable, INeedsPreparationForSerialization
|
||||||
|
|
||||||
public async Task PrepareSerialization(DatabaseContext database)
|
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)
|
this.AuthorUsername = await database.Users.Where(u => u.UserId == this.PosterUserId)
|
||||||
.Select(u => u.Username)
|
.Select(u => u.Username)
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue