Skip to content

Media: Record the trashing user against the History audit entry (closes #22661)#22668

Merged
kjac merged 1 commit into
mainfrom
v17/bugfix/22661-correct-tracking-of-media-deleter
May 3, 2026
Merged

Media: Record the trashing user against the History audit entry (closes #22661)#22668
kjac merged 1 commit into
mainfrom
v17/bugfix/22661-correct-tracking-of-media-deleter

Conversation

@AndyButland

@AndyButland AndyButland commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Description

When user B trashes a media item that user A originally created/uploaded, the History panel for that item shows user A against the Media deleted entry instead of user B. Documents behave correctly (they show user B). The bug is reported on v13 in #22661 but is still present in the latest code.

Root cause

The Media deleted entry in the History panel is written by RelateOnTrashNotificationHandler.HandleAsync on MediaMovedToRecycleBinNotification:

The handler uses the back-office user when available, otherwise falls back to item.Entity.WriterId, and this is what is being logged.

For documents, ContentService.PerformMoveContentLocked already updates WriterId = userId before saving, so the fallback resolves to user B (the deleting user). For media, MediaService.PerformMoveMediaLocked saved the entity without ever updating WriterId, so the fallback resolved to user A (the original creator).

Fix

src/Umbraco.Core/Services/MediaService.cs: pass userId through to PerformMoveMediaLocked and set media.WriterId = userId before saving — mirroring ContentService.PerformMoveContentLocked and aligning the behaviour with documents.

Testing

Automated

An integration tests has been added verifying that the writer is set correctly for media, and, for completeness, a similar one added for documents.

Manual

To verify manually:

  • Create a media item with one user.
  • Login as another user and delete it (move it to the recycle bin).
  • View the audit log from the "Info" workspace view for the media and note the correct user is associated with the delete operation.

Copilot AI review requested due to automatic review settings April 30, 2026 21:33
@claude

claude Bot commented Apr 30, 2026

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes incorrect attribution in Media history/audit by ensuring media items’ WriterId is updated to the acting user when moved/trashed, aligning media behavior with documents and enabling correct fallback attribution in RelateOnTrashNotificationHandler.

Changes:

  • Update MediaService move/trash save path to set media.WriterId = userId during move operations (including trashing).
  • Refactor/organize media editing integration tests into a partial-class layout and add regression coverage for WriterId + existing AuditType.Move attribution.
  • Add companion content tests to guard existing document behavior from regressions.

Reviewed changes

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

Show a summary per file
File Description
src/Umbraco.Core/Services/MediaService.cs Pass userId through move-save helper and update WriterId before saving so audit/history attribution reflects the acting user.
tests/Umbraco.Tests.Integration/Umbraco.Tests.Integration.csproj Nests the media recycle-bin test file under the new MediaEditingServiceTests.cs via <DependentUpon>.
tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MediaEditingServiceTests.cs Introduces fixture/shared helpers for media editing tests (partial-class layout).
tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/MediaEditingServiceTests.MoveToRecycleBin.cs Adds regression tests for WriterId update on trash and validates AuditType.Move is attributed to the deleter.
tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.MoveToRecycleBin.cs Adds companion tests ensuring content trash keeps CreatorId stable, updates WriterId, and records AuditType.Move against the acting user.

@kjac kjac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Works like a charm.

Good job on refactoring the MediaEditingServiceTests too 👏

@kjac kjac merged commit 52c1336 into main May 3, 2026
33 of 34 checks passed
@kjac kjac deleted the v17/bugfix/22661-correct-tracking-of-media-deleter branch May 3, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants