Better notes and bans (#14228)

Co-authored-by: Chief-Engineer <119664036+Chief-Engineer@users.noreply.github.com>
This commit is contained in:
Riggle
2023-07-21 13:38:52 +02:00
committed by GitHub
parent c6cb6ad928
commit 579913b617
84 changed files with 9820 additions and 886 deletions

View File

@@ -1,21 +1,75 @@
using Content.Server.Database;
using System.Diagnostics;
using Content.Server.Database;
using Content.Shared.Administration.Notes;
using Content.Shared.Database;
namespace Content.Server.Administration.Notes;
public static class AdminNotesExtensions
{
public static SharedAdminNote ToShared(this AdminNote note)
public static SharedAdminNote ToShared(this IAdminRemarksCommon note)
{
NoteSeverity? severity = null;
var secret = false;
NoteType type;
string[]? bannedRoles = null;
string? unbannedByName = null;
DateTime? unbannedTime = null;
bool? seen = null;
switch (note)
{
case AdminNote adminNote:
type = NoteType.Note;
severity = adminNote.Severity;
secret = adminNote.Secret;
break;
case AdminWatchlist:
type = NoteType.Watchlist;
secret = true;
break;
case AdminMessage adminMessage:
type = NoteType.Message;
seen = adminMessage.Seen;
break;
case ServerBanNote ban:
type = NoteType.ServerBan;
severity = ban.Severity;
unbannedTime = ban.UnbanTime;
unbannedByName = ban.UnbanningAdmin?.LastSeenUserName ?? Loc.GetString("system-user");
break;
case ServerRoleBanNote roleBan:
type = NoteType.RoleBan;
severity = roleBan.Severity;
bannedRoles = roleBan.Roles;
unbannedTime = roleBan.UnbanTime;
unbannedByName = roleBan.UnbanningAdmin?.LastSeenUserName ?? Loc.GetString("system-user");
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), note.GetType(), "Unknown note type");
}
// There may be bans without a user, but why would we ever be converting them to shared notes?
if (note.PlayerUserId is null)
throw new ArgumentNullException(nameof(note.PlayerUserId), "Player user ID cannot be null for a note");
return new SharedAdminNote(
note.Id,
note.PlayerUserId.Value,
note.RoundId,
note.PlayerUserId,
note.Round?.Server.Name,
note.PlaytimeAtNote,
type,
note.Message,
note.CreatedBy.LastSeenUserName,
note.LastEditedBy.LastSeenUserName,
severity,
secret,
note.CreatedBy?.LastSeenUserName ?? Loc.GetString("system-user"),
note.LastEditedBy?.LastSeenUserName ?? string.Empty,
note.CreatedAt,
note.LastEditedAt
note.LastEditedAt,
note.ExpirationTime,
bannedRoles,
unbannedTime,
unbannedByName,
seen
);
}
}