mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-15 06:02:28 +00:00
Add support for dismissing cases
This commit is contained in:
parent
1996c1cdbb
commit
96e8c7f71e
6 changed files with 86 additions and 10 deletions
|
@ -0,0 +1,52 @@
|
|||
using LBPUnion.ProjectLighthouse.Administration;
|
||||
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin;
|
||||
|
||||
[ApiController]
|
||||
[Route("moderation/case/{id:int}")]
|
||||
public class ModerationCaseController : ControllerBase
|
||||
{
|
||||
private readonly Database database;
|
||||
|
||||
public ModerationCaseController(Database database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
[HttpGet("dismiss")]
|
||||
public async Task<IActionResult> DismissCase([FromRoute] int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsModerator) return this.StatusCode(403, "");
|
||||
|
||||
ModerationCase? @case = await this.database.Cases.FirstOrDefaultAsync(c => c.CaseId == id);
|
||||
if (@case == null) return this.NotFound();
|
||||
|
||||
@case.DismissedAt = DateTime.Now;
|
||||
@case.DismisserId = user.UserId;
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Ok();
|
||||
}
|
||||
|
||||
[HttpGet("undoDismiss")]
|
||||
public async Task<IActionResult> UndoDismissCase([FromRoute] int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsModerator) return this.StatusCode(403, "");
|
||||
|
||||
ModerationCase? @case = await this.database.Cases.FirstOrDefaultAsync(c => c.CaseId == id);
|
||||
if (@case == null) return this.NotFound();
|
||||
|
||||
@case.DismissedAt = null;
|
||||
@case.DismisserId = null;
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Ok();
|
||||
}
|
||||
}
|
|
@ -61,6 +61,7 @@
|
|||
<select name="role" class="ui selection dropdown">
|
||||
@foreach (PermissionLevel level in Enum.GetValues<PermissionLevel>())
|
||||
{
|
||||
if(level < 0) continue;
|
||||
string selected = level == user.PermissionLevel ? " selected" : "";
|
||||
|
||||
<option value="@((int)level)"@selected>@level.ToString()</option>
|
||||
|
|
|
@ -31,6 +31,8 @@ public class CasePage : BaseLayout
|
|||
this.SearchValue = name.Replace(" ", string.Empty);
|
||||
|
||||
this.Cases = await this.Database.Cases
|
||||
.Include(c => c.Creator)
|
||||
.Include(c => c.Dismisser)
|
||||
.OrderByDescending(c => c.CaseId)
|
||||
.ToListAsync();
|
||||
this.CaseCount = await this.Database.Cases.CountAsync(c => c.Description.Contains(this.SearchValue));
|
||||
|
|
|
@ -22,13 +22,13 @@
|
|||
Debug.Assert(Model.Dismisser != null);
|
||||
Debug.Assert(Model.DismissedAt != null);
|
||||
|
||||
<h3 class="ui red header">
|
||||
<h3 class="ui @color header">
|
||||
This case was dismissed by <a href="/user/@Model.Dismisser.UserId">@Model.Dismisser.Username</a> on @Model.DismissedAt.Value.ToString("MM/dd/yyyy @ h:mm tt").
|
||||
</h3>
|
||||
}
|
||||
else if (Model.Expired)
|
||||
{
|
||||
<h3 class="ui red header">
|
||||
<h3 class="ui @color header">
|
||||
This case expired on @Model.ExpiresAt!.Value.ToString("MM/dd/yyyy @ h:mm tt").
|
||||
</h3>
|
||||
}
|
||||
|
@ -59,8 +59,18 @@
|
|||
<b>No description was provided.</b>
|
||||
}
|
||||
|
||||
<a class="ui green small button" href="/moderation/case/@Model.CaseId/dismiss">
|
||||
<i class="checkmark icon"></i>
|
||||
<span>Dismiss</span>
|
||||
</a>
|
||||
@if (!Model.Dismissed)
|
||||
{
|
||||
<a class="ui green small button" href="/moderation/case/@Model.CaseId/dismiss">
|
||||
<i class="checkmark icon"></i>
|
||||
<span>Dismiss</span>
|
||||
</a>
|
||||
}
|
||||
else
|
||||
{
|
||||
<a class="ui yellow small button" href="/moderation/case/@Model.CaseId/undoDismiss">
|
||||
<i class="undo icon"></i>
|
||||
<span>Undo dismission</span> @* TODO: fix english here lol wtf is this *@
|
||||
</a>
|
||||
}
|
||||
</div>
|
|
@ -2,8 +2,10 @@ namespace LBPUnion.ProjectLighthouse.Administration;
|
|||
|
||||
public enum PermissionLevel
|
||||
{
|
||||
Banned = 0,
|
||||
Default = 1,
|
||||
Moderator = 2,
|
||||
Administrator = 3,
|
||||
Banned = -3,
|
||||
Restricted = -2,
|
||||
Silenced = -1,
|
||||
Default = 0,
|
||||
Moderator = 1,
|
||||
Administrator = 2,
|
||||
}
|
|
@ -137,6 +137,15 @@ public class User
|
|||
[JsonIgnore]
|
||||
public bool IsBanned => this.PermissionLevel == PermissionLevel.Banned;
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsRestricted => this.PermissionLevel == PermissionLevel.Restricted ||
|
||||
this.PermissionLevel == PermissionLevel.Banned;
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsSilenced => this.PermissionLevel == PermissionLevel.Silenced ||
|
||||
this.PermissionLevel == PermissionLevel.Restricted ||
|
||||
this.PermissionLevel == PermissionLevel.Banned;
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsModerator => this.PermissionLevel == PermissionLevel.Moderator ||
|
||||
this.PermissionLevel == PermissionLevel.Administrator;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue