mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-14 19:29:53 +01:00
Ban database refactor (#42495) * Ban DB refactor seems to work at a basic level for PostgreSQL * New ban creation API Supports all the new functionality (multiple players/addresses/hwids/roles/rounds per ban). * Make the migration irreversible * Re-implement ban notifications The server ID check is no longer done as admins may want to place bans spanning multiple rounds irrelevant of the source server. * Fix some split query warnings * Implement migration on SQLite * More comments * Remove required from ban reason SS14.Admin changes would like this * More missing AsSplitQuery() calls * Fix missing ban type filter * Fix old CreateServerBan API with permanent time * Fix department and role ban commands with permanent time * Re-add banhits navigation property Dropped this on accident, SS14.Admin needs it. * More ban API fixes. * Don't fetch ban exemption info for role bans Not relevant, reduces query performance * Regenerate migrations * Fix adminnotes command for players that never connected Would blow up handling null player records. Not a new bug introduced by the refactor, but I ran into it. * Great shame... I accidentally committed submodule update... * Update GDPR scripts * Fix sandbox violation * Fix bans with duplicate info causing DB exceptions Most notably happened with role bans, as multiple departments may include the same role.
125 lines
3.6 KiB
C#
125 lines
3.6 KiB
C#
using System.Collections.Immutable;
|
|
using System.Net;
|
|
using Content.Shared.Database;
|
|
using Robust.Shared.Network;
|
|
|
|
namespace Content.Server.Database;
|
|
|
|
// This file contains copies of records returned from the database.
|
|
// We can't return the raw EF Core entities as they are often unsuited.
|
|
// (e.g. datetime handling of Microsoft.Data.Sqlite)
|
|
|
|
public interface IAdminRemarksRecord
|
|
{
|
|
public int Id { get; }
|
|
|
|
public ImmutableArray<RoundRecord> Rounds { get; }
|
|
|
|
public ImmutableArray<PlayerRecord> Players { get; }
|
|
public TimeSpan PlaytimeAtNote { get; }
|
|
|
|
public string Message { get; }
|
|
|
|
public PlayerRecord? CreatedBy { get; }
|
|
|
|
public DateTimeOffset CreatedAt { get; }
|
|
|
|
public PlayerRecord? LastEditedBy { get; }
|
|
|
|
public DateTimeOffset? LastEditedAt { get; }
|
|
public DateTimeOffset? ExpirationTime { get; }
|
|
|
|
public bool Deleted { get; }
|
|
}
|
|
|
|
public sealed record BanNoteRecord(
|
|
int Id,
|
|
BanType Type,
|
|
ImmutableArray<RoundRecord> Rounds,
|
|
ImmutableArray<PlayerRecord> Players,
|
|
TimeSpan PlaytimeAtNote,
|
|
string Message,
|
|
NoteSeverity Severity,
|
|
PlayerRecord? CreatedBy,
|
|
DateTimeOffset CreatedAt,
|
|
PlayerRecord? LastEditedBy,
|
|
DateTimeOffset? LastEditedAt,
|
|
DateTimeOffset? ExpirationTime,
|
|
bool Deleted,
|
|
PlayerRecord? UnbanningAdmin,
|
|
DateTime? UnbanTime,
|
|
ImmutableArray<BanRoleDef> Roles) : IAdminRemarksRecord;
|
|
|
|
public sealed record AdminNoteRecord(
|
|
int Id,
|
|
RoundRecord? Round,
|
|
PlayerRecord? Player,
|
|
TimeSpan PlaytimeAtNote,
|
|
string Message,
|
|
NoteSeverity Severity,
|
|
PlayerRecord? CreatedBy,
|
|
DateTimeOffset CreatedAt,
|
|
PlayerRecord? LastEditedBy,
|
|
DateTimeOffset? LastEditedAt,
|
|
DateTimeOffset? ExpirationTime,
|
|
bool Deleted,
|
|
PlayerRecord? DeletedBy,
|
|
DateTimeOffset? DeletedAt,
|
|
bool Secret) : IAdminRemarksRecord
|
|
{
|
|
ImmutableArray<RoundRecord> IAdminRemarksRecord.Rounds => Round != null ? [Round] : [];
|
|
ImmutableArray<PlayerRecord> IAdminRemarksRecord.Players => Player != null ? [Player] : [];
|
|
}
|
|
|
|
public sealed record AdminWatchlistRecord(
|
|
int Id,
|
|
RoundRecord? Round,
|
|
PlayerRecord? Player,
|
|
TimeSpan PlaytimeAtNote,
|
|
string Message,
|
|
PlayerRecord? CreatedBy,
|
|
DateTimeOffset CreatedAt,
|
|
PlayerRecord? LastEditedBy,
|
|
DateTimeOffset? LastEditedAt,
|
|
DateTimeOffset? ExpirationTime,
|
|
bool Deleted,
|
|
PlayerRecord? DeletedBy,
|
|
DateTimeOffset? DeletedAt) : IAdminRemarksRecord
|
|
{
|
|
ImmutableArray<RoundRecord> IAdminRemarksRecord.Rounds => Round != null ? [Round] : [];
|
|
ImmutableArray<PlayerRecord> IAdminRemarksRecord.Players => Player != null ? [Player] : [];
|
|
}
|
|
|
|
public sealed record AdminMessageRecord(
|
|
int Id,
|
|
RoundRecord? Round,
|
|
PlayerRecord? Player,
|
|
TimeSpan PlaytimeAtNote,
|
|
string Message,
|
|
PlayerRecord? CreatedBy,
|
|
DateTimeOffset CreatedAt,
|
|
PlayerRecord? LastEditedBy,
|
|
DateTimeOffset? LastEditedAt,
|
|
DateTimeOffset? ExpirationTime,
|
|
bool Deleted,
|
|
PlayerRecord? DeletedBy,
|
|
DateTimeOffset? DeletedAt,
|
|
bool Seen,
|
|
bool Dismissed) : IAdminRemarksRecord
|
|
{
|
|
ImmutableArray<RoundRecord> IAdminRemarksRecord.Rounds => Round != null ? [Round] : [];
|
|
ImmutableArray<PlayerRecord> IAdminRemarksRecord.Players => Player != null ? [Player] : [];
|
|
}
|
|
|
|
public sealed record PlayerRecord(
|
|
NetUserId UserId,
|
|
DateTimeOffset FirstSeenTime,
|
|
string LastSeenUserName,
|
|
DateTimeOffset LastSeenTime,
|
|
IPAddress? LastSeenAddress,
|
|
ImmutableTypedHwid? HWId);
|
|
|
|
public sealed record RoundRecord(int Id, DateTimeOffset? StartDate, ServerRecord Server);
|
|
|
|
public sealed record ServerRecord(int Id, string Name);
|