Skip to content

Database Auditing #1

@ktwrd

Description

@ktwrd

Implementing an Audit Trail for user actions in the database would be a smart idea, especially for when Cockatoo (maybe) goes open-source and when more than just intcoms and myself have access to the dashboard.

Similar database models should be created for events that occour, like the Bullseye cache being refresh for an application, or a user creating a service account.

Proposed database model for Document audit events
public class DocumentAuditModel : BaseGuidModel
{
    public const string CollectionName = "audit_log;

    [JsonIgnore]
    public BsonTimestamp Timestamp { get; set; }
    [BsonIgnore]
    [JsonPropertyName(nameof(Timestamp))]
    public long TimestampJson => Timestamp.Value;

    public DocumentAuditActionKind Action { get; set; }

    /// <summary>
    /// Foreign Key to <see cref="UserModel.Id"/>
    /// </summary>
    public string UserId { get; set; }
    /// <summary>
    /// Foreign Key to <see cref="UserSessionModel.Id"/>
    /// </summary>
    public string UserSessionId { get; set; }
    /// <summary>
    /// Name of the Collection that had an event happen on it.
    /// </summary>
    public string CollectionName { get; set; }
    /// <summary>
    /// <see cref="Type.ToString()"/> of the document.
    /// </summary>
    public string DocumentType { get; set; }
    /// <summary>
    /// JSON of the document before the action was done.
    /// </summary>
    /// <remarks>
    /// This will be <see langword="null"/> when <see cref="Action"/> is <see cref="DocumentAuditActionKind.Insert"/>
    /// </remarks>
    public string? BeforeJson { get; set; }
    /// <summary>
    /// JSON of the document after the action was done.
    /// </summary>
    /// <remarks>
    /// This will be <see langword="null"/> when <see cref="Action"/> is <see cref="DocumentAuditActionKind.Delete"/>
    /// </remarks>
    public string? AfterJson { get; set; }
}

public enum DocumentAuditActionKind
{
    /// <summary>
    /// New document was inserted. <see cref="DocumentAuditModel.BeforeJson"/> will always be null.
    /// </summary>
    Insert,
    Update,
    Delete
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions