-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Cannot view audit logs when they contain entries with user id 0 #19263
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
Cannot view audit logs when they contain entries with user id 0 #19263
Conversation
581c275 to
2424d4a
Compare
2424d4a to
af9f130
Compare
| private AuditLogResponseModel CreateAuditLogViewModel(IAuditItem auditItem) | ||
| { | ||
| Guid userKey = _userIdKeyResolver.GetAsync(auditItem.UserId).GetAwaiter().GetResult(); | ||
| IUser user = _userService.GetAsync(userKey).GetAwaiter().GetResult() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the user service does no extra validations when retrieving the user, I removed this call entirely, as it seemed unnecessary as we only need the key.
There was a problem hiding this 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 updates the audit log functionality to properly handle audit entries for the special Unknown/System user (user id 0).
- Updates the IUserIdKeyResolver documentation to indicate that an exception is thrown when a user is not found.
- Modifies the AuditLogPresentationFactory to return an empty user reference when the user id is the unknown/system user, avoiding an exception.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Umbraco.Core/Services/IUserIdKeyResolver.cs | Updated XML comments to document the new exception-based behavior when a user is not found. |
| src/Umbraco.Cms.Api.Management/Factories/AuditLogPresentationFactory.cs | Refactored audit log view model creation to handle user id 0 gracefully using a switch expression. |
Zeegaan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, tests good 🎉
Prerequisites
If there's an existing issue for this PR then this fixes #17149
Description
When using the
IContentServiceit is possible to pass in user id 0 (special Unknown/System user). This user does not actually exist in the database, and was therefore causing an exception to be thrown inIUserIdKeyResolver, which was called when mapping the audit logs.It was not mentioned in the reported issue, but when reproducing the issue I noticed it only happened with user 0, any other non-existing id would throw a foreign key error when trying to insert, so this was a special case.
Reproduction steps
In my case I added a simple API endpoint that I could easily call as needed, and added the following code. You can also check the reproduction sample provided in the issue.
Current behavior
The audit logs do not load and an error toast is shown.

New behavior
The audit logs load and show the entries with id 0 as Unknown.
