Adds even more important Admin Logging (#10268)
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Access.Systems;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Database;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
namespace Content.Server.Access.Components
|
||||
@@ -12,6 +15,7 @@ namespace Content.Server.Access.Components
|
||||
public sealed class IdCardConsoleComponent : SharedIdCardConsoleComponent
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(IdCardConsoleUiKey.Key);
|
||||
|
||||
@@ -26,6 +30,7 @@ namespace Content.Server.Access.Components
|
||||
{
|
||||
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
||||
@@ -38,7 +43,7 @@ namespace Content.Server.Access.Components
|
||||
switch (obj.Message)
|
||||
{
|
||||
case WriteToTargetIdMessage msg:
|
||||
TryWriteToTargetId(msg.FullName, msg.JobTitle, msg.AccessList);
|
||||
TryWriteToTargetId(msg.FullName, msg.JobTitle, msg.AccessList, player);
|
||||
UpdateUserInterface();
|
||||
break;
|
||||
}
|
||||
@@ -60,17 +65,17 @@ namespace Content.Server.Access.Components
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the "Submit" button in the UI gets pressed.
|
||||
/// Called whenever an access button is pressed, adding or removing that access from the target ID card.
|
||||
/// Writes data passed from the UI into the ID stored in <see cref="TargetIdSlot"/>, if present.
|
||||
/// </summary>
|
||||
private void TryWriteToTargetId(string newFullName, string newJobTitle, List<string> newAccessList)
|
||||
private void TryWriteToTargetId(string newFullName, string newJobTitle, List<string> newAccessList, EntityUid player)
|
||||
{
|
||||
if (TargetIdSlot.Item is not {Valid: true} targetIdEntity || !PrivilegedIdIsAuthorized())
|
||||
return;
|
||||
|
||||
var cardSystem = EntitySystem.Get<IdCardSystem>();
|
||||
cardSystem.TryChangeFullName(targetIdEntity, newFullName);
|
||||
cardSystem.TryChangeJobTitle(targetIdEntity, newJobTitle);
|
||||
cardSystem.TryChangeFullName(targetIdEntity, newFullName, player: player);
|
||||
cardSystem.TryChangeJobTitle(targetIdEntity, newJobTitle, player: player);
|
||||
|
||||
if (!newAccessList.TrueForAll(x => AccessLevels.Contains(x)))
|
||||
{
|
||||
@@ -80,6 +85,12 @@ namespace Content.Server.Access.Components
|
||||
|
||||
var accessSystem = EntitySystem.Get<AccessSystem>();
|
||||
accessSystem.TrySetTags(targetIdEntity, newAccessList);
|
||||
|
||||
/*TODO: ECS IdCardConsoleComponent and then log on card ejection, together with the save.
|
||||
This current implementation is pretty shit as it logs 27 entries (27 lines) if someone decides to give themselves AA*/
|
||||
_adminLogger.Add(LogType.Action, LogImpact.Medium,
|
||||
$"{_entities.ToPrettyString(player):player} has modified {_entities.ToPrettyString(targetIdEntity):entity} with the following accesses: [{string.Join(", ", newAccessList)}]");
|
||||
|
||||
}
|
||||
|
||||
public void UpdateUserInterface()
|
||||
|
||||
@@ -2,11 +2,13 @@ using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Inventory;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Kitchen.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Access;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.PDA;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Player;
|
||||
@@ -21,6 +23,7 @@ namespace Content.Server.Access.Systems
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -73,22 +76,39 @@ namespace Content.Server.Access.Systems
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryChangeJobTitle(EntityUid uid, string jobTitle, IdCardComponent? id = null)
|
||||
/// <summary>
|
||||
/// Attempts to change the job title of a card.
|
||||
/// Returns true/false.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If provided with a player's EntityUid to the player parameter, adds the change to the admin logs.
|
||||
/// </remarks>
|
||||
public bool TryChangeJobTitle(EntityUid uid, string jobTitle, IdCardComponent? id = null, EntityUid? player = null)
|
||||
{
|
||||
if (!Resolve(uid, ref id))
|
||||
return false;
|
||||
|
||||
// TODO: Whenever we get admin logging these should be logged
|
||||
if (jobTitle.Length > SharedIdCardConsoleComponent.MaxJobTitleLength)
|
||||
jobTitle = jobTitle[..SharedIdCardConsoleComponent.MaxJobTitleLength];
|
||||
|
||||
id.JobTitle = jobTitle;
|
||||
Dirty(id);
|
||||
UpdateEntityName(uid, id);
|
||||
|
||||
if (player != null)
|
||||
_adminLogger.Add(LogType.Identity, LogImpact.Low,
|
||||
$"{ToPrettyString(player.Value):player} has changed the job title of {ToPrettyString(id.Owner):entity} to {jobTitle} ");
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryChangeFullName(EntityUid uid, string fullName, IdCardComponent? id = null)
|
||||
/// <summary>
|
||||
/// Attempts to change the full name of a card.
|
||||
/// Returns true/false.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If provided with a player's EntityUid to the player parameter, adds the change to the admin logs.
|
||||
/// </remarks>
|
||||
public bool TryChangeFullName(EntityUid uid, string fullName, IdCardComponent? id = null, EntityUid? player = null)
|
||||
{
|
||||
if (!Resolve(uid, ref id))
|
||||
return false;
|
||||
@@ -99,6 +119,10 @@ namespace Content.Server.Access.Systems
|
||||
id.FullName = fullName;
|
||||
Dirty(id);
|
||||
UpdateEntityName(uid, id);
|
||||
|
||||
if (player != null)
|
||||
_adminLogger.Add(LogType.Identity, LogImpact.Low,
|
||||
$"{ToPrettyString(player.Value):player} has changed the name of {ToPrettyString(id.Owner):entity} to {fullName} ");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user