From 6f55ce3226b8452443eec92176e0798157a6e381 Mon Sep 17 00:00:00 2001 From: koko Date: Wed, 26 Apr 2023 22:48:19 -0400 Subject: [PATCH] Add basic ability to flag duplicate levels (#753) * Add the basics for duplicate level flagging * Use this.BadRequest instead of StatusCode(500) * Remove redundant slot creator check * Include creator entity * Redirect back to slot page for unauthenticated reqs * Check if reporter = level creator on server side * A few formatting nitpicks with the webhook * Move external url config to a shorter var * Change duplicate flag button icon to a flag * Remove accidental dollar sign Co-authored-by: Josh * Remove another accidental dollar sign Co-authored-by: Josh * Three dollar signs... I'm blind Co-authored-by: Josh * Update ProjectLighthouse.Servers.Website/Controllers/Moderator/ModerationSlotController.cs Co-authored-by: Josh --------- Co-authored-by: Josh --- .../Moderator/ModerationSlotController.cs | 23 +++++++++++++++++++ .../Pages/Partials/SlotCardPartial.cshtml | 12 ++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/ProjectLighthouse.Servers.Website/Controllers/Moderator/ModerationSlotController.cs b/ProjectLighthouse.Servers.Website/Controllers/Moderator/ModerationSlotController.cs index df0632e5..383979a6 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/Moderator/ModerationSlotController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/Moderator/ModerationSlotController.cs @@ -68,4 +68,27 @@ public class ModerationSlotController : ControllerBase return this.Redirect("~/slots/0"); } + + [HttpGet("flag")] + public async Task FlagLevel([FromRoute] int id) + { + UserEntity? user = this.database.UserFromWebRequest(this.Request); + if (user == null) return this.Redirect($"~/slot/{id}"); + + SlotEntity? slot = await this.database.Slots.Include(s => s.Creator).FirstOrDefaultAsync(s => s.SlotId == id); + if (slot == null) return this.BadRequest(); + if (slot.CreatorId == user.UserId) return this.Redirect($"~/slot/{slot.SlotId}"); + + string externalUrl = ServerConfiguration.Instance.ExternalUrl; + + await WebhookHelper.SendWebhook(title: "New duplicate level flag", + description: @$"Level [**{slot.Name}**]({externalUrl}/slot/{slot.SlotId}) has been flagged as a duplicate level. + + > **Reporter:** [{user.Username}]({externalUrl}/user/{user.UserId}) + > **Offender:** [{slot.Creator!.Username}]({externalUrl}/user/{slot.CreatorId}) + > **Level Hash:** {slot.RootLevel}", + dest: WebhookHelper.WebhookDestination.Moderation); + + return this.Redirect($"~/slot/{slot.SlotId}"); + } } diff --git a/ProjectLighthouse.Servers.Website/Pages/Partials/SlotCardPartial.cshtml b/ProjectLighthouse.Servers.Website/Pages/Partials/SlotCardPartial.cshtml index 700edc45..a5c0bfa8 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Partials/SlotCardPartial.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/Partials/SlotCardPartial.cshtml @@ -104,12 +104,20 @@

- @if (user != null && !mini && (user.IsModerator || user.UserId == Model.CreatorId)) + @if (user != null && !mini && (user.IsModerator || Model.CreatorId == user.UserId)) { } + + @if (user != null && !mini && (user.UserId != Model.CreatorId)) + { + + + + }

@@ -142,4 +150,4 @@ } }
- \ No newline at end of file +