mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-17 23:22:27 +00:00
Add case generator for bans, allow mods to ban
This commit is contained in:
parent
1eede416d4
commit
cdcc03fdc1
8 changed files with 85 additions and 47 deletions
|
@ -24,7 +24,7 @@ public class AdminUserController : ControllerBase
|
|||
public async Task<IActionResult> UnbanUser([FromRoute] int id)
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.NotFound();
|
||||
if (user == null || !user.IsModerator) return this.NotFound();
|
||||
|
||||
User? targetedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
||||
if (targetedUser == null) return this.NotFound();
|
||||
|
@ -42,7 +42,7 @@ public class AdminUserController : ControllerBase
|
|||
[HttpGet("wipePlanets")]
|
||||
public async Task<IActionResult> WipePlanets([FromRoute] int id) {
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.NotFound();
|
||||
if (user == null || !user.IsModerator) return this.NotFound();
|
||||
|
||||
User? targetedUser = await this.database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
||||
if (targetedUser == null) return this.NotFound();
|
||||
|
@ -118,7 +118,7 @@ public class AdminUserController : ControllerBase
|
|||
}
|
||||
else
|
||||
{
|
||||
return this.Redirect($"/admin/user/{id}/ban");
|
||||
return this.Redirect($"/moderation/user/{id}/ban");
|
||||
}
|
||||
|
||||
return this.Redirect("/admin/users");
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
@page "/admin/user/{id:int}/ban"
|
||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin.AdminBanUserPage
|
||||
|
||||
@{
|
||||
Layout = "Layouts/BaseLayout";
|
||||
Model.Title = "Ban " + Model.TargetedUser!.Username + "?";
|
||||
}
|
||||
|
||||
<p>Are you sure you want to ban this user?</p>
|
||||
|
||||
<form method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<div class="ui left labeled input">
|
||||
<label for="text" class="ui blue label">Reason: </label>
|
||||
<input type="text" name="reason" id="text">
|
||||
</div><br><br>
|
||||
|
||||
<input type="submit" value="Yes, ban @Model.TargetedUser.Username!" id="submit" class="ui red button"><br>
|
||||
</form>
|
|
@ -0,0 +1,25 @@
|
|||
@page "/moderation/user/{id:int}/ban"
|
||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin.ModeratorBanUserPage
|
||||
|
||||
@{
|
||||
Layout = "Layouts/BaseLayout";
|
||||
Model.Title = "Ban " + Model.TargetedUser!.Username + "?";
|
||||
}
|
||||
|
||||
<p>Are you sure you want to ban this user?</p>
|
||||
|
||||
<form method="post">
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<div class="ui left labeled input">
|
||||
<label for="text" class="ui blue label">Reason: </label>
|
||||
<input type="text" name="reason" id="text">
|
||||
</div><br>
|
||||
|
||||
<div class="ui left labeled input">
|
||||
<label for="caseExpires" class="ui blue label">Expires on: </label>
|
||||
<input type="datetime-local" name="caseExpires" id="caseExpires">
|
||||
</div><br>
|
||||
|
||||
<br><input type="submit" value="Yes, ban @Model.TargetedUser.Username!" id="submit" class="ui red button"><br>
|
||||
</form>
|
|
@ -8,17 +8,17 @@ using Microsoft.EntityFrameworkCore;
|
|||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Admin;
|
||||
|
||||
public class AdminBanUserPage : BaseLayout
|
||||
public class ModeratorBanUserPage : BaseLayout
|
||||
{
|
||||
|
||||
public User? TargetedUser;
|
||||
public AdminBanUserPage(Database database) : base(database)
|
||||
public ModeratorBanUserPage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public async Task<IActionResult> OnGet([FromRoute] int id)
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.NotFound();
|
||||
if (user == null || !user.IsModerator) return this.NotFound();
|
||||
|
||||
this.TargetedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
||||
if (this.TargetedUser == null) return this.NotFound();
|
||||
|
@ -26,10 +26,10 @@ public class AdminBanUserPage : BaseLayout
|
|||
return this.Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPost([FromRoute] int id, string reason)
|
||||
public async Task<IActionResult> OnPost([FromRoute] int id, string reason, DateTime caseExpires)
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsAdmin) return this.NotFound();
|
||||
if (user == null || !user.IsModerator) return this.NotFound();
|
||||
|
||||
this.TargetedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
||||
if (this.TargetedUser == null) return this.NotFound();
|
||||
|
@ -43,6 +43,9 @@ public class AdminBanUserPage : BaseLayout
|
|||
// invalidate all currently active webtokens
|
||||
this.Database.WebTokens.RemoveRange(this.Database.WebTokens.Where(t => t.UserId == this.TargetedUser.UserId));
|
||||
|
||||
// generate & add moderation case
|
||||
this.Database.Add(ModerationCase.NewBanCase(user.UserId, this.TargetedUser.UserId, reason, caseExpires));
|
||||
|
||||
await this.Database.SaveChangesAsync();
|
||||
return this.Redirect($"/user/{this.TargetedUser.UserId}");
|
||||
}
|
|
@ -126,7 +126,7 @@
|
|||
@if (!Model.ProfileUser.IsBanned)
|
||||
{
|
||||
<div>
|
||||
<a class="ui red button" href="/admin/user/@Model.ProfileUser.UserId/ban">
|
||||
<a class="ui red button" href="/moderation/user/@Model.ProfileUser.UserId/ban">
|
||||
<i class="ban icon"></i>
|
||||
<span>Ban User</span>
|
||||
</a>
|
||||
|
|
|
@ -36,10 +36,10 @@ public static class CaseTypeExtensions
|
|||
{
|
||||
return type switch
|
||||
{
|
||||
CaseType.UserDeletion => false, // you cant get a user from a deleted id
|
||||
CaseType.UserSilence => true,
|
||||
CaseType.UserRestriction => true,
|
||||
CaseType.UserBan => true,
|
||||
CaseType.UserDeletion => true,
|
||||
CaseType.UserCommentsDisabled => true,
|
||||
CaseType.UserDetailsEdited => true,
|
||||
CaseType.UserEarthDeletion => true,
|
||||
|
@ -51,7 +51,7 @@ public static class CaseTypeExtensions
|
|||
{
|
||||
return type switch
|
||||
{
|
||||
CaseType.LevelDeletion => true,
|
||||
CaseType.LevelDeletion => false, // you cant get a slot from a deleted id
|
||||
CaseType.LevelLock => true,
|
||||
CaseType.LevelCommentsDisabled => true,
|
||||
CaseType.LevelDetailsEdited => true,
|
||||
|
|
|
@ -67,14 +67,6 @@ public class SetUserModeratorCommand : SetUserPermissionLevelCommand
|
|||
public override string[] Aliases() => new[] { "make-moderator", };
|
||||
}
|
||||
|
||||
public class BanUserCommand : SetUserPermissionLevelCommand
|
||||
{
|
||||
public BanUserCommand() : base(PermissionLevel.Banned)
|
||||
{}
|
||||
public override string Name() => "Ban User";
|
||||
public override string[] Aliases() => new[] { "ban", };
|
||||
}
|
||||
|
||||
public class DemoteUserCommand : SetUserPermissionLevelCommand
|
||||
{
|
||||
public DemoteUserCommand() : base(PermissionLevel.Default)
|
||||
|
|
|
@ -45,7 +45,10 @@ public class ModerationCase
|
|||
}
|
||||
#endregion
|
||||
|
||||
public static ModerationCase NewTeamPickCase(int caseCreator, int slotId, bool added) => new()
|
||||
#region Case creators
|
||||
#region Level
|
||||
public static ModerationCase NewTeamPickCase(int caseCreator, int slotId, bool added)
|
||||
=> new()
|
||||
{
|
||||
CaseType = added ? CaseType.LevelTeamPickAdded : CaseType.LevelTeamPickRemoved,
|
||||
CaseDescription = "",
|
||||
|
@ -53,4 +56,39 @@ public class ModerationCase
|
|||
CaseCreated = DateTime.Now,
|
||||
AffectedId = slotId,
|
||||
};
|
||||
|
||||
public static ModerationCase NewLevelDeletionCase(int caseCreator, int slotId)
|
||||
=> new()
|
||||
{
|
||||
CaseType = CaseType.LevelDeletion,
|
||||
CaseDescription = "Deleted slot ID " + slotId,
|
||||
CaseCreatorId = caseCreator,
|
||||
CaseCreated = DateTime.Now,
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region User
|
||||
public static ModerationCase NewBanCase(int caseCreator, int userId, string reason, DateTime caseExpires)
|
||||
=> new()
|
||||
{
|
||||
CaseType = CaseType.UserBan,
|
||||
CaseDescription = $"Banned for reason '{reason}'",
|
||||
CaseCreatorId = caseCreator,
|
||||
CaseCreated = DateTime.Now,
|
||||
CaseExpires = caseExpires,
|
||||
AffectedId = userId,
|
||||
};
|
||||
|
||||
public static ModerationCase NewAccountDeletionCase(int caseCreator, int userId)
|
||||
=> new()
|
||||
{
|
||||
CaseType = CaseType.UserDeletion,
|
||||
CaseDescription = "Deleted user ID " + userId,
|
||||
CaseCreatorId = caseCreator,
|
||||
CaseCreated = DateTime.Now,
|
||||
};
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue