Open up new case page for moderators

This commit is contained in:
jvyden 2022-08-05 20:55:47 -04:00
commit d540a54cd8
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
6 changed files with 94 additions and 69 deletions

View file

@ -0,0 +1,56 @@
using LBPUnion.ProjectLighthouse.Administration;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using Microsoft.AspNetCore.Mvc;
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin;
public class NewCasePage : BaseLayout
{
public NewCasePage(Database database) : base(database)
{}
public CaseType Type { get; set; }
public int AffectedId { get; set; }
public IActionResult OnGet([FromQuery] CaseType? type)
{
User? user = this.Database.UserFromWebRequest(this.Request);
if (user == null || !user.IsModerator) return this.Redirect("/login");
if (type == null) return this.BadRequest();
this.Type = (CaseType)type;
return this.Page();
}
public async Task<IActionResult> OnPost(CaseType? type, string reason, string modNotes, DateTime expires, int affectedId)
{
User? user = this.Database.UserFromWebRequest(this.Request);
if (user == null || !user.IsModerator) return this.Redirect("/login");
if (type == null) return this.BadRequest();
// this is fucking ugly and so is the person who wrote it
// if id is invalid then return bad request
if (!(await ((CaseType)type).IsIdValid(affectedId, this.Database))) return this.BadRequest();
ModerationCase @case = new()
{
Type = (CaseType)type,
Reason = reason,
ModeratorNotes = modNotes,
ExpiresAt = expires,
CreatedAt = DateTime.Now,
CreatorId = user.UserId,
AffectedId = affectedId,
};
this.Database.Cases.Add(@case);
await this.Database.SaveChangesAsync();
return this.Redirect("/moderation/cases/0");
}
}