Fix rendering issues with case creation page (#863)

This commit is contained in:
koko 2023-08-08 20:24:03 -04:00 committed by GitHub
parent 027173b9c7
commit 1d89f7c548
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 38 deletions

View file

@ -2,6 +2,7 @@
@using LBPUnion.ProjectLighthouse.Localization.StringLists
@using LBPUnion.ProjectLighthouse.Servers.Website.Extensions
@using LBPUnion.ProjectLighthouse.Types.Entities.Moderation
@using LBPUnion.ProjectLighthouse.Types.Moderation.Cases
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Moderation.NewCasePage
@{
@ -27,9 +28,18 @@
<div>
<b>Case Type:</b> @Model.Type.ToString()
</div>
@if (Model.Type.AffectsUser())
{
<div>
<b>Affected User:</b> <a href="/user/@Model.AffectedId">@Model.AffectedUser!.Username (id: @Model.AffectedId)</a>
</div>
}
else if (Model.Type.AffectsLevel())
{
<div>
<b>Affected Level:</b> <a href="/user/@Model.AffectedId">@Model.AffectedSlot!.Name (id: @Model.AffectedId)</a>
</div>
}
</div>
<div class="ui yellow segment">
@ -50,6 +60,8 @@
</button>
</div>
@if (Model.Type.AffectsUser())
{
<div class="ui blue segment">
<details style="transition: max-height 0.25s ease-in-out;">
<summary>Moderation history for user <a href="/user/@Model.AffectedId">@Model.AffectedUser!.Username</a></summary>
@ -80,6 +92,7 @@
</div>
</details>
</div>
}
<div class="ui red segment">
<div style="margin-bottom: 1em;">

View file

@ -1,6 +1,7 @@
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Localization.StringLists;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Moderation;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Moderation.Cases;
@ -18,6 +19,7 @@ public class NewCasePage : BaseLayout
public int AffectedId { get; set; }
public UserEntity? AffectedUser { get; set; }
public SlotEntity? AffectedSlot { get; set; }
public List<ModerationCaseEntity> AffectedHistory { get; set; } = new();
public string? Error { get; private set; }
@ -34,8 +36,17 @@ public class NewCasePage : BaseLayout
this.AffectedId = affectedId.Value;
if (this.Type.AffectsUser())
{
this.AffectedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == this.AffectedId);
if (this.AffectedUser == null) return this.BadRequest();
}
else if (this.Type.AffectsLevel())
{
this.AffectedSlot = await this.Database.Slots.FirstOrDefaultAsync(s => s.SlotId == this.AffectedId);
if (this.AffectedSlot == null) return this.BadRequest();
}
else return this.BadRequest();
this.AffectedHistory = await this.Database.Cases.Where(c => c.AffectedId == this.AffectedId)
.OrderByDescending(c => c.CreatedAt)
@ -58,16 +69,28 @@ public class NewCasePage : BaseLayout
// if id is invalid then return bad request
if (!await type.Value.IsIdValid((int)affectedId, this.Database)) return this.BadRequest();
UserEntity? affectedUser =
await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == affectedId.Value);
if (type.Value.AffectsUser())
{
UserEntity? affectedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == affectedId.Value);
if (affectedUser == null) return this.NotFound();
if (affectedUser.IsModerator)
{
this.Error = this.Translate(ErrorStrings.ActionNoPermission);
this.Type = type.Value;
this.AffectedId = affectedId.Value;
this.AffectedUser = affectedUser;
this.AffectedHistory = await this.Database.Cases.Where(c => c.AffectedId == this.AffectedId)
.OrderByDescending(c => c.CreatedAt)
.ToListAsync();
return this.Page();
}
}
ModerationCaseEntity @case = new()
{