-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Requires space-wizards/space-station-14#29365
- Loading branch information
Showing
9 changed files
with
483 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Content.Server.Database; | ||
|
||
namespace SS14.Admin.Helpers; | ||
|
||
public static class BanExemptions | ||
{ | ||
public static (ServerBanExemptFlags Value, string DisplayName)[] GetExemptions() | ||
{ | ||
return | ||
[ | ||
(ServerBanExemptFlags.Datacenter, "Datacenter"), | ||
(ServerBanExemptFlags.IP, "Only matches IP"), | ||
(ServerBanExemptFlags.BlacklistedRange, "Blacklisted range"), | ||
]; | ||
} | ||
|
||
public static ServerBanExemptFlags GetExemptionFromForm(IFormCollection formCollection) | ||
{ | ||
var flags = ServerBanExemptFlags.None; | ||
|
||
foreach (var (value, _) in GetExemptions()) | ||
{ | ||
if (formCollection.TryGetValue($"exemption_{value}", out var checkValue) && checkValue == "on") | ||
{ | ||
flags |= value; | ||
} | ||
} | ||
|
||
return flags; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Content.Shared.Database; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
|
||
namespace SS14.Admin.Helpers; | ||
|
||
public static class NoteSeverityHelper | ||
{ | ||
public static SelectListItem[] SeverityItems => | ||
[ | ||
new SelectListItem("None", NoteSeverity.None.ToString()), | ||
new SelectListItem("Minor", NoteSeverity.Minor.ToString()), | ||
new SelectListItem("Medium", NoteSeverity.Medium.ToString()), | ||
new SelectListItem("High", NoteSeverity.High.ToString()), | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@page | ||
@model SS14.Admin.Pages.Bans.BanTemplates.Create | ||
|
||
|
||
@{ | ||
ViewData["Title"] = "Create new ban template"; | ||
} | ||
|
||
<partial name="Shared/StatusMessageAlert" /> | ||
|
||
<form method="post" asp-page-handler="Create" class="container"> | ||
<h1>@ViewData["Title"]</h1> | ||
|
||
<div asp-validation-summary="All" class="text-danger"></div> | ||
|
||
<div class="form-group row"> | ||
<label asp-for="Title" class="col-sm-3 col-form-label">Title</label> | ||
<div class="col-sm-9"> | ||
<input asp-for="Title" class="form-control"> | ||
</div> | ||
</div> | ||
<input type="submit" value="Create" class="btn btn-primary"> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Content.Server.Database; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace SS14.Admin.Pages.Bans.BanTemplates; | ||
|
||
[Authorize(Roles = "BAN")] | ||
[ValidateAntiForgeryToken] | ||
public class Create(PostgresServerDbContext dbContext) : PageModel | ||
{ | ||
[BindProperty] public string Title { get; set; } = ""; | ||
|
||
public void OnGet() | ||
{ | ||
|
||
} | ||
|
||
public async Task<IActionResult> OnPostCreateAsync() | ||
{ | ||
if (string.IsNullOrWhiteSpace(Title)) | ||
{ | ||
TempData["StatusMessage"] = "Error: name must not be empty"; | ||
return Page(); | ||
} | ||
|
||
var template = new BanTemplate | ||
{ | ||
Title = Title, | ||
}; | ||
|
||
dbContext.BanTemplate.Add(template); | ||
|
||
await dbContext.SaveChangesAsync(); | ||
|
||
return RedirectToPage("View", new { id = template.Id }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
@page | ||
@using SS14.Admin.Helpers | ||
@model SS14.Admin.Pages.Bans.BanTemplates.View | ||
|
||
@{ | ||
ViewData["Title"] = $"Ban template: {Model.Template.Title}"; | ||
} | ||
|
||
<partial name="Shared/StatusMessageAlert" /> | ||
|
||
<form method="post" asp-page-handler="Edit" class="container"> | ||
<h1>@ViewData["Title"]</h1> | ||
|
||
<div asp-validation-summary="All" class="text-danger"></div> | ||
|
||
<div class="form-group row"> | ||
<label asp-for="Input.Title" class="col-sm-3 col-form-label">Name</label> | ||
<div class="col-sm-9"> | ||
<input asp-for="Input.Title" class="form-control"> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group row"> | ||
<label asp-for="Input.LengthMinutes" class="col-sm-3 col-form-label">Minutes (0: permanent)</label> | ||
<div class="col-sm-9"> | ||
<div class="row"> | ||
<div class="col-lg-6"> | ||
<input asp-for="Input.LengthMinutes" id="durationInput" class="form-control"> | ||
</div> | ||
<div class="col-lg-6"> | ||
<div class="row g-0"> | ||
<button data-duration="60" data-suffix="h" class="durationButton btn btn-secondary col"></button> | ||
<button data-duration="1440" data-suffix="d" class="durationButton btn btn-secondary col"></button> | ||
<button data-duration="10080" data-suffix="w" class="durationButton btn btn-secondary col"></button> | ||
<button data-duration="43200" data-suffix="M" class="durationButton btn btn-secondary col"></button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group row"> | ||
<label asp-for="Input.Reason" class="col-sm-3 col-form-label">Reason</label> | ||
<div class="col-sm-9"> | ||
<textarea asp-for="Input.Reason" class="form-control"></textarea> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group row"> | ||
<label asp-for="Input.Reason" class="col-sm-3 col-form-label">Severity</label> | ||
<div class="col-sm-9"> | ||
<select asp-for="Input.Severity" class="form-control" asp-items="@NoteSeverityHelper.SeverityItems"> | ||
</select> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group row"> | ||
<legend class="col-form-label col-sm-3 float-sm-left pt-0">Settings</legend> | ||
<div class="col-sm-9 mb-3"> | ||
<div class="form-check"> | ||
<input asp-for="Input.AutoDelete" class="form-check-input"/> | ||
<label asp-for="Input.AutoDelete" class="form-check-label"></label> | ||
</div> | ||
<div class="form-check"> | ||
<input asp-for="Input.Hidden" class="form-check-input"/> | ||
<label asp-for="Input.Hidden" class="form-check-label"></label> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group row"> | ||
<legend class="col-form-label col-sm-3 float-sm-left pt-0">Exemption flags</legend> | ||
<div class="col-sm-9 mb-3"> | ||
@foreach (var (value, display) in BanExemptions.GetExemptions()) | ||
{ | ||
<div class="form-check"> | ||
<input id="exemption_@value" name="exemption_@value" class="form-check-input" type="checkbox" checked="@((Model.Template.ExemptFlags & value) != 0)" /> | ||
<label for="exemption_@value" class="form-check-label">@display</label> | ||
</div> | ||
} | ||
</div> | ||
</div> | ||
|
||
<input type="submit" asp-route-id="@Model.Template.Id" asp-page-handler="Edit" value="Save" class="btn btn-primary"> | ||
</form> | ||
|
||
<partial name="Shared/BanTimeButtonScript" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Content.Server.Database; | ||
using Content.Shared.Database; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
using Microsoft.EntityFrameworkCore; | ||
using SS14.Admin.Helpers; | ||
|
||
namespace SS14.Admin.Pages.Bans.BanTemplates; | ||
|
||
[Authorize(Roles = "BAN")] | ||
[ValidateAntiForgeryToken] | ||
public class View(PostgresServerDbContext dbContext) : PageModel | ||
{ | ||
public BanTemplate Template = default!; | ||
|
||
[BindProperty] public InputModel Input { get; set; } = new(); | ||
|
||
public sealed class InputModel | ||
{ | ||
[Required] public string Title { get; set; } = ""; | ||
public int LengthMinutes { get; set; } | ||
public string? Reason { get; set; } | ||
|
||
[Display(Name = "Delete ban when expired")] | ||
public bool AutoDelete { get; set; } | ||
|
||
[Display(Name = "Hidden from player")] public bool Hidden { get; set; } | ||
public NoteSeverity Severity { get; set; } | ||
} | ||
|
||
public async Task<IActionResult> OnGetAsync(int id) | ||
{ | ||
var template = await dbContext.BanTemplate.SingleOrDefaultAsync(t => t.Id == id); | ||
if (template == null) | ||
return NotFound(); | ||
|
||
Input.Hidden = template.Hidden; | ||
Input.Severity = template.Severity; | ||
Input.Reason = template.Reason; | ||
Input.Title = template.Title; | ||
Input.LengthMinutes = (int)template.Length.TotalMinutes; | ||
Input.AutoDelete = template.AutoDelete; | ||
|
||
Template = template; | ||
return Page(); | ||
} | ||
|
||
public async Task<IActionResult> OnPostEditAsync(int id) | ||
{ | ||
if (!ModelState.IsValid) | ||
return RedirectToPage(new { id }); | ||
|
||
var template = await dbContext.BanTemplate.SingleOrDefaultAsync(t => t.Id == id); | ||
if (template == null) | ||
return NotFound(); | ||
|
||
if (string.IsNullOrWhiteSpace(Input.Title)) | ||
{ | ||
TempData["StatusMessage"] = "Error: title is empty"; | ||
return RedirectToPage(new { id }); | ||
} | ||
|
||
template.Title = Input.Title; | ||
template.Length = TimeSpan.FromMinutes(Input.LengthMinutes); | ||
template.Reason = Input.Reason ?? ""; | ||
template.AutoDelete = Input.AutoDelete; | ||
template.Hidden = Input.Hidden; | ||
template.Severity = Input.Severity; | ||
|
||
var flags = ServerBanExemptFlags.None; | ||
foreach (var (value, _) in BanExemptions.GetExemptions()) | ||
{ | ||
if (Request.Form.TryGetValue($"exemption_{value}", out var checkValue) && checkValue == "on") | ||
{ | ||
flags |= value; | ||
} | ||
} | ||
|
||
template.ExemptFlags = flags; | ||
|
||
await dbContext.SaveChangesAsync(); | ||
|
||
return RedirectToPage(new { id }); | ||
} | ||
} |
Oops, something went wrong.