Skip to content

Audit service rework #19346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: v17/improvement/introduce-audit-entry-service
Choose a base branch
from

Conversation

lauraneto
Copy link
Contributor

Note

This was added on top of #19345, due to method moving from this service to the new AuditEntryService.

Description

  • Added new async and paged methods
    • AddAsync - replaces Add (async + accepts user key)
    • GetItemsAsync - replaces GetLogs (async + pagination)
    • GetItemsByEntityAsync - replaces GetPagedItemsByEntity and GetLogs(objectId) (async + pagination)
    • CleanLogsAsync - replaces CleanLogs (async)
  • Marked (now) redundant methods as obsolete and re-used logic between non-obsolete and obsolete methods
  • Updated all of the usages to use the non-obsolete methods
  • Added unit tests class AuditServiceTests and some unit tests
  • Updated existing integration test

Testing

TODO

- Added new async and paged methods
- Marked (now) redundant methods as obsolete
- Updated all of the usages to use the non-obsolete methods
- Added unit tests class `AuditServiceTests` and some unit tests
- Updated existing integration test
@lauraneto lauraneto requested a review from Copilot May 16, 2025 15:50
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reworks the audit service by introducing new asynchronous and paged methods across the codebase and deprecating the old synchronous implementations. Key changes include:

  • Replacing sync audit log methods with async versions (e.g. AddAsync, CleanLogsAsync, GetItemsAsync, etc.) and marking outdated methods as obsolete.
  • Updating unit and integration tests to use the new async methods.
  • Adjusting notification handler registrations and background job implementations to align with the async model.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/BackgroundJobs/Jobs/LogScrubberJobTests.cs Updated verification to use CleanLogsAsync
tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/AuditServiceTests.cs Updated tests invoking async audit log methods
tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.cs Changed to async notification handler and arrays for audit type filters
tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs Converted content variation tests to async calls for audit logs
src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs Replaced sync audit calls with async ones and handled responses accordingly
src/Umbraco.Infrastructure/Events/RelateOnTrashNotificationHandler.cs Switched to async audit logging and updated constructor dependency injection
src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs Changed registration from sync to async notification handlers
src/Umbraco.Infrastructure/BackgroundJobs/Jobs/LogScrubberJob.cs Updated job execution to await CleanLogsAsync
src/Umbraco.Core/Services/IAuditService.cs Updated interface to include new async methods and marked obsolete methods
src/Umbraco.Core/Events/RelateOnCopyNotificationHandler.cs Moved to async implementation and added new dependency
Comments suppressed due to low confidence (2)

src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs:86

  • [nitpick] Consider refactoring the blocking call to GetAwaiter().GetResult() by making the method asynchronous and awaiting the async call, to reduce the risk of deadlocks and improve scalability.
_auditService.AddAsync( AuditType.PackagerInstall, user?.Key ?? Constants.Security.SuperUserKey, -1, "Package", $"Package data installed for package '{compiledPackage.Name}'.").GetAwaiter().GetResult();

src/Umbraco.Core/Services/IAuditService.cs:157

  • The parameter type for 'sinceDate' differs from the one in GetItemsAsync (DateTimeOffset? vs DateTime?); consider unifying these types for consistency across the audit API.
Task<PagedModel<IAuditItem>> GetPagedItemsByUserAsync( Guid userKey, int skip, int take, Direction orderDirection = Direction.Descending, AuditType[]? auditTypeFilter = null, DateTime? sinceDate = null) => throw new NotImplementedException();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant