2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Models;
|
|
|
|
|
using Umbraco.Cms.Core.Persistence.Querying;
|
2025-07-01 09:12:37 +02:00
|
|
|
using Umbraco.Cms.Core.Services.OperationStatus;
|
2015-01-19 15:12:34 +11:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
namespace Umbraco.Cms.Core.Services;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a service for handling audit.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public interface IAuditService : IService
|
2015-01-19 15:12:34 +11:00
|
|
|
{
|
2025-07-01 09:12:37 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adds an audit entry.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type">The type of the audit.</param>
|
|
|
|
|
/// <param name="userKey">The key of the user triggering the event.</param>
|
|
|
|
|
/// <param name="objectId">The identifier of the affected object.</param>
|
|
|
|
|
/// <param name="entityType">The entity type of the affected object.</param>
|
|
|
|
|
/// <param name="comment">The comment associated with the audit entry.</param>
|
|
|
|
|
/// <param name="parameters">The parameters associated with the audit entry.</param>
|
|
|
|
|
/// <returns>Result of the add audit log operation.</returns>
|
|
|
|
|
public Task<Attempt<AuditLogOperationStatus>> AddAsync(
|
|
|
|
|
AuditType type,
|
|
|
|
|
Guid userKey,
|
|
|
|
|
int objectId,
|
|
|
|
|
string? entityType,
|
|
|
|
|
string? comment = null,
|
|
|
|
|
string? parameters = null) => throw new NotImplementedException();
|
2021-02-18 11:06:02 +01:00
|
|
|
|
2025-07-01 09:12:37 +02:00
|
|
|
[Obsolete("Use AddAsync() instead. Scheduled for removal in Umbraco 19.")]
|
|
|
|
|
void Add(AuditType type, int userId, int objectId, string? entityType, string comment, string? parameters = null);
|
2018-03-22 17:41:13 +01:00
|
|
|
|
2025-07-01 09:12:37 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Returns paged items in the audit trail.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="skip">The number of audit trail entries to skip.</param>
|
|
|
|
|
/// <param name="take">The number of audit trail entries to take.</param>
|
|
|
|
|
/// <param name="orderDirection">
|
|
|
|
|
/// By default, this will always be ordered descending (newest first).
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="sinceDate">
|
|
|
|
|
/// If populated, will only return entries after this time.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="auditTypeFilter">
|
|
|
|
|
/// Since we currently do not have enum support with our expression parser, we cannot query on AuditType in the query
|
|
|
|
|
/// or the custom filter, so we need to do that here.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <returns>The paged audit logs.</returns>
|
|
|
|
|
public Task<PagedModel<IAuditItem>> GetItemsAsync(
|
|
|
|
|
int skip,
|
|
|
|
|
int take,
|
|
|
|
|
Direction orderDirection = Direction.Descending,
|
|
|
|
|
DateTimeOffset? sinceDate = null,
|
|
|
|
|
AuditType[]? auditTypeFilter = null) => throw new NotImplementedException();
|
2018-03-22 17:41:13 +01:00
|
|
|
|
2025-07-01 09:12:37 +02:00
|
|
|
[Obsolete("Use GetItemsAsync() instead. Scheduled for removal in Umbraco 19.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
IEnumerable<IAuditItem> GetLogs(AuditType type, DateTime? sinceDate = null);
|
2018-03-22 17:41:13 +01:00
|
|
|
|
2025-07-01 09:12:37 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Returns paged items in the audit trail for a given entity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="entityKey">The key of the entity.</param>
|
|
|
|
|
/// <param name="entityType">The entity type.</param>
|
|
|
|
|
/// <param name="skip">The number of audit trail entries to skip.</param>
|
|
|
|
|
/// <param name="take">The number of audit trail entries to take.</param>
|
|
|
|
|
/// <param name="orderDirection">
|
|
|
|
|
/// By default, this will always be ordered descending (newest first).
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="sinceDate">
|
|
|
|
|
/// If populated, will only return entries after this time.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="auditTypeFilter">
|
|
|
|
|
/// Since we currently do not have enum support with our expression parser, we cannot query on AuditType in the query
|
|
|
|
|
/// or the custom filter, so we need to do that here.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <returns>The paged items in the audit trail for the specified entity.</returns>
|
|
|
|
|
Task<PagedModel<IAuditItem>> GetItemsByKeyAsync(
|
|
|
|
|
Guid entityKey,
|
|
|
|
|
UmbracoObjectTypes entityType,
|
|
|
|
|
int skip,
|
|
|
|
|
int take,
|
|
|
|
|
Direction orderDirection = Direction.Descending,
|
|
|
|
|
DateTimeOffset? sinceDate = null,
|
|
|
|
|
AuditType[]? auditTypeFilter = null) => throw new NotImplementedException();
|
2022-06-07 15:28:38 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// Returns paged items in the audit trail for a given entity.
|
2022-06-07 15:28:38 +02:00
|
|
|
/// </summary>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// <param name="entityId">The identifier of the entity.</param>
|
|
|
|
|
/// <param name="skip">The number of audit trail entries to skip.</param>
|
|
|
|
|
/// <param name="take">The number of audit trail entries to take.</param>
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <param name="orderDirection">
|
2025-07-01 09:12:37 +02:00
|
|
|
/// By default, this will always be ordered descending (newest first).
|
2022-06-07 15:28:38 +02:00
|
|
|
/// </param>
|
|
|
|
|
/// <param name="auditTypeFilter">
|
|
|
|
|
/// Since we currently do not have enum support with our expression parser, we cannot query on AuditType in the query
|
2025-07-01 09:12:37 +02:00
|
|
|
/// or the custom filter, so we need to do that here.
|
2022-06-07 15:28:38 +02:00
|
|
|
/// </param>
|
|
|
|
|
/// <param name="customFilter">
|
2025-07-01 09:12:37 +02:00
|
|
|
/// Optional filter to be applied.
|
2022-06-07 15:28:38 +02:00
|
|
|
/// </param>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// <returns>The paged items in the audit trail for the specified entity.</returns>
|
|
|
|
|
public Task<PagedModel<IAuditItem>> GetItemsByEntityAsync(
|
2022-06-07 15:28:38 +02:00
|
|
|
int entityId,
|
2025-07-01 09:12:37 +02:00
|
|
|
int skip,
|
|
|
|
|
int take,
|
2022-06-07 15:28:38 +02:00
|
|
|
Direction orderDirection = Direction.Descending,
|
|
|
|
|
AuditType[]? auditTypeFilter = null,
|
2025-07-01 09:12:37 +02:00
|
|
|
IQuery<IAuditItem>? customFilter = null) => throw new NotImplementedException();
|
2021-02-18 11:06:02 +01:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// Returns paged items in the audit trail for a given entity.
|
2022-06-07 15:28:38 +02:00
|
|
|
/// </summary>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// <param name="entityId">The identifier of the entity.</param>
|
|
|
|
|
/// <param name="pageIndex">The index of tha page (pagination).</param>
|
|
|
|
|
/// <param name="pageSize">The number of results to return.</param>
|
|
|
|
|
/// <param name="totalRecords">The total number of records.</param>
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <param name="orderDirection">
|
2025-07-01 09:12:37 +02:00
|
|
|
/// By default, this will always be ordered descending (newest first).
|
2022-06-07 15:28:38 +02:00
|
|
|
/// </param>
|
|
|
|
|
/// <param name="auditTypeFilter">
|
|
|
|
|
/// Since we currently do not have enum support with our expression parser, we cannot query on AuditType in the query
|
2025-07-01 09:12:37 +02:00
|
|
|
/// or the custom filter, so we need to do that here.
|
2022-06-07 15:28:38 +02:00
|
|
|
/// </param>
|
|
|
|
|
/// <param name="customFilter">
|
2025-07-01 09:12:37 +02:00
|
|
|
/// Optional filter to be applied.
|
2022-06-07 15:28:38 +02:00
|
|
|
/// </param>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// <returns>The paged items in the audit trail for the specified entity.</returns>
|
|
|
|
|
[Obsolete("Use GetItemsByEntityAsync() instead. Scheduled for removal in Umbraco 19.")]
|
|
|
|
|
IEnumerable<IAuditItem> GetPagedItemsByEntity(
|
|
|
|
|
int entityId,
|
2022-06-07 15:28:38 +02:00
|
|
|
long pageIndex,
|
|
|
|
|
int pageSize,
|
|
|
|
|
out long totalRecords,
|
|
|
|
|
Direction orderDirection = Direction.Descending,
|
|
|
|
|
AuditType[]? auditTypeFilter = null,
|
|
|
|
|
IQuery<IAuditItem>? customFilter = null);
|
|
|
|
|
|
2025-07-01 09:12:37 +02:00
|
|
|
[Obsolete("Use GetItemsByEntityAsync() instead. Scheduled for removal in Umbraco 19.")]
|
|
|
|
|
IEnumerable<IAuditItem> GetLogs(int objectId);
|
|
|
|
|
|
2023-02-23 11:32:24 +01:00
|
|
|
/// <summary>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// Returns paged items in the audit trail for a given user.
|
2023-02-23 11:32:24 +01:00
|
|
|
/// </summary>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// <param name="userKey">The key of the user.</param>
|
|
|
|
|
/// <param name="skip">The number of audit trail entries to skip.</param>
|
|
|
|
|
/// <param name="take">The number of audit trail entries to take.</param>
|
2023-02-23 11:32:24 +01:00
|
|
|
/// <param name="orderDirection">
|
2025-07-01 09:12:37 +02:00
|
|
|
/// By default, this will always be ordered descending (newest first).
|
2023-02-23 11:32:24 +01:00
|
|
|
/// </param>
|
|
|
|
|
/// <param name="auditTypeFilter">
|
|
|
|
|
/// Since we currently do not have enum support with our expression parser, we cannot query on AuditType in the query
|
2025-07-01 09:12:37 +02:00
|
|
|
/// or the custom filter, so we need to do that here.
|
2023-02-23 11:32:24 +01:00
|
|
|
/// </param>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// <param name="sinceDate">The date to filter the audit entries.</param>
|
|
|
|
|
/// <returns>The paged items in the audit trail for the specified user.</returns>
|
|
|
|
|
Task<PagedModel<IAuditItem>> GetPagedItemsByUserAsync(
|
|
|
|
|
Guid userKey,
|
2023-02-23 11:32:24 +01:00
|
|
|
int skip,
|
|
|
|
|
int take,
|
|
|
|
|
Direction orderDirection = Direction.Descending,
|
2025-07-01 09:12:37 +02:00
|
|
|
AuditType[]? auditTypeFilter = null,
|
|
|
|
|
DateTime? sinceDate = null) => throw new NotImplementedException();
|
2023-02-23 11:32:24 +01:00
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// Returns paged items in the audit trail for a given user.
|
2023-02-23 11:32:24 +01:00
|
|
|
/// </summary>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// <param name="userId"></param>
|
|
|
|
|
/// <param name="pageIndex"></param>
|
|
|
|
|
/// <param name="pageSize"></param>
|
|
|
|
|
/// <param name="totalRecords"></param>
|
2023-02-23 11:32:24 +01:00
|
|
|
/// <param name="orderDirection">
|
2025-07-01 09:12:37 +02:00
|
|
|
/// By default this will always be ordered descending (newest first).
|
2023-02-23 11:32:24 +01:00
|
|
|
/// </param>
|
|
|
|
|
/// <param name="auditTypeFilter">
|
|
|
|
|
/// Since we currently do not have enum support with our expression parser, we cannot query on AuditType in the query
|
|
|
|
|
/// or the custom filter
|
2025-07-01 09:12:37 +02:00
|
|
|
/// so we need to do that here.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="customFilter">
|
|
|
|
|
/// Optional filter to be applied.
|
2023-02-23 11:32:24 +01:00
|
|
|
/// </param>
|
|
|
|
|
/// <returns></returns>
|
2025-07-01 09:12:37 +02:00
|
|
|
[Obsolete("Use GetPagedItemsByUserAsync() instead. Scheduled for removal in Umbraco 19.")]
|
|
|
|
|
IEnumerable<IAuditItem> GetPagedItemsByUser(
|
|
|
|
|
int userId,
|
|
|
|
|
long pageIndex,
|
|
|
|
|
int pageSize,
|
|
|
|
|
out long totalRecords,
|
2023-02-23 11:32:24 +01:00
|
|
|
Direction orderDirection = Direction.Descending,
|
|
|
|
|
AuditType[]? auditTypeFilter = null,
|
2025-07-01 09:12:37 +02:00
|
|
|
IQuery<IAuditItem>? customFilter = null);
|
|
|
|
|
|
|
|
|
|
[Obsolete("Use GetPagedItemsByUserAsync() instead. Scheduled for removal in Umbraco 19.")]
|
|
|
|
|
IEnumerable<IAuditItem> GetUserLogs(int userId, AuditType type, DateTime? sinceDate = null);
|
2023-02-23 11:32:24 +01:00
|
|
|
|
2022-06-07 15:28:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Writes an audit entry for an audited event.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="performingUserId">The identifier of the user triggering the audited event.</param>
|
|
|
|
|
/// <param name="perfomingDetails">Free-form details about the user triggering the audited event.</param>
|
|
|
|
|
/// <param name="performingIp">The IP address or the request triggering the audited event.</param>
|
|
|
|
|
/// <param name="eventDateUtc">The date and time of the audited event.</param>
|
|
|
|
|
/// <param name="affectedUserId">The identifier of the user affected by the audited event.</param>
|
|
|
|
|
/// <param name="affectedDetails">Free-form details about the entity affected by the audited event.</param>
|
|
|
|
|
/// <param name="eventType">
|
|
|
|
|
/// The type of the audited event - must contain only alphanumeric chars and hyphens with forward slashes separating
|
|
|
|
|
/// categories.
|
|
|
|
|
/// <example>
|
|
|
|
|
/// The eventType will generally be formatted like: {application}/{entity-type}/{category}/{sub-category}
|
|
|
|
|
/// Example: umbraco/user/sign-in/failed
|
|
|
|
|
/// </example>
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="eventDetails">Free-form details about the audited event.</param>
|
2025-07-01 09:12:37 +02:00
|
|
|
/// <returns>The created audit entry.</returns>
|
|
|
|
|
[Obsolete("Use IAuditEntryService.WriteAsync() instead. Scheduled for removal in Umbraco 19.")]
|
2022-06-07 15:28:38 +02:00
|
|
|
IAuditEntry Write(
|
|
|
|
|
int performingUserId,
|
|
|
|
|
string perfomingDetails,
|
|
|
|
|
string performingIp,
|
|
|
|
|
DateTime eventDateUtc,
|
|
|
|
|
int affectedUserId,
|
|
|
|
|
string affectedDetails,
|
|
|
|
|
string eventType,
|
|
|
|
|
string eventDetails);
|
2025-07-01 09:12:37 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Cleans the audit logs older than the specified maximum age.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="maximumAgeOfLogsInMinutes">The maximum age of logs in minutes.</param>
|
|
|
|
|
/// <returns>Task representing the asynchronous operation.</returns>
|
|
|
|
|
public Task CleanLogsAsync(int maximumAgeOfLogsInMinutes) => throw new NotImplementedException();
|
|
|
|
|
|
|
|
|
|
[Obsolete("Use CleanLogsAsync() instead. Scheduled for removal in Umbraco 19.")]
|
|
|
|
|
void CleanLogs(int maximumAgeOfLogsInMinutes);
|
2017-07-20 11:21:28 +02:00
|
|
|
}
|