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 <josh@slendy.pw>

* Remove another accidental dollar sign

Co-authored-by: Josh <josh@slendy.pw>

* Three dollar signs... I'm blind

Co-authored-by: Josh <josh@slendy.pw>

* Update ProjectLighthouse.Servers.Website/Controllers/Moderator/ModerationSlotController.cs

Co-authored-by: Josh <josh@slendy.pw>

---------

Co-authored-by: Josh <josh@slendy.pw>
This commit is contained in:
koko 2023-04-26 22:48:19 -04:00 committed by GitHub
parent eb79d7cf48
commit 6f55ce3226
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View file

@ -68,4 +68,27 @@ public class ModerationSlotController : ControllerBase
return this.Redirect("~/slots/0");
}
[HttpGet("flag")]
public async Task<IActionResult> 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}");
}
}

View file

@ -104,12 +104,20 @@
</div>
<div class="cardButtons">
<br>
@if (user != null && !mini && (user.IsModerator || user.UserId == Model.CreatorId))
@if (user != null && !mini && (user.IsModerator || Model.CreatorId == user.UserId))
{
<a class="ui blue tiny button" href="/slot/@Model.SlotId/settings" title="Settings">
<i class="cog icon" style="margin: 0"></i>
</a>
}
@if (user != null && !mini && (user.UserId != Model.CreatorId))
{
<a class="ui red tiny button" href="/moderation/slot/@Model.SlotId/flag" title="Flag As Duplicate"
onclick='return confirm("Are you sure you want to flag this level as a duplicate? False reports may result in punishment.")'>
<i class="flag icon" style="margin: 0"></i>
</a>
}
</div>
<div class="cardButtons" style="margin-left: 0">
<br>