Skip to content

Audit entries rework #19345

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

Open
wants to merge 4 commits into
base: v17/dev
Choose a base branch
from

Conversation

lauraneto
Copy link
Contributor

@lauraneto lauraneto commented May 16, 2025

Description

  • Moved logic related to the IAuditEntryRepository (umbracoAudit) from the AuditService to the new service
  • Introduced new async methods
    • Using ids (marked as obsolete - for easier transition from the previous Write method)
    • Using keys
  • Added migration to add columns for performingUserKey and affectedUserKey and convert existing user ids
  • Moved and updated integration tests related to the audit entries to a new test class AuditEntryServiceTests
  • Added unit tests class AuditEntryServiceTests and added a few unit tests
  • Adjusted usages of the old AuditService.Write method to use the new one (mostly notification handlers)
  • Added Task<Attempt<Guid>> TryGetAsync(int id) and Task<Attempt<int>> TryGetAsync(Guid key) methods to IUserIdKeyResolver

Affected notification handlers that trigger audit logs

  • BackOfficeUserManagerAuditer
    • UserLoginSuccessNotification
    • UserLogoutSuccessNotification
    • UserLoginFailedNotification
    • UserForgotPasswordRequestedNotification
    • UserForgotPasswordChangedNotification
    • UserPasswordChangedNotification
    • UserPasswordResetNotification
  • AuditNotificationsHandler
    • MemberSavedNotification
    • MemberDeletedNotification
    • AssignedMemberRolesNotification
    • RemovedMemberRolesNotification
    • ExportedMemberNotification
    • UserSavedNotification
    • UserDeletedNotification
    • UserGroupWithUsersSavedNotification
    • AssignedUserGroupPermissionsNotification

Testing

Run the project in the main branch and do a few user operations. Then, switch to this branch, perform the update and do additional user operations.
Check the database to ensure that:

  • The new columns for the user keys were added
  • The migration filled in the keys based on the ids (if the user still exists)
  • New entries were added correctly and contain both the id and key of the users

❓ Pending questions ❓

  1. What to do regarding user id 0 (SYSTEM, Unknown)?
  • Is it ok to give it key 00000000-0000-0000-0000-000000000000 or do we want it to be null? (both in the database and code)
    • If empty guid is preferred, the migration should probably also convert user id 0 to guid empty, to differentiate between ids that weren't found and unknown user.
    • If null is preferred, some changes might be needed in the AddAsync methods (at the moment if the id is 0 or the overload accepting id is used and it cannot convert/find that id, it is saving as empty guid)

- Moved logic related to the IAuditEntryRepository from the AuditService to the new service
- Introduced new Async methods
  - Using ids (for easier transition from the previous Write method)
  - Using keys
- Moved and updated integration tests related to the audit entries to a new test class `AuditEntryServiceTests`
- Added unit tests class `AuditEntryServiceTests` and added a few unit tests
- Added migration to add columns for `performingUserKey` and `affectedUserKey` and convert existing user ids
- Adjusted usages of the old AuditService.Write method to use the new one (mostly notification handlers)
@lauraneto lauraneto changed the base branch from main to v17/dev May 16, 2025 15:00
@lauraneto lauraneto marked this pull request as ready for review May 19, 2025 13:36
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