diff --git a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/PartialViewTreeControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/PartialViewTreeControllerBase.cs index b45aff4616..6875e395f6 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/PartialViewTreeControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/PartialViewTreeControllerBase.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Management.Controllers.Tree; @@ -25,7 +25,7 @@ public class PartialViewTreeControllerBase : FileSystemTreeControllerBase // FileSystem is required therefore, we can't remove it without some wizadry. When obsoletion is due, remove this. [ActivatorUtilitiesConstructor] - [Obsolete("Scheduled for removal in Umbraco 19")] + [Obsolete("Scheduled for removal in Umbraco 18.")] public PartialViewTreeControllerBase(IPartialViewTreeService partialViewTreeService, FileSystems fileSystems) : base(partialViewTreeService) { @@ -34,12 +34,12 @@ public class PartialViewTreeControllerBase : FileSystemTreeControllerBase throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 18.")] public PartialViewTreeControllerBase(FileSystems fileSystems) : this(StaticServiceProvider.Instance.GetRequiredService()) => FileSystem = fileSystems.PartialViewsFileSystem ?? throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); - [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 19")] + [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 18.")] protected override IFileSystem FileSystem { get; } } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ScriptTreeControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ScriptTreeControllerBase.cs index ba302fc920..d79740d845 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ScriptTreeControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ScriptTreeControllerBase.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Management.Controllers.Tree; @@ -25,7 +25,7 @@ public class ScriptTreeControllerBase : FileSystemTreeControllerBase // FileSystem is required therefore, we can't remove it without some wizadry. When obsoletion is due, remove this. [ActivatorUtilitiesConstructor] - [Obsolete("Scheduled for removal in Umbraco 19")] + [Obsolete("Scheduled for removal in Umbraco 18.")] public ScriptTreeControllerBase(IScriptTreeService scriptTreeService, FileSystems fileSystems) : base(scriptTreeService) { @@ -34,12 +34,12 @@ public class ScriptTreeControllerBase : FileSystemTreeControllerBase throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 18.")] public ScriptTreeControllerBase(FileSystems fileSystems) : this(StaticServiceProvider.Instance.GetRequiredService()) => FileSystem = fileSystems.ScriptsFileSystem ?? throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); - [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 19")] + [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 18.")] protected override IFileSystem FileSystem { get; } } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/AncestorsStaticFileTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/AncestorsStaticFileTreeController.cs index cba287af2d..83c9e9f371 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/AncestorsStaticFileTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/AncestorsStaticFileTreeController.cs @@ -1,6 +1,8 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; +using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; using Umbraco.Cms.Core.IO; @@ -9,11 +11,18 @@ namespace Umbraco.Cms.Api.Management.Controllers.StaticFile.Tree; [ApiVersion("1.0")] public class AncestorsStaticFileTreeController : StaticFileTreeControllerBase { + [Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")] public AncestorsStaticFileTreeController(IPhysicalFileSystem physicalFileSystem) : base(physicalFileSystem) { } + [ActivatorUtilitiesConstructor] + public AncestorsStaticFileTreeController(IPhysicalFileSystem physicalFileSystem, IPhysicalFileSystemTreeService fileSystemTreeService) + : base(physicalFileSystem, fileSystemTreeService) + { + } + [HttpGet("ancestors")] [MapToApiVersion("1.0")] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] diff --git a/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/ChildrenStaticFileTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/ChildrenStaticFileTreeController.cs index a68780a8e1..b99cd783fe 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/ChildrenStaticFileTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/ChildrenStaticFileTreeController.cs @@ -1,20 +1,29 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Umbraco.Cms.Core.IO; +using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Common.ViewModels.Pagination; +using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; +using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.StaticFile.Tree; [ApiVersion("1.0")] public class ChildrenStaticFileTreeController : StaticFileTreeControllerBase { + [Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")] public ChildrenStaticFileTreeController(IPhysicalFileSystem physicalFileSystem) : base(physicalFileSystem) { } + [ActivatorUtilitiesConstructor] + public ChildrenStaticFileTreeController(IPhysicalFileSystem physicalFileSystem, IPhysicalFileSystemTreeService fileSystemTreeService) + : base(physicalFileSystem, fileSystemTreeService) + { + } + [HttpGet("children")] [MapToApiVersion("1.0")] [ProducesResponseType(typeof(PagedViewModel), StatusCodes.Status200OK)] diff --git a/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/RootStaticFileTreeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/RootStaticFileTreeController.cs index b709aae4ef..bbb7f6c9c4 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/RootStaticFileTreeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/RootStaticFileTreeController.cs @@ -1,20 +1,29 @@ -using Asp.Versioning; +using Asp.Versioning; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Umbraco.Cms.Core.IO; +using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Common.ViewModels.Pagination; +using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Api.Management.ViewModels.Tree; +using Umbraco.Cms.Core.IO; namespace Umbraco.Cms.Api.Management.Controllers.StaticFile.Tree; [ApiVersion("1.0")] public class RootStaticFileTreeController : StaticFileTreeControllerBase { + [Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")] public RootStaticFileTreeController(IPhysicalFileSystem physicalFileSystem) : base(physicalFileSystem) { } + [ActivatorUtilitiesConstructor] + public RootStaticFileTreeController(IPhysicalFileSystem physicalFileSystem, IPhysicalFileSystemTreeService fileSystemTreeService) + : base(physicalFileSystem, fileSystemTreeService) + { + } + [HttpGet("root")] [MapToApiVersion("1.0")] [ProducesResponseType(typeof(PagedViewModel), StatusCodes.Status200OK)] diff --git a/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/StaticFileTreeControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/StaticFileTreeControllerBase.cs index 0695f0b0ed..f7f291a663 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/StaticFileTreeControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/StaticFileTreeControllerBase.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Management.Controllers.Tree; using Umbraco.Cms.Api.Management.Routing; @@ -17,19 +17,21 @@ public class StaticFileTreeControllerBase : FileSystemTreeControllerBase private readonly IFileSystemTreeService _fileSystemTreeService; private static readonly string[] _allowedRootFolders = { $"{Path.DirectorySeparatorChar}App_Plugins", $"{Path.DirectorySeparatorChar}wwwroot" }; - public StaticFileTreeControllerBase(IPhysicalFileSystem physicalFileSystem, IFileSystemTreeService fileSystemTreeService) + [Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")] + public StaticFileTreeControllerBase(IPhysicalFileSystem physicalFileSystem) + : base(StaticServiceProvider.Instance.GetRequiredService()) + { + FileSystem = physicalFileSystem; + _fileSystemTreeService = StaticServiceProvider.Instance.GetRequiredService(); + } + + public StaticFileTreeControllerBase(IPhysicalFileSystem physicalFileSystem, IPhysicalFileSystemTreeService fileSystemTreeService) : base (fileSystemTreeService) { FileSystem = physicalFileSystem; _fileSystemTreeService = fileSystemTreeService; } - [Obsolete("Please use the other constructor. Scheduled for removal in Umbraco 19")] - public StaticFileTreeControllerBase(IPhysicalFileSystem physicalFileSystem) - : this(physicalFileSystem, StaticServiceProvider.Instance.GetRequiredService()) - { - } - protected override IFileSystem FileSystem { get; } protected string[] GetDirectories(string path) => diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/StylesheetTreeControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/StylesheetTreeControllerBase.cs index dd15a02d73..501293f11f 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/StylesheetTreeControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/StylesheetTreeControllerBase.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Management.Controllers.Tree; @@ -25,7 +25,7 @@ public class StylesheetTreeControllerBase : FileSystemTreeControllerBase // FileSystem is required therefore, we can't remove it without some wizadry. When obsoletion is due, remove this. [ActivatorUtilitiesConstructor] - [Obsolete("Scheduled for removal in Umbraco 19")] + [Obsolete("Scheduled for removal in Umbraco 18.")] public StylesheetTreeControllerBase(IStyleSheetTreeService styleSheetTreeService, FileSystems fileSystems) : base(styleSheetTreeService) { @@ -34,12 +34,12 @@ public class StylesheetTreeControllerBase : FileSystemTreeControllerBase throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); } - [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")] + [Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 18.")] public StylesheetTreeControllerBase(FileSystems fileSystems) : this(StaticServiceProvider.Instance.GetRequiredService()) => FileSystem = fileSystems.ScriptsFileSystem ?? throw new ArgumentException("Missing scripts file system", nameof(fileSystems)); - [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 19")] + [Obsolete("Included in the service class. Scheduled to be removed in Umbraco 18.")] protected override IFileSystem FileSystem { get; } } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Tree/FileSystemTreeControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/Tree/FileSystemTreeControllerBase.cs index 933986e2f3..68d1414788 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Tree/FileSystemTreeControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Tree/FileSystemTreeControllerBase.cs @@ -15,19 +15,18 @@ public abstract class FileSystemTreeControllerBase : ManagementApiControllerBase { private readonly IFileSystemTreeService _fileSystemTreeService; - [Obsolete("Has been moved to the individual services. Scheduled to be removed in Umbraco 19")] + [Obsolete("Has been moved to the individual services. Scheduled to be removed in Umbraco 18.")] protected abstract IFileSystem FileSystem { get; } [ActivatorUtilitiesConstructor] protected FileSystemTreeControllerBase(IFileSystemTreeService fileSystemTreeService) => _fileSystemTreeService = fileSystemTreeService; - [Obsolete("Use the other constructor. Scheduled for removal in Umbraco 19")] + [Obsolete("Use the other constructor. Scheduled for removal in Umbraco 18.")] protected FileSystemTreeControllerBase() : this(StaticServiceProvider.Instance.GetRequiredService()) { } - protected Task>> GetRoot(int skip, int take) { FileSystemTreeItemPresentationModel[] viewModels = _fileSystemTreeService.GetPathViewModels(string.Empty, skip, take, out var totalItems); @@ -70,7 +69,7 @@ public abstract class FileSystemTreeControllerBase : ManagementApiControllerBase private PagedViewModel PagedViewModel(IEnumerable viewModels, long totalItems) => new() { Total = totalItems, Items = viewModels }; - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")] + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] protected virtual FileSystemTreeItemPresentationModel[] GetAncestorModels(string path, bool includeSelf) { var directories = path.Split(Path.DirectorySeparatorChar).Take(Range.EndAt(Index.FromEnd(1))).ToArray(); @@ -87,28 +86,28 @@ public abstract class FileSystemTreeControllerBase : ManagementApiControllerBase return result.ToArray(); } - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")] + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] protected virtual string[] GetDirectories(string path) => FileSystem .GetDirectories(path) .OrderBy(directory => directory) .ToArray(); - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")] + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] protected virtual string[] GetFiles(string path) => FileSystem .GetFiles(path) .OrderBy(file => file) .ToArray(); - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")] + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] protected virtual bool DirectoryHasChildren(string path) => FileSystem.GetFiles(path).Any() || FileSystem.GetDirectories(path).Any(); - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")] + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] private string GetFileSystemItemName(bool isFolder, string itemPath) => isFolder ? Path.GetFileName(itemPath) : FileSystem.GetFileName(itemPath); - [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")] + [Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")] private FileSystemTreeItemPresentationModel MapViewModel(string path, string name, bool isFolder) { var parentPath = Path.GetDirectoryName(path); diff --git a/src/Umbraco.Cms.Api.Management/DependencyInjection/TreeBuilderExtensions.cs b/src/Umbraco.Cms.Api.Management/DependencyInjection/TreeBuilderExtensions.cs index 733223efa0..a598a3dabd 100644 --- a/src/Umbraco.Cms.Api.Management/DependencyInjection/TreeBuilderExtensions.cs +++ b/src/Umbraco.Cms.Api.Management/DependencyInjection/TreeBuilderExtensions.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Api.Management.Services.Entities; using Umbraco.Cms.Api.Management.Services.FileSystem; using Umbraco.Cms.Core.DependencyInjection; @@ -11,10 +11,13 @@ internal static class TreeBuilderExtensions internal static IUmbracoBuilder AddTrees(this IUmbracoBuilder builder) { builder.Services.AddTransient(); + builder.Services.AddUnique(); builder.Services.AddUnique(); builder.Services.AddUnique(); + builder.Services.AddUnique(); + return builder; } } diff --git a/src/Umbraco.Cms.Api.Management/DependencyInjection/UmbracoBuilder.BackOffice.cs b/src/Umbraco.Cms.Api.Management/DependencyInjection/UmbracoBuilder.BackOffice.cs index 2b3e4e06e6..b97edf5188 100644 --- a/src/Umbraco.Cms.Api.Management/DependencyInjection/UmbracoBuilder.BackOffice.cs +++ b/src/Umbraco.Cms.Api.Management/DependencyInjection/UmbracoBuilder.BackOffice.cs @@ -1,12 +1,10 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Umbraco.Cms.Api.Management.DependencyInjection; -using Umbraco.Cms.Api.Management.Security; using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Infrastructure.DependencyInjection; -using Umbraco.Cms.Infrastructure.Examine.DependencyInjection; using Umbraco.Cms.Web.Common.Hosting; namespace Umbraco.Extensions; diff --git a/src/Umbraco.Cms.Api.Management/Services/FileSystem/IFileSystemTreeService.cs b/src/Umbraco.Cms.Api.Management/Services/FileSystem/IFileSystemTreeService.cs index cdf96a4910..edcfd84532 100644 --- a/src/Umbraco.Cms.Api.Management/Services/FileSystem/IFileSystemTreeService.cs +++ b/src/Umbraco.Cms.Api.Management/Services/FileSystem/IFileSystemTreeService.cs @@ -1,5 +1,4 @@ -using Umbraco.Cms.Api.Management.ViewModels.Tree; -using Umbraco.Cms.Core.IO; +using Umbraco.Cms.Api.Management.ViewModels.Tree; namespace Umbraco.Cms.Api.Management.Services.FileSystem; @@ -9,8 +8,7 @@ public interface IFileSystemTreeService FileSystemTreeItemPresentationModel[] GetPathViewModels(string path, int skip, int take, out long totalItems); - FileSystemTreeItemPresentationModel[] GetSiblingsViewModels(string path, int before, int after, out long totalBefore, - out long totalAfter); + FileSystemTreeItemPresentationModel[] GetSiblingsViewModels(string path, int before, int after, out long totalBefore, out long totalAfter); string[] GetDirectories(string path); diff --git a/src/Umbraco.Cms.Api.Management/Services/FileSystem/IPhysicalFileSystemTreeService.cs b/src/Umbraco.Cms.Api.Management/Services/FileSystem/IPhysicalFileSystemTreeService.cs new file mode 100644 index 0000000000..77977fbcd6 --- /dev/null +++ b/src/Umbraco.Cms.Api.Management/Services/FileSystem/IPhysicalFileSystemTreeService.cs @@ -0,0 +1,5 @@ +namespace Umbraco.Cms.Api.Management.Services.FileSystem; + +public interface IPhysicalFileSystemTreeService : IFileSystemTreeService +{ +} diff --git a/src/Umbraco.Cms.Api.Management/Services/FileSystem/PhysicalFileSystemTreeService.cs b/src/Umbraco.Cms.Api.Management/Services/FileSystem/PhysicalFileSystemTreeService.cs new file mode 100644 index 0000000000..3ee03e4927 --- /dev/null +++ b/src/Umbraco.Cms.Api.Management/Services/FileSystem/PhysicalFileSystemTreeService.cs @@ -0,0 +1,13 @@ +using Umbraco.Cms.Core.IO; + +namespace Umbraco.Cms.Api.Management.Services.FileSystem; + +public class PhysicalFileSystemTreeService : FileSystemTreeServiceBase, IPhysicalFileSystemTreeService +{ + private readonly IFileSystem _physicalFileSystem; + + protected override IFileSystem FileSystem => _physicalFileSystem; + + public PhysicalFileSystemTreeService(IPhysicalFileSystem physicalFileSystem) => + _physicalFileSystem = physicalFileSystem; +}