Skip to content

Commit 2260da2

Browse files
bergmaniakjac
andauthored
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 <[email protected]>
1 parent f44fb59 commit 2260da2

File tree

11 files changed

+28
-28
lines changed

11 files changed

+28
-28
lines changed

src/Umbraco.Cms.Api.Management/Controllers/Document/GetAuditLogDocumentController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public GetAuditLogDocumentController(
3535
[MapToApiVersion("1.0")]
3636
[HttpGet("{id:guid}/audit-log")]
3737
[ProducesResponseType(typeof(PagedViewModel<AuditLogResponseModel>), StatusCodes.Status200OK)]
38-
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTime? sinceDate = null, int skip = 0, int take = 100)
38+
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTimeOffset? sinceDate = null, int skip = 0, int take = 100)
3939
{
4040
AuthorizationResult authorizationResult = await _authorizationService.AuthorizeResourceAsync(
4141
User,

src/Umbraco.Cms.Api.Management/Controllers/LogViewer/AllLogViewerController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public async Task<IActionResult> AllLogs(
4848
Direction orderDirection = Direction.Descending,
4949
string? filterExpression = null,
5050
[FromQuery(Name = "logLevel")] LogLevel[]? logLevels = null,
51-
DateTime? startDate = null,
52-
DateTime? endDate = null)
51+
DateTimeOffset? startDate = null,
52+
DateTimeOffset? endDate = null)
5353
{
5454
var levels = logLevels?.Select(l => l.ToString()).ToArray();
5555

src/Umbraco.Cms.Api.Management/Controllers/LogViewer/AllMessageTemplateLogViewerController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public async Task<IActionResult> AllMessageTemplates(
4040
CancellationToken cancellationToken,
4141
int skip = 0,
4242
int take = 100,
43-
DateTime? startDate = null,
44-
DateTime? endDate = null)
43+
DateTimeOffset? startDate = null,
44+
DateTimeOffset? endDate = null)
4545
{
4646
Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus> messageTemplatesAttempt = await _logViewerService.GetMessageTemplatesAsync(startDate, endDate, skip, take);
4747

src/Umbraco.Cms.Api.Management/Controllers/LogViewer/LogLevelCountLogViewerController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public LogLevelCountLogViewerController(ILogViewerService logViewerService, IUmb
3434
[ProducesResponseType(typeof(LogLevelCountsReponseModel), StatusCodes.Status200OK)]
3535
public async Task<IActionResult> LogLevelCounts(
3636
CancellationToken cancellationToken,
37-
DateTime? startDate = null,
38-
DateTime? endDate = null)
37+
DateTimeOffset? startDate = null,
38+
DateTimeOffset? endDate = null)
3939
{
4040
Attempt<LogLevelCounts?, LogViewerOperationStatus> logLevelCountsAttempt =
4141
await _logViewerService.GetLogLevelCountsAsync(startDate, endDate);

src/Umbraco.Cms.Api.Management/Controllers/LogViewer/ValidateLogFileSizeLogViewerController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class ValidateLogFileSizeLogViewerController : LogViewerControllerBase
2626
[ProducesResponseType(StatusCodes.Status200OK)]
2727
public async Task<IActionResult> CanViewLogs(
2828
CancellationToken cancellationToken,
29-
DateTime? startDate = null,
30-
DateTime? endDate = null)
29+
DateTimeOffset? startDate = null,
30+
DateTimeOffset? endDate = null)
3131
{
3232
Attempt<bool, LogViewerOperationStatus> result = await _logViewerService.CanViewLogsAsync(startDate, endDate);
3333

src/Umbraco.Cms.Api.Management/Controllers/Media/GetAuditLogMediaController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public GetAuditLogMediaController(
3434
[MapToApiVersion("1.0")]
3535
[HttpGet("{id:guid}/audit-log")]
3636
[ProducesResponseType(typeof(PagedViewModel<AuditLogResponseModel>), StatusCodes.Status200OK)]
37-
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTime? sinceDate = null, int skip = 0, int take = 100)
37+
public async Task<IActionResult> GetAuditLog(CancellationToken cancellationToken, Guid id, Direction orderDirection = Direction.Descending, DateTimeOffset? sinceDate = null, int skip = 0, int take = 100)
3838
{
3939
AuthorizationResult authorizationResult = await _authorizationService.AuthorizeResourceAsync(
4040
User,

src/Umbraco.Cms.Api.Management/ViewModels/Member/MemberResponseModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public class MemberResponseModel : ContentResponseModelBase<MemberValueModel, Me
1919

2020
public int FailedPasswordAttempts { get; set; }
2121

22-
public DateTime? LastLoginDate { get; set; }
22+
public DateTimeOffset? LastLoginDate { get; set; }
2323

24-
public DateTime? LastLockoutDate { get; set; }
24+
public DateTimeOffset? LastLockoutDate { get; set; }
2525

26-
public DateTime? LastPasswordChangeDate { get; set; }
26+
public DateTimeOffset? LastPasswordChangeDate { get; set; }
2727

2828
public IEnumerable<Guid> Groups { get; set; } = [];
2929
}

src/Umbraco.Core/Services/AuditService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public async Task<PagedModel<IAuditItem>> GetItemsByKeyAsync(
242242
int skip,
243243
int take,
244244
Direction orderDirection = Direction.Descending,
245-
DateTime? sinceDate = null,
245+
DateTimeOffset? sinceDate = null,
246246
AuditType[]? auditTypeFilter = null)
247247
{
248248
if (skip < 0)
@@ -264,7 +264,7 @@ public async Task<PagedModel<IAuditItem>> GetItemsByKeyAsync(
264264
using (ScopeProvider.CreateCoreScope(autoComplete: true))
265265
{
266266
IQuery<IAuditItem> query = Query<IAuditItem>().Where(x => x.Id == keyToIdAttempt.Result);
267-
IQuery<IAuditItem>? customFilter = sinceDate.HasValue ? Query<IAuditItem>().Where(x => x.CreateDate >= sinceDate) : null;
267+
IQuery<IAuditItem>? customFilter = sinceDate.HasValue ? Query<IAuditItem>().Where(x => x.CreateDate >= sinceDate.Value.LocalDateTime) : null;
268268
PaginationHelper.ConvertSkipTakeToPaging(skip, take, out var pageNumber, out var pageSize);
269269

270270
IEnumerable<IAuditItem> auditItems = _auditRepository.GetPagedResultsByQuery(query, pageNumber, pageSize, out var totalRecords, orderDirection, auditTypeFilter, customFilter);

src/Umbraco.Core/Services/IAuditService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Task<PagedModel<IAuditItem>> GetItemsByKeyAsync(
9999
int skip,
100100
int take,
101101
Direction orderDirection = Direction.Descending,
102-
DateTime? sinceDate = null,
102+
DateTimeOffset? sinceDate = null,
103103
AuditType[]? auditTypeFilter = null) => throw new NotImplementedException();
104104

105105
/// <summary>

src/Umbraco.Core/Services/ILogViewerService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public interface ILogViewerService : IService
2222
/// <param name="filterExpression">The query expression to filter on.</param>
2323
/// <param name="logLevels">The log levels for which to retrieve the log messages.</param>
2424
Task<Attempt<PagedModel<ILogEntry>?, LogViewerOperationStatus>> GetPagedLogsAsync(
25-
DateTime? startDate,
26-
DateTime? endDate,
25+
DateTimeOffset? startDate,
26+
DateTimeOffset? endDate,
2727
int skip,
2828
int take,
2929
Direction orderDirection = Direction.Descending,
@@ -63,7 +63,7 @@ public interface ILogViewerService : IService
6363
/// <param name="startDate">The start date for the date range.</param>
6464
/// <param name="endDate">The end date for the date range.</param>
6565
/// <returns>The value whether or not you are able to view the logs.</returns>
66-
Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(DateTime? startDate, DateTime? endDate);
66+
Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(DateTimeOffset? startDate, DateTimeOffset? endDate);
6767

6868
/// <summary>
6969
/// Returns a number of the different log level entries.
@@ -72,7 +72,7 @@ public interface ILogViewerService : IService
7272
/// </summary>
7373
/// <param name="startDate">The start date for the date range.</param>
7474
/// <param name="endDate">The end date for the date range.</param>
75-
Task<Attempt<LogLevelCounts?, LogViewerOperationStatus>> GetLogLevelCountsAsync(DateTime? startDate, DateTime? endDate);
75+
Task<Attempt<LogLevelCounts?, LogViewerOperationStatus>> GetLogLevelCountsAsync(DateTimeOffset? startDate, DateTimeOffset? endDate);
7676

7777
/// <summary>
7878
/// Returns a paged model of all unique message templates and their counts.
@@ -83,7 +83,7 @@ public interface ILogViewerService : IService
8383
/// <param name="endDate">The end date for the date range.</param>
8484
/// <param name="skip">The amount of items to skip.</param>
8585
/// <param name="take">The amount of items to take.</param>
86-
Task<Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus>> GetMessageTemplatesAsync(DateTime? startDate, DateTime? endDate, int skip, int take);
86+
Task<Attempt<PagedModel<LogTemplate>, LogViewerOperationStatus>> GetMessageTemplatesAsync(DateTimeOffset? startDate, DateTimeOffset? endDate, int skip, int take);
8787

8888
/// <summary>
8989
/// Get the log level values of the global minimum and the UmbracoFile one from the config file.

0 commit comments

Comments
 (0)