Media: Add protection to restrict access to media in recycle bin (closes #2931) (#20378)

* Add MoveFile it IFileSystem and implement on file systems.

* Rename media file on move to recycle bin.

* Rename file on restore from recycle bin.

* Add configuration to enabled recycle bin media protection.

* Expose backoffice authentication as cookie for non-backoffice usage.
Protected requests for media in recycle bin.

* Display protected image when viewing image cropper in the backoffice media recycle bin.

* Code tidy and comments.

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Introduced helper class to DRY up repeated code between image cropper and file upload notification handlers.

* Reverted client-side and management API updates.

* Moved update of path to media file in recycle bin with deleted suffix to the server.

* Separate integration tests for add and remove.

* Use interpolated strings.

* Renamed variable.

* Move EnableMediaRecycleBinProtection to ContentSettings.

* Tidied up comments.

* Added TODO for 18.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Andy Butland
2025-11-04 08:39:44 +01:00
committed by GitHub
parent b502e29d51
commit 2b8146f72d
24 changed files with 757 additions and 34 deletions

View File

@@ -1,7 +1,6 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
using System.IO;
using System.Text;
using Microsoft.Extensions.Logging;
using Moq;
@@ -82,6 +81,24 @@ public class PhysicalFileSystemTests : AbstractFileSystemTests
});
}
[Test]
public void MoveFileTest()
{
var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FileSysTests");
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
{
_fileSystem.AddFile("sub/f3.txt", ms);
}
Assert.IsTrue(File.Exists(Path.Combine(basePath, "sub/f3.txt")));
_fileSystem.MoveFile("sub/f3.txt", "sub2/f4.txt");
Assert.IsFalse(File.Exists(Path.Combine(basePath, "sub/f3.txt")));
Assert.IsTrue(File.Exists(Path.Combine(basePath, "sub2/f4.txt")));
}
[Test]
public void GetFullPathTest()
{