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
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

@ -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; }
@ -33,9 +35,18 @@ public class NewCasePage : BaseLayout
this.Type = type.Value;
this.AffectedId = affectedId.Value;
this.AffectedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == this.AffectedId);
if (this.AffectedUser == null) return this.BadRequest();
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,15 +69,27 @@ 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 (affectedUser == null) return this.NotFound();
if (affectedUser.IsModerator)
if (type.Value.AffectsUser())
{
this.Error = this.Translate(ErrorStrings.ActionNoPermission);
return this.Page();
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()