Skip to content

Commit

Permalink
Management api should use datetimeoffset (#16196)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
bergmania and kjac authored May 7, 2024
1 parent f44fb59 commit 2260da2
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public GetAuditLogDocumentController(
[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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public async Task<IActionResult> AllLogs(
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public async Task<IActionResult> AllMessageTemplates(
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public LogLevelCountLogViewerController(ILogViewerService logViewerService, IUmb
[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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public GetAuditLogMediaController(
[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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; } = [];
}
4 changes: 2 additions & 2 deletions src/Umbraco.Core/Services/AuditService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public async Task<PagedModel<IAuditItem>> GetItemsByKeyAsync(
int skip,
int take,
Direction orderDirection = Direction.Descending,
DateTime? sinceDate = null,
DateTimeOffset? sinceDate = null,
AuditType[]? auditTypeFilter = null)
{
if (skip < 0)
Expand All @@ -264,7 +264,7 @@ public async Task<PagedModel<IAuditItem>> GetItemsByKeyAsync(
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);
Expand Down
2 changes: 1 addition & 1 deletion src/Umbraco.Core/Services/IAuditService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Task<PagedModel<IAuditItem>> GetItemsByKeyAsync(
int skip,
int take,
Direction orderDirection = Direction.Descending,
DateTime? sinceDate = null,
DateTimeOffset? sinceDate = null,
AuditType[]? auditTypeFilter = null) => throw new NotImplementedException();

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/Umbraco.Core/Services/ILogViewerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions src/Umbraco.Core/Services/LogViewerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public LogViewerService(

/// <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,
Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task<PagedModel<ILogViewerQuery>> GetSavedLogQueriesAsync(int skip,
}

/// <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);
Expand All @@ -123,7 +123,7 @@ public async Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(Date
}

/// <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);

Expand All @@ -143,7 +143,7 @@ public async Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(Date
}

/// <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);

Expand Down Expand Up @@ -183,7 +183,7 @@ public ReadOnlyDictionary<string, LogLevel> GetLogLevelsFromSinks()
/// <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)
{
Expand All @@ -199,7 +199,7 @@ private LogTimePeriod GetTimePeriod(DateTime? startDate, DateTime? endDate)
}
}

return new LogTimePeriod(startDate.Value, endDate.Value);
return new LogTimePeriod(startDate.Value.LocalDateTime, endDate.Value.LocalDateTime);
}

/// <summary>
Expand Down

0 comments on commit 2260da2

Please sign in to comment.