Skip to content

Use audit service instead of repository directly in services #19357

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 1 commit into
base: v17/improvement/audit-service-rework
Choose a base branch
from

Conversation

lauraneto
Copy link
Contributor

Note

These changes were done on top of the v17/improvement/audit-service-rework branch for simplicity, but can be made separate if needed.

Prerequisites

  • I have added steps to test this contribution in the description below

Description

This pull request refactors the audit logging functionality across several services. The key changes include replacing the use of IAuditRepository with IAuditService and using the new asynchronous IAuditService.AddAsync method.

The following services were adjusted:

  • ContentBlueprintContainerService
  • ContentService
  • ContentTypeContainerService
  • ContentTypeService
  • ContentTypeServiceBaseOfTRepositoryTItemTService
  • ContentVersionService
  • DataTypeContainerService
  • DataTypeService
  • DictionaryItemService
  • EntityTypeContainerService
  • FileService
  • FileServiceOperationBase
  • LanguageService
  • LocalizationService (just removed the reference to IAuditRepository as it wasn't used)
  • MediaService
  • MediaTypeContainerService
  • MediaTypeService
  • MemberService
  • MemberTypeService
  • PartialViewService
  • RelationService
  • ScriptService
  • StylesheetService
  • TemplateService

In order to test the changes I performed an operation on each type (related to each service), and verified that an entry had been added to the umbracoLog table.
Example: creating a blueprint, saving a content item, creating a content type, etc.

@lauraneto lauraneto requested a review from Copilot May 19, 2025 11:35
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 refactors audit logging across multiple services to use the new asynchronous IAuditService.AddAsync API instead of the old IAuditRepository.Save calls and replaces constructor dependencies accordingly.

  • Swapped all uses of IAuditRepository for IAuditService and introduced AuditAsync wrappers.
  • Updated obsolete constructors to resolve IAuditService via StaticServiceProvider.
  • Added injection of IUserIdKeyResolver where needed to look up user keys.

Reviewed Changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Umbraco.Core/Services/MemberTypeService.cs Replaced repository with service and added obsolete CTORs
src/Umbraco.Core/Services/MemberService.cs Swapped audit repo for service, added async AuditAsync
src/Umbraco.Core/Services/MediaTypeService.cs Replaced audit repo, updated constructors
src/Umbraco.Core/Services/MediaTypeContainerService.cs Updated base call to use IAuditService
src/Umbraco.Core/Services/MediaService.cs Replaced audit repo, added async audit helper
src/Umbraco.Core/Services/LocalizationService.cs Removed unused audit repo dependency
src/Umbraco.Core/Services/LanguageService.cs Swapped audit repo for service and refactored AuditAsync
src/Umbraco.Core/Services/FileServiceOperationBase.cs Replaced audit repo, added async AuditAsync
src/Umbraco.Core/Services/FileService.cs Replaced audit repo, added async AuditAsync
src/Umbraco.Core/Services/EntityTypeContainerService.cs Swapped to IAuditService and async calls
src/Umbraco.Core/Services/DictionaryItemService.cs Replaced audit repo, introduced AuditAsync
src/Umbraco.Core/Services/DataTypeService.cs Swapped audit repo, added multi‐overload AuditAsync
src/Umbraco.Core/Services/DataTypeContainerService.cs Updated base class call to use service
src/Umbraco.Core/Services/ContentVersionService.cs Replaced audit repo, refactored AuditAsync
src/Umbraco.Core/Services/ContentTypeServiceBaseOfTRepositoryTItemTService.cs Swapped to service and refactored AuditAsync
src/Umbraco.Core/Services/ContentTypeService.cs Replaced audit repo, added obsolete CTORs
src/Umbraco.Core/Services/ContentTypeContainerService.cs Updated base call to use IAuditService
src/Umbraco.Core/Services/ContentService.cs Swapped audit repo, refactored AuditAsync
src/Umbraco.Core/Services/ContentBlueprintContainerService.cs Updated base call to use IAuditService
src/Umbraco.Core/Services/AuditService.cs Removed IUserService, injected IUserIdKeyResolver
Comments suppressed due to low confidence (4)

src/Umbraco.Core/Services/FileServiceOperationBase.cs:19

  • The logger is typed as ILogger<StylesheetService> in this generic base class. Consider parameterizing it with the actual class name (FileServiceOperationBase<...>) to ensure log categories are accurate.
private readonly ILogger<StylesheetService> _logger;

src/Umbraco.Core/Services/MediaTypeService.cs:69

  • [nitpick] This obsolete constructor uses an expression-bodied assignment, which differs from the block-bodied style used elsewhere. For consistency, consider converting it to a standard constructor block.
contentTypeFilters) => MediaService = mediaService;

src/Umbraco.Core/Services/MemberTypeService.cs:54

  • The obsolete constructors still take an unused IAuditRepository parameter. To suppress compiler warnings and signal its intentional deprecation, prefix it with _ or annotate it with [Obsolete] rather than leaving it unused.
IAuditRepository auditRepository,

src/Umbraco.Core/Services/DataTypeService.cs:962

  • The audit type was changed from New to Save for this update operation. Confirm that this aligns with your audit semantics, as it may affect how create vs. update actions are distinguished in logs.
userKey,
-                AuditType.New);
+                AuditType.Save);

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