Skip to content

Commit 61f1c4a

Browse files
AndyButlandlauranetoCopilot
authored
Fixes issue with service registration for file system tree service (#20273)
* Display the latest update date in document collection view * Fix issue with service registration of physical file system tree service. * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Laura Neto <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent cf10a59 commit 61f1c4a

13 files changed

+85
-40
lines changed

src/Umbraco.Cms.Api.Management/Controllers/PartialView/Tree/PartialViewTreeControllerBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Authorization;
1+
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.Extensions.DependencyInjection;
44
using Umbraco.Cms.Api.Management.Controllers.Tree;
@@ -25,7 +25,7 @@ public PartialViewTreeControllerBase(IPartialViewTreeService partialViewTreeServ
2525

2626
// FileSystem is required therefore, we can't remove it without some wizadry. When obsoletion is due, remove this.
2727
[ActivatorUtilitiesConstructor]
28-
[Obsolete("Scheduled for removal in Umbraco 19")]
28+
[Obsolete("Scheduled for removal in Umbraco 18.")]
2929
public PartialViewTreeControllerBase(IPartialViewTreeService partialViewTreeService, FileSystems fileSystems)
3030
: base(partialViewTreeService)
3131
{
@@ -34,12 +34,12 @@ public PartialViewTreeControllerBase(IPartialViewTreeService partialViewTreeServ
3434
throw new ArgumentException("Missing scripts file system", nameof(fileSystems));
3535
}
3636

37-
[Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")]
37+
[Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 18.")]
3838
public PartialViewTreeControllerBase(FileSystems fileSystems)
3939
: this(StaticServiceProvider.Instance.GetRequiredService<IPartialViewTreeService>())
4040
=> FileSystem = fileSystems.PartialViewsFileSystem ??
4141
throw new ArgumentException("Missing scripts file system", nameof(fileSystems));
4242

43-
[Obsolete("Included in the service class. Scheduled to be removed in Umbraco 19")]
43+
[Obsolete("Included in the service class. Scheduled to be removed in Umbraco 18.")]
4444
protected override IFileSystem FileSystem { get; }
4545
}

src/Umbraco.Cms.Api.Management/Controllers/Script/Tree/ScriptTreeControllerBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Authorization;
1+
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.Extensions.DependencyInjection;
44
using Umbraco.Cms.Api.Management.Controllers.Tree;
@@ -25,7 +25,7 @@ public ScriptTreeControllerBase(IScriptTreeService scriptTreeService)
2525

2626
// FileSystem is required therefore, we can't remove it without some wizadry. When obsoletion is due, remove this.
2727
[ActivatorUtilitiesConstructor]
28-
[Obsolete("Scheduled for removal in Umbraco 19")]
28+
[Obsolete("Scheduled for removal in Umbraco 18.")]
2929
public ScriptTreeControllerBase(IScriptTreeService scriptTreeService, FileSystems fileSystems)
3030
: base(scriptTreeService)
3131
{
@@ -34,12 +34,12 @@ public ScriptTreeControllerBase(IScriptTreeService scriptTreeService, FileSystem
3434
throw new ArgumentException("Missing scripts file system", nameof(fileSystems));
3535
}
3636

37-
[Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")]
37+
[Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 18.")]
3838
public ScriptTreeControllerBase(FileSystems fileSystems)
3939
: this(StaticServiceProvider.Instance.GetRequiredService<IScriptTreeService>())
4040
=> FileSystem = fileSystems.ScriptsFileSystem ??
4141
throw new ArgumentException("Missing scripts file system", nameof(fileSystems));
4242

43-
[Obsolete("Included in the service class. Scheduled to be removed in Umbraco 19")]
43+
[Obsolete("Included in the service class. Scheduled to be removed in Umbraco 18.")]
4444
protected override IFileSystem FileSystem { get; }
4545
}

src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/AncestorsStaticFileTreeController.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using Asp.Versioning;
1+
using Asp.Versioning;
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Umbraco.Cms.Api.Management.Services.FileSystem;
46
using Umbraco.Cms.Api.Management.ViewModels.Tree;
57
using Umbraco.Cms.Core.IO;
68

@@ -9,11 +11,18 @@ namespace Umbraco.Cms.Api.Management.Controllers.StaticFile.Tree;
911
[ApiVersion("1.0")]
1012
public class AncestorsStaticFileTreeController : StaticFileTreeControllerBase
1113
{
14+
[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")]
1215
public AncestorsStaticFileTreeController(IPhysicalFileSystem physicalFileSystem)
1316
: base(physicalFileSystem)
1417
{
1518
}
1619

20+
[ActivatorUtilitiesConstructor]
21+
public AncestorsStaticFileTreeController(IPhysicalFileSystem physicalFileSystem, IPhysicalFileSystemTreeService fileSystemTreeService)
22+
: base(physicalFileSystem, fileSystemTreeService)
23+
{
24+
}
25+
1726
[HttpGet("ancestors")]
1827
[MapToApiVersion("1.0")]
1928
[ProducesResponseType(typeof(IEnumerable<FileSystemTreeItemPresentationModel>), StatusCodes.Status200OK)]

src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/ChildrenStaticFileTreeController.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
using Asp.Versioning;
1+
using Asp.Versioning;
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.AspNetCore.Mvc;
4-
using Umbraco.Cms.Core.IO;
4+
using Microsoft.Extensions.DependencyInjection;
55
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
6+
using Umbraco.Cms.Api.Management.Services.FileSystem;
67
using Umbraco.Cms.Api.Management.ViewModels.Tree;
8+
using Umbraco.Cms.Core.IO;
79

810
namespace Umbraco.Cms.Api.Management.Controllers.StaticFile.Tree;
911

1012
[ApiVersion("1.0")]
1113
public class ChildrenStaticFileTreeController : StaticFileTreeControllerBase
1214
{
15+
[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")]
1316
public ChildrenStaticFileTreeController(IPhysicalFileSystem physicalFileSystem)
1417
: base(physicalFileSystem)
1518
{
1619
}
1720

21+
[ActivatorUtilitiesConstructor]
22+
public ChildrenStaticFileTreeController(IPhysicalFileSystem physicalFileSystem, IPhysicalFileSystemTreeService fileSystemTreeService)
23+
: base(physicalFileSystem, fileSystemTreeService)
24+
{
25+
}
26+
1827
[HttpGet("children")]
1928
[MapToApiVersion("1.0")]
2029
[ProducesResponseType(typeof(PagedViewModel<FileSystemTreeItemPresentationModel>), StatusCodes.Status200OK)]

src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/RootStaticFileTreeController.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
using Asp.Versioning;
1+
using Asp.Versioning;
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.AspNetCore.Mvc;
4-
using Umbraco.Cms.Core.IO;
4+
using Microsoft.Extensions.DependencyInjection;
55
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
6+
using Umbraco.Cms.Api.Management.Services.FileSystem;
67
using Umbraco.Cms.Api.Management.ViewModels.Tree;
8+
using Umbraco.Cms.Core.IO;
79

810
namespace Umbraco.Cms.Api.Management.Controllers.StaticFile.Tree;
911

1012
[ApiVersion("1.0")]
1113
public class RootStaticFileTreeController : StaticFileTreeControllerBase
1214
{
15+
[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")]
1316
public RootStaticFileTreeController(IPhysicalFileSystem physicalFileSystem)
1417
: base(physicalFileSystem)
1518
{
1619
}
1720

21+
[ActivatorUtilitiesConstructor]
22+
public RootStaticFileTreeController(IPhysicalFileSystem physicalFileSystem, IPhysicalFileSystemTreeService fileSystemTreeService)
23+
: base(physicalFileSystem, fileSystemTreeService)
24+
{
25+
}
26+
1827
[HttpGet("root")]
1928
[MapToApiVersion("1.0")]
2029
[ProducesResponseType(typeof(PagedViewModel<FileSystemTreeItemPresentationModel>), StatusCodes.Status200OK)]

src/Umbraco.Cms.Api.Management/Controllers/StaticFile/Tree/StaticFileTreeControllerBase.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Mvc;
22
using Microsoft.Extensions.DependencyInjection;
33
using Umbraco.Cms.Api.Management.Controllers.Tree;
44
using Umbraco.Cms.Api.Management.Routing;
@@ -17,17 +17,19 @@ public class StaticFileTreeControllerBase : FileSystemTreeControllerBase
1717
private readonly IFileSystemTreeService _fileSystemTreeService;
1818
private static readonly string[] _allowedRootFolders = { $"{Path.DirectorySeparatorChar}App_Plugins", $"{Path.DirectorySeparatorChar}wwwroot" };
1919

20-
public StaticFileTreeControllerBase(IPhysicalFileSystem physicalFileSystem, IFileSystemTreeService fileSystemTreeService)
21-
: base (fileSystemTreeService)
20+
[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")]
21+
public StaticFileTreeControllerBase(IPhysicalFileSystem physicalFileSystem)
22+
: base(StaticServiceProvider.Instance.GetRequiredService<IPhysicalFileSystemTreeService>())
2223
{
2324
FileSystem = physicalFileSystem;
24-
_fileSystemTreeService = fileSystemTreeService;
25+
_fileSystemTreeService = StaticServiceProvider.Instance.GetRequiredService<IPhysicalFileSystemTreeService>();
2526
}
2627

27-
[Obsolete("Please use the other constructor. Scheduled for removal in Umbraco 19")]
28-
public StaticFileTreeControllerBase(IPhysicalFileSystem physicalFileSystem)
29-
: this(physicalFileSystem, StaticServiceProvider.Instance.GetRequiredService<IFileSystemTreeService>())
28+
public StaticFileTreeControllerBase(IPhysicalFileSystem physicalFileSystem, IPhysicalFileSystemTreeService fileSystemTreeService)
29+
: base (fileSystemTreeService)
3030
{
31+
FileSystem = physicalFileSystem;
32+
_fileSystemTreeService = fileSystemTreeService;
3133
}
3234

3335
protected override IFileSystem FileSystem { get; }

src/Umbraco.Cms.Api.Management/Controllers/Stylesheet/Tree/StylesheetTreeControllerBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Authorization;
1+
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Mvc;
33
using Microsoft.Extensions.DependencyInjection;
44
using Umbraco.Cms.Api.Management.Controllers.Tree;
@@ -25,7 +25,7 @@ public StylesheetTreeControllerBase(IStyleSheetTreeService styleSheetTreeService
2525

2626
// FileSystem is required therefore, we can't remove it without some wizadry. When obsoletion is due, remove this.
2727
[ActivatorUtilitiesConstructor]
28-
[Obsolete("Scheduled for removal in Umbraco 19")]
28+
[Obsolete("Scheduled for removal in Umbraco 18.")]
2929
public StylesheetTreeControllerBase(IStyleSheetTreeService styleSheetTreeService, FileSystems fileSystems)
3030
: base(styleSheetTreeService)
3131
{
@@ -34,12 +34,12 @@ public StylesheetTreeControllerBase(IStyleSheetTreeService styleSheetTreeService
3434
throw new ArgumentException("Missing scripts file system", nameof(fileSystems));
3535
}
3636

37-
[Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 19")]
37+
[Obsolete("Please use the other constructor. Scheduled to be removed in Umbraco 18.")]
3838
public StylesheetTreeControllerBase(FileSystems fileSystems)
3939
: this(StaticServiceProvider.Instance.GetRequiredService<IStyleSheetTreeService>())
4040
=> FileSystem = fileSystems.ScriptsFileSystem ??
4141
throw new ArgumentException("Missing scripts file system", nameof(fileSystems));
4242

43-
[Obsolete("Included in the service class. Scheduled to be removed in Umbraco 19")]
43+
[Obsolete("Included in the service class. Scheduled to be removed in Umbraco 18.")]
4444
protected override IFileSystem FileSystem { get; }
4545
}

src/Umbraco.Cms.Api.Management/Controllers/Tree/FileSystemTreeControllerBase.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ public abstract class FileSystemTreeControllerBase : ManagementApiControllerBase
1515
{
1616
private readonly IFileSystemTreeService _fileSystemTreeService;
1717

18-
[Obsolete("Has been moved to the individual services. Scheduled to be removed in Umbraco 19")]
18+
[Obsolete("Has been moved to the individual services. Scheduled to be removed in Umbraco 18.")]
1919
protected abstract IFileSystem FileSystem { get; }
2020

2121
[ActivatorUtilitiesConstructor]
2222
protected FileSystemTreeControllerBase(IFileSystemTreeService fileSystemTreeService) => _fileSystemTreeService = fileSystemTreeService;
2323

24-
[Obsolete("Use the other constructor. Scheduled for removal in Umbraco 19")]
24+
[Obsolete("Use the other constructor. Scheduled for removal in Umbraco 18.")]
2525
protected FileSystemTreeControllerBase()
2626
: this(StaticServiceProvider.Instance.GetRequiredService<IScriptTreeService>())
2727
{
2828
}
2929

30-
3130
protected Task<ActionResult<PagedViewModel<FileSystemTreeItemPresentationModel>>> GetRoot(int skip, int take)
3231
{
3332
FileSystemTreeItemPresentationModel[] viewModels = _fileSystemTreeService.GetPathViewModels(string.Empty, skip, take, out var totalItems);
@@ -70,7 +69,7 @@ protected virtual Task<ActionResult<IEnumerable<FileSystemTreeItemPresentationMo
7069
private PagedViewModel<FileSystemTreeItemPresentationModel> PagedViewModel(IEnumerable<FileSystemTreeItemPresentationModel> viewModels, long totalItems)
7170
=> new() { Total = totalItems, Items = viewModels };
7271

73-
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")]
72+
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")]
7473
protected virtual FileSystemTreeItemPresentationModel[] GetAncestorModels(string path, bool includeSelf)
7574
{
7675
var directories = path.Split(Path.DirectorySeparatorChar).Take(Range.EndAt(Index.FromEnd(1))).ToArray();
@@ -87,28 +86,28 @@ protected virtual FileSystemTreeItemPresentationModel[] GetAncestorModels(string
8786
return result.ToArray();
8887
}
8988

90-
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")]
89+
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")]
9190
protected virtual string[] GetDirectories(string path) => FileSystem
9291
.GetDirectories(path)
9392
.OrderBy(directory => directory)
9493
.ToArray();
9594

96-
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")]
95+
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")]
9796
protected virtual string[] GetFiles(string path) => FileSystem
9897
.GetFiles(path)
9998
.OrderBy(file => file)
10099
.ToArray();
101100

102-
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")]
101+
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")]
103102
protected virtual bool DirectoryHasChildren(string path)
104103
=> FileSystem.GetFiles(path).Any() || FileSystem.GetDirectories(path).Any();
105104

106-
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")]
105+
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")]
107106
private string GetFileSystemItemName(bool isFolder, string itemPath) => isFolder
108107
? Path.GetFileName(itemPath)
109108
: FileSystem.GetFileName(itemPath);
110109

111-
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 19")]
110+
[Obsolete("Has been moved to FileSystemTreeServiceBase. Scheduled for removal in Umbraco 18.")]
112111
private FileSystemTreeItemPresentationModel MapViewModel(string path, string name, bool isFolder)
113112
{
114113
var parentPath = Path.GetDirectoryName(path);

src/Umbraco.Cms.Api.Management/DependencyInjection/TreeBuilderExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.Extensions.DependencyInjection;
1+
using Microsoft.Extensions.DependencyInjection;
22
using Umbraco.Cms.Api.Management.Services.Entities;
33
using Umbraco.Cms.Api.Management.Services.FileSystem;
44
using Umbraco.Cms.Core.DependencyInjection;
@@ -11,10 +11,13 @@ internal static class TreeBuilderExtensions
1111
internal static IUmbracoBuilder AddTrees(this IUmbracoBuilder builder)
1212
{
1313
builder.Services.AddTransient<IUserStartNodeEntitiesService, UserStartNodeEntitiesService>();
14+
1415
builder.Services.AddUnique<IPartialViewTreeService, PartialViewTreeService>();
1516
builder.Services.AddUnique<IScriptTreeService, ScriptTreeService>();
1617
builder.Services.AddUnique<IStyleSheetTreeService, StyleSheetTreeService>();
1718

19+
builder.Services.AddUnique<IPhysicalFileSystemTreeService, PhysicalFileSystemTreeService>();
20+
1821
return builder;
1922
}
2023
}

src/Umbraco.Cms.Api.Management/DependencyInjection/UmbracoBuilder.BackOffice.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using Microsoft.Extensions.Logging;
33
using Umbraco.Cms.Api.Management.DependencyInjection;
4-
using Umbraco.Cms.Api.Management.Security;
54
using Umbraco.Cms.Core.DependencyInjection;
65
using Umbraco.Cms.Core.Hosting;
76
using Umbraco.Cms.Core.IO;
87
using Umbraco.Cms.Infrastructure.DependencyInjection;
9-
using Umbraco.Cms.Infrastructure.Examine.DependencyInjection;
108
using Umbraco.Cms.Web.Common.Hosting;
119

1210
namespace Umbraco.Extensions;

0 commit comments

Comments
 (0)