Management api should use datetimeoffset (#16196)
* Move audit log endpoints to their respective silos and clean up * Fix failing integration tests * Using DateTimeOffset in management api and new methods in service layer --------- Co-authored-by: kjac <kja@umbraco.dk>
This commit is contained in:
@@ -35,7 +35,7 @@ public class GetAuditLogDocumentController : DocumentControllerBase
|
||||
[MapToApiVersion("1.0")]
|
||||
[HttpGet("{id:guid}/audit-log")]
|
||||
[ProducesResponseType(typeof(PagedViewModel<AuditLogResponseModel>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTime? sinceDate = null, int skip = 0, int take = 100)
|
||||
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTimeOffset? sinceDate = null, int skip = 0, int take = 100)
|
||||
{
|
||||
AuthorizationResult authorizationResult = await _authorizationService.AuthorizeResourceAsync(
|
||||
User,
|
||||
|
||||
@@ -48,8 +48,8 @@ public class AllLogViewerController : LogViewerControllerBase
|
||||
Direction orderDirection = Direction.Descending,
|
||||
string? filterExpression = null,
|
||||
[FromQuery(Name = "logLevel")] LogLevel[]? logLevels = null,
|
||||
DateTime? startDate = null,
|
||||
DateTime? endDate = null)
|
||||
DateTimeOffset? startDate = null,
|
||||
DateTimeOffset? endDate = null)
|
||||
{
|
||||
var levels = logLevels?.Select(l => l.ToString()).ToArray();
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@ public class AllMessageTemplateLogViewerController : LogViewerControllerBase
|
||||
CancellationToken cancellationToken,
|
||||
int skip = 0,
|
||||
int take = 100,
|
||||
DateTime? startDate = null,
|
||||
DateTime? endDate = null)
|
||||
DateTimeOffset? startDate = null,
|
||||
DateTimeOffset? endDate = null)
|
||||
{
|
||||
Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus> messageTemplatesAttempt = await _logViewerService.GetMessageTemplatesAsync(startDate, endDate, skip, take);
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ public class LogLevelCountLogViewerController : LogViewerControllerBase
|
||||
[ProducesResponseType(typeof(LogLevelCountsReponseModel), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> LogLevelCounts(
|
||||
CancellationToken cancellationToken,
|
||||
DateTime? startDate = null,
|
||||
DateTime? endDate = null)
|
||||
DateTimeOffset? startDate = null,
|
||||
DateTimeOffset? endDate = null)
|
||||
{
|
||||
Attempt<LogLevelCounts?, LogViewerOperationStatus> logLevelCountsAttempt =
|
||||
await _logViewerService.GetLogLevelCountsAsync(startDate, endDate);
|
||||
|
||||
@@ -26,8 +26,8 @@ public class ValidateLogFileSizeLogViewerController : LogViewerControllerBase
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> CanViewLogs(
|
||||
CancellationToken cancellationToken,
|
||||
DateTime? startDate = null,
|
||||
DateTime? endDate = null)
|
||||
DateTimeOffset? startDate = null,
|
||||
DateTimeOffset? endDate = null)
|
||||
{
|
||||
Attempt<bool, LogViewerOperationStatus> result = await _logViewerService.CanViewLogsAsync(startDate, endDate);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class GetAuditLogMediaController : MediaControllerBase
|
||||
[MapToApiVersion("1.0")]
|
||||
[HttpGet("{id:guid}/audit-log")]
|
||||
[ProducesResponseType(typeof(PagedViewModel<AuditLogResponseModel>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTime? sinceDate = null, int skip = 0, int take = 100)
|
||||
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTimeOffset? sinceDate = null, int skip = 0, int take = 100)
|
||||
{
|
||||
AuthorizationResult authorizationResult = await _authorizationService.AuthorizeResourceAsync(
|
||||
User,
|
||||
|
||||
@@ -19,11 +19,11 @@ public class MemberResponseModel : ContentResponseModelBase<MemberValueModel, Me
|
||||
|
||||
public int FailedPasswordAttempts { get; set; }
|
||||
|
||||
public DateTime? LastLoginDate { get; set; }
|
||||
public DateTimeOffset? LastLoginDate { get; set; }
|
||||
|
||||
public DateTime? LastLockoutDate { get; set; }
|
||||
public DateTimeOffset? LastLockoutDate { get; set; }
|
||||
|
||||
public DateTime? LastPasswordChangeDate { get; set; }
|
||||
public DateTimeOffset? LastPasswordChangeDate { get; set; }
|
||||
|
||||
public IEnumerable<Guid> Groups { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ public sealed class AuditService : RepositoryService, IAuditService
|
||||
int skip,
|
||||
int take,
|
||||
Direction orderDirection = Direction.Descending,
|
||||
DateTime? sinceDate = null,
|
||||
DateTimeOffset? sinceDate = null,
|
||||
AuditType[]? auditTypeFilter = null)
|
||||
{
|
||||
if (skip < 0)
|
||||
@@ -264,7 +264,7 @@ public sealed class AuditService : RepositoryService, IAuditService
|
||||
using (ScopeProvider.CreateCoreScope(autoComplete: true))
|
||||
{
|
||||
IQuery<IAuditItem> query = Query<IAuditItem>().Where(x => x.Id == keyToIdAttempt.Result);
|
||||
IQuery<IAuditItem>? customFilter = sinceDate.HasValue ? Query<IAuditItem>().Where(x => x.CreateDate >= sinceDate) : null;
|
||||
IQuery<IAuditItem>? customFilter = sinceDate.HasValue ? Query<IAuditItem>().Where(x => x.CreateDate >= sinceDate.Value.LocalDateTime) : null;
|
||||
PaginationHelper.ConvertSkipTakeToPaging(skip, take, out var pageNumber, out var pageSize);
|
||||
|
||||
IEnumerable<IAuditItem> auditItems = _auditRepository.GetPagedResultsByQuery(query, pageNumber, pageSize, out var totalRecords, orderDirection, auditTypeFilter, customFilter);
|
||||
|
||||
@@ -99,7 +99,7 @@ public interface IAuditService : IService
|
||||
int skip,
|
||||
int take,
|
||||
Direction orderDirection = Direction.Descending,
|
||||
DateTime? sinceDate = null,
|
||||
DateTimeOffset? sinceDate = null,
|
||||
AuditType[]? auditTypeFilter = null) => throw new NotImplementedException();
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -22,8 +22,8 @@ public interface ILogViewerService : IService
|
||||
/// <param name="filterExpression">The query expression to filter on.</param>
|
||||
/// <param name="logLevels">The log levels for which to retrieve the log messages.</param>
|
||||
Task<Attempt<PagedModel<ILogEntry>?, LogViewerOperationStatus>> GetPagedLogsAsync(
|
||||
DateTime? startDate,
|
||||
DateTime? endDate,
|
||||
DateTimeOffset? startDate,
|
||||
DateTimeOffset? endDate,
|
||||
int skip,
|
||||
int take,
|
||||
Direction orderDirection = Direction.Descending,
|
||||
@@ -63,7 +63,7 @@ public interface ILogViewerService : IService
|
||||
/// <param name="startDate">The start date for the date range.</param>
|
||||
/// <param name="endDate">The end date for the date range.</param>
|
||||
/// <returns>The value whether or not you are able to view the logs.</returns>
|
||||
Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(DateTime? startDate, DateTime? endDate);
|
||||
Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(DateTimeOffset? startDate, DateTimeOffset? endDate);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a number of the different log level entries.
|
||||
@@ -72,7 +72,7 @@ public interface ILogViewerService : IService
|
||||
/// </summary>
|
||||
/// <param name="startDate">The start date for the date range.</param>
|
||||
/// <param name="endDate">The end date for the date range.</param>
|
||||
Task<Attempt<LogLevelCounts?, LogViewerOperationStatus>> GetLogLevelCountsAsync(DateTime? startDate, DateTime? endDate);
|
||||
Task<Attempt<LogLevelCounts?, LogViewerOperationStatus>> GetLogLevelCountsAsync(DateTimeOffset? startDate, DateTimeOffset? endDate);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a paged model of all unique message templates and their counts.
|
||||
@@ -83,7 +83,7 @@ public interface ILogViewerService : IService
|
||||
/// <param name="endDate">The end date for the date range.</param>
|
||||
/// <param name="skip">The amount of items to skip.</param>
|
||||
/// <param name="take">The amount of items to take.</param>
|
||||
Task<Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus>> GetMessageTemplatesAsync(DateTime? startDate, DateTime? endDate, int skip, int take);
|
||||
Task<Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus>> GetMessageTemplatesAsync(DateTimeOffset? startDate, DateTimeOffset? endDate, int skip, int take);
|
||||
|
||||
/// <summary>
|
||||
/// Get the log level values of the global minimum and the UmbracoFile one from the config file.
|
||||
|
||||
@@ -32,8 +32,8 @@ public class LogViewerService : ILogViewerService
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<Attempt<PagedModel<ILogEntry>?, LogViewerOperationStatus>> GetPagedLogsAsync(
|
||||
DateTime? startDate,
|
||||
DateTime? endDate,
|
||||
DateTimeOffset? startDate,
|
||||
DateTimeOffset? endDate,
|
||||
int skip,
|
||||
int take,
|
||||
Direction orderDirection = Direction.Descending,
|
||||
@@ -109,7 +109,7 @@ public class LogViewerService : ILogViewerService
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(DateTime? startDate, DateTime? endDate)
|
||||
public async Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(DateTimeOffset? startDate, DateTimeOffset? endDate)
|
||||
{
|
||||
LogTimePeriod logTimePeriod = GetTimePeriod(startDate, endDate);
|
||||
bool isAllowed = CanViewLogs(logTimePeriod);
|
||||
@@ -123,7 +123,7 @@ public class LogViewerService : ILogViewerService
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<Attempt<LogLevelCounts?, LogViewerOperationStatus>> GetLogLevelCountsAsync(DateTime? startDate, DateTime? endDate)
|
||||
public async Task<Attempt<LogLevelCounts?, LogViewerOperationStatus>> GetLogLevelCountsAsync(DateTimeOffset? startDate, DateTimeOffset? endDate)
|
||||
{
|
||||
LogTimePeriod logTimePeriod = GetTimePeriod(startDate, endDate);
|
||||
|
||||
@@ -143,7 +143,7 @@ public class LogViewerService : ILogViewerService
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus>> GetMessageTemplatesAsync(DateTime? startDate, DateTime? endDate, int skip, int take)
|
||||
public async Task<Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus>> GetMessageTemplatesAsync(DateTimeOffset? startDate, DateTimeOffset? endDate, int skip, int take)
|
||||
{
|
||||
LogTimePeriod logTimePeriod = GetTimePeriod(startDate, endDate);
|
||||
|
||||
@@ -183,7 +183,7 @@ public class LogViewerService : ILogViewerService
|
||||
/// <param name="startDate">The start date for the date range (can be null).</param>
|
||||
/// <param name="endDate">The end date for the date range (can be null).</param>
|
||||
/// <returns>The LogTimePeriod object used to filter logs.</returns>
|
||||
private LogTimePeriod GetTimePeriod(DateTime? startDate, DateTime? endDate)
|
||||
private LogTimePeriod GetTimePeriod(DateTimeOffset? startDate, DateTimeOffset? endDate)
|
||||
{
|
||||
if (startDate is null || endDate is null)
|
||||
{
|
||||
@@ -199,7 +199,7 @@ public class LogViewerService : ILogViewerService
|
||||
}
|
||||
}
|
||||
|
||||
return new LogTimePeriod(startDate.Value, endDate.Value);
|
||||
return new LogTimePeriod(startDate.Value.LocalDateTime, endDate.Value.LocalDateTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user