mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-24 14:11:29 +00:00
Redesign case creation page (#854)
* Redesign case creation page * Fix user id placeholder text * Handle empty moderation history * Mod history dropdown nitpick * Fix styling issue with dropdown ui fluid dropdown inherits from ui form * Potentially fix NRE * Un-require reason/mod notes * Display username in moderation history view * Order mod history by creation time descending * Nitpick no moderation history string * Handle AffectedUser null check within controller * Fix styling issues * Move moderation history segment above create case button segment * Link back to affected user * Move expiration field in with the other entries * Grammatical consistency nitpick in history dropdown * Handle empty case reasons in mod history * This is the last nitpick, I swear! * I lied. Variable naming consistency :trollface: * Consolidate setPermanent function into button onclick * Use HTML details and Fomantic list instead of dropdown * Fix padding issue with details list * Format history and user/id nicely * Styling fixes and nitpicks of list items/links * Apply suggestions from code review * Clarification with code review suggestion
This commit is contained in:
parent
24225d5ef5
commit
027173b9c7
3 changed files with 103 additions and 21 deletions
|
@ -12,14 +12,17 @@ namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Moderation;
|
|||
public class NewCasePage : BaseLayout
|
||||
{
|
||||
public NewCasePage(DatabaseContext database) : base(database)
|
||||
{}
|
||||
{ }
|
||||
|
||||
public CaseType Type { get; set; }
|
||||
|
||||
public int AffectedId { get; set; }
|
||||
public UserEntity? AffectedUser { get; set; }
|
||||
public List<ModerationCaseEntity> AffectedHistory { get; set; } = new();
|
||||
|
||||
public string? Error { get; private set; }
|
||||
|
||||
public IActionResult OnGet([FromQuery] CaseType? type, [FromQuery] int? affectedId)
|
||||
public async Task<IActionResult> OnGet([FromQuery] CaseType? type, [FromQuery] int? affectedId)
|
||||
{
|
||||
UserEntity? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsModerator) return this.Redirect("/login");
|
||||
|
@ -28,8 +31,16 @@ public class NewCasePage : BaseLayout
|
|||
if (affectedId == null) return this.BadRequest();
|
||||
|
||||
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();
|
||||
|
||||
this.AffectedHistory = await this.Database.Cases.Where(c => c.AffectedId == this.AffectedId)
|
||||
.OrderByDescending(c => c.CreatedAt)
|
||||
.ToListAsync();
|
||||
|
||||
return this.Page();
|
||||
}
|
||||
|
||||
|
@ -43,14 +54,16 @@ public class NewCasePage : BaseLayout
|
|||
|
||||
reason ??= string.Empty;
|
||||
modNotes ??= string.Empty;
|
||||
|
||||
|
||||
// if id is invalid then return bad request
|
||||
if (!await type.Value.IsIdValid((int)affectedId, this.Database)) return this.BadRequest();
|
||||
|
||||
UserEntity? affectedUserEntity =
|
||||
UserEntity? affectedUser =
|
||||
await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == affectedId.Value);
|
||||
|
||||
if (affectedUserEntity?.IsModerator ?? false)
|
||||
if (affectedUser == null) return this.NotFound();
|
||||
|
||||
if (affectedUser.IsModerator)
|
||||
{
|
||||
this.Error = this.Translate(ErrorStrings.ActionNoPermission);
|
||||
return this.Page();
|
||||
|
@ -70,7 +83,7 @@ public class NewCasePage : BaseLayout
|
|||
|
||||
this.Database.Cases.Add(@case);
|
||||
await this.Database.SaveChangesAsync();
|
||||
|
||||
|
||||
return this.Redirect("/moderation/cases/0");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue