Skip to content

Commit cebfb21

Browse files
AndyButlandCopilotNillasKA
authored
Introduced sign providers for trees and implemented one for documents with schedule pending (#19806)
* Create sign provider collection and call registered providers on rendering a page of tree item view models. Re-work tree controller constructors to provide registered providers as a collection. * Stub implementation of sign provider for documents with a scheduled publish pending. * Complete implementation of tree sign for pending scheduled publish. * Added integration test for new method on IContentService. * Added unit test for HasScheduleSignProvider. * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * Tidied usings and clarified method header comments. * Adding a fixed prefix to all future signs, and removing the provider property * Adding a sign for protected tree documents. * Adding IsProtectedSignProviderTest.cs & correcting HasScheduleSignProviderTests.cs to no longer assert the provider * Fixing minor things in accordance with CR * Adding collection items compatibility * Introduced IHasSigns interface to provide more re-use across trees and collections. Fixed updates to base content controllers (no need to introduce a new type variable). Removed passing entities for populating tree signs (we aren't using it, so simplifies things). * Refactoring a bit to make existing code less duplicated and fixing some constructor obsoletion * Introducing a has pending changes sign. * Applying changes based on CR * Introducing tests for HasPendingChangesSignProvider.cs and stopped the use of contentService * Introducing tests for HasPendingChangesSignProvider.cs and slight logic change * Introduced HasCollectionSignProvider.cs and tests. * Introducing collection signs to Media Tree & Media Collection items * Introducing Plain Items and tests. Refactoring tests as well * Introduced alternative CanProvideSigns() implementation on IsProtectedSignProvider.cs * Slight refactoring to reduce bloating. * Adding [ActivatorUtilitiesConstructor] since it threw an error otherwise * Minor cleanup. * Updated OpenApi.json. --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: NillasKA <[email protected]>
1 parent 467e55c commit cebfb21

File tree

88 files changed

+2249
-126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2249
-126
lines changed

src/Umbraco.Cms.Api.Management/Controllers/Content/ContentCollectionControllerBase.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using Microsoft.AspNetCore.Http;
22
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.DependencyInjection;
34
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
5+
using Umbraco.Cms.Api.Management.Services.Signs;
46
using Umbraco.Cms.Api.Management.ViewModels.Content;
7+
using Umbraco.Cms.Core.DependencyInjection;
58
using Umbraco.Cms.Core.Mapping;
69
using Umbraco.Cms.Core.Models;
710
using Umbraco.Cms.Core.Models.ContentEditing;
@@ -18,8 +21,19 @@ public abstract class ContentCollectionControllerBase<TContent, TCollectionRespo
1821
where TVariantResponseModel : VariantResponseModelBase
1922
{
2023
private readonly IUmbracoMapper _mapper;
24+
private readonly SignProviderCollection _signProviders;
2125

22-
protected ContentCollectionControllerBase(IUmbracoMapper mapper) => _mapper = mapper;
26+
protected ContentCollectionControllerBase(IUmbracoMapper mapper, SignProviderCollection signProvider)
27+
{
28+
_mapper = mapper;
29+
_signProviders = signProvider;
30+
}
31+
32+
[Obsolete("Use the constructer with all parameters. To be removed in Umbraco 18")]
33+
protected ContentCollectionControllerBase(IUmbracoMapper mapper)
34+
: this(mapper, StaticServiceProvider.Instance.GetRequiredService<SignProviderCollection>())
35+
{
36+
}
2337

2438
[Obsolete("This method is no longer used and will be removed in Umbraco 17.")]
2539
protected IActionResult CollectionResult(ListViewPagedModel<TContent> result)
@@ -48,6 +62,9 @@ protected IActionResult CollectionResult(ListViewPagedModel<TContent> result)
4862
return Ok(pageViewModel);
4963
}
5064

65+
/// <summary>
66+
/// Creates a collection result from the provided collection response models and total number of items.
67+
/// </summary>
5168
protected IActionResult CollectionResult(List<TCollectionResponseModel> collectionResponseModels, long totalNumberOfItems)
5269
{
5370
var pageViewModel = new PagedViewModel<TCollectionResponseModel>
@@ -104,4 +121,15 @@ protected IActionResult ContentCollectionOperationStatusResult(ContentCollection
104121
StatusCode = StatusCodes.Status500InternalServerError,
105122
},
106123
});
124+
125+
/// <summary>
126+
/// Populates the signs for the collection response models.
127+
/// </summary>
128+
protected async Task PopulateSigns(IEnumerable<TCollectionResponseModel> itemViewModels)
129+
{
130+
foreach (ISignProvider signProvider in _signProviders.Where(x => x.CanProvideSigns<TCollectionResponseModel>()))
131+
{
132+
await signProvider.PopulateSignsAsync(itemViewModels);
133+
}
134+
}
107135
}

src/Umbraco.Cms.Api.Management/Controllers/DataType/Tree/AncestorsDataTypeTreeController.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
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.Signs;
46
using Umbraco.Cms.Api.Management.ViewModels.Tree;
57
using Umbraco.Cms.Core.Services;
68

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

20+
[ActivatorUtilitiesConstructor]
21+
public AncestorsDataTypeTreeController(IEntityService entityService, SignProviderCollection signProviders, IDataTypeService dataTypeService)
22+
: base(entityService, signProviders, dataTypeService)
23+
{
24+
}
25+
1726
[HttpGet("ancestors")]
1827
[MapToApiVersion("1.0")]
1928
[ProducesResponseType(typeof(IEnumerable<DataTypeTreeItemResponseModel>), StatusCodes.Status200OK)]

src/Umbraco.Cms.Api.Management/Controllers/DataType/Tree/ChildrenDataTypeTreeController.cs

Lines changed: 10 additions & 1 deletion
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;
44
using Umbraco.Cms.Core.Services;
55
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
66
using Umbraco.Cms.Api.Management.ViewModels.Tree;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Umbraco.Cms.Api.Management.Services.Signs;
79

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

1012
[ApiVersion("1.0")]
1113
public class ChildrenDataTypeTreeController : DataTypeTreeControllerBase
1214
{
15+
[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")]
1316
public ChildrenDataTypeTreeController(IEntityService entityService, IDataTypeService dataTypeService)
1417
: base(entityService, dataTypeService)
1518
{
1619
}
1720

21+
[ActivatorUtilitiesConstructor]
22+
public ChildrenDataTypeTreeController(IEntityService entityService, SignProviderCollection signProviders, IDataTypeService dataTypeService)
23+
: base(entityService, signProviders, dataTypeService)
24+
{
25+
}
26+
1827
[HttpGet("children")]
1928
[MapToApiVersion("1.0")]
2029
[ProducesResponseType(typeof(PagedViewModel<DataTypeTreeItemResponseModel>), StatusCodes.Status200OK)]

src/Umbraco.Cms.Api.Management/Controllers/DataType/Tree/DataTypeTreeControllerBase.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
using Microsoft.AspNetCore.Authorization;
1+
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.DependencyInjection;
34
using Umbraco.Cms.Api.Management.Controllers.Tree;
45
using Umbraco.Cms.Api.Management.Routing;
6+
using Umbraco.Cms.Api.Management.Services.Signs;
57
using Umbraco.Cms.Api.Management.ViewModels.Tree;
68
using Umbraco.Cms.Core;
9+
using Umbraco.Cms.Core.DependencyInjection;
710
using Umbraco.Cms.Core.Models;
811
using Umbraco.Cms.Core.Models.Entities;
912
using Umbraco.Cms.Core.Services;
@@ -19,8 +22,17 @@ public class DataTypeTreeControllerBase : FolderTreeControllerBase<DataTypeTreeI
1922
{
2023
private readonly IDataTypeService _dataTypeService;
2124

25+
[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")]
2226
public DataTypeTreeControllerBase(IEntityService entityService, IDataTypeService dataTypeService)
23-
: base(entityService) =>
27+
: this(
28+
entityService,
29+
StaticServiceProvider.Instance.GetRequiredService<SignProviderCollection>(),
30+
dataTypeService)
31+
{
32+
}
33+
34+
public DataTypeTreeControllerBase(IEntityService entityService, SignProviderCollection signProviders, IDataTypeService dataTypeService)
35+
: base(entityService, signProviders) =>
2436
_dataTypeService = dataTypeService;
2537

2638
protected override UmbracoObjectTypes ItemObjectType => UmbracoObjectTypes.DataType;

src/Umbraco.Cms.Api.Management/Controllers/DataType/Tree/RootDataTypeTreeController.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1-
using Asp.Versioning;
1+
using Asp.Versioning;
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.AspNetCore.Mvc;
44
using Umbraco.Cms.Core.Services;
55
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
6-
using Umbraco.Cms.Api.Management.ViewModels.DataType.Item;
76
using Umbraco.Cms.Api.Management.ViewModels.Tree;
7+
using Microsoft.Extensions.DependencyInjection;
8+
using Umbraco.Cms.Api.Management.Services.Signs;
89

910
namespace Umbraco.Cms.Api.Management.Controllers.DataType.Tree;
1011

1112
[ApiVersion("1.0")]
1213
public class RootDataTypeTreeController : DataTypeTreeControllerBase
1314
{
15+
[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")]
1416
public RootDataTypeTreeController(IEntityService entityService, IDataTypeService dataTypeService)
1517
: base(entityService, dataTypeService)
1618
{
1719
}
1820

21+
[ActivatorUtilitiesConstructor]
22+
public RootDataTypeTreeController(IEntityService entityService, SignProviderCollection signProviders, IDataTypeService dataTypeService)
23+
: base(entityService, signProviders, dataTypeService)
24+
{
25+
}
26+
1927
[HttpGet("root")]
2028
[MapToApiVersion("1.0")]
2129
[ProducesResponseType(typeof(PagedViewModel<DataTypeTreeItemResponseModel>), StatusCodes.Status200OK)]

src/Umbraco.Cms.Api.Management/Controllers/DataType/Tree/SiblingsDataTypeTreeController.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
using Microsoft.AspNetCore.Http;
22
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.DependencyInjection;
34
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
5+
using Umbraco.Cms.Api.Management.Services.Signs;
46
using Umbraco.Cms.Api.Management.ViewModels.Tree;
57
using Umbraco.Cms.Core.Services;
68

79
namespace Umbraco.Cms.Api.Management.Controllers.DataType.Tree;
810

911
public class SiblingsDataTypeTreeController : DataTypeTreeControllerBase
1012
{
13+
[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")]
1114
public SiblingsDataTypeTreeController(IEntityService entityService, IDataTypeService dataTypeService)
1215
: base(entityService, dataTypeService)
1316
{
1417
}
1518

19+
[ActivatorUtilitiesConstructor]
20+
public SiblingsDataTypeTreeController(IEntityService entityService, SignProviderCollection signProviders, IDataTypeService dataTypeService)
21+
: base(entityService, signProviders, dataTypeService)
22+
{
23+
}
24+
1625
[HttpGet("siblings")]
1726
[ProducesResponseType(typeof(SubsetViewModel<DataTypeTreeItemResponseModel>), StatusCodes.Status200OK)]
1827
public async Task<ActionResult<SubsetViewModel<DataTypeTreeItemResponseModel>>> Siblings(CancellationToken cancellationToken, Guid target, int before, int after, bool foldersOnly = false)

src/Umbraco.Cms.Api.Management/Controllers/Dictionary/Tree/AncestorsDictionaryTreeController.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.Signs;
46
using Umbraco.Cms.Api.Management.ViewModels.Tree;
57
using Umbraco.Cms.Core.Services;
68

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

20+
[ActivatorUtilitiesConstructor]
21+
public AncestorsDictionaryTreeController(IEntityService entityService, SignProviderCollection signProviders, IDictionaryItemService dictionaryItemService)
22+
: base(entityService, signProviders, dictionaryItemService)
23+
{
24+
}
25+
1726
[HttpGet("ancestors")]
1827
[MapToApiVersion("1.0")]
1928
[ProducesResponseType(typeof(IEnumerable<NamedEntityTreeItemResponseModel>), StatusCodes.Status200OK)]

src/Umbraco.Cms.Api.Management/Controllers/Dictionary/Tree/ChildrenDictionaryTreeController.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1-
using Asp.Versioning;
1+
using Asp.Versioning;
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.AspNetCore.Mvc;
4-
using Umbraco.Cms.Core.Models;
5-
using Umbraco.Cms.Core.Services;
4+
using Microsoft.Extensions.DependencyInjection;
65
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
6+
using Umbraco.Cms.Api.Management.Services.Signs;
77
using Umbraco.Cms.Api.Management.ViewModels.Tree;
8+
using Umbraco.Cms.Core.Models;
9+
using Umbraco.Cms.Core.Services;
810

911
namespace Umbraco.Cms.Api.Management.Controllers.Dictionary.Tree;
1012

1113
[ApiVersion("1.0")]
1214
public class ChildrenDictionaryTreeController : DictionaryTreeControllerBase
1315
{
16+
[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")]
1417
public ChildrenDictionaryTreeController(IEntityService entityService, IDictionaryItemService dictionaryItemService)
1518
: base(entityService, dictionaryItemService)
1619
{
1720
}
1821

22+
[ActivatorUtilitiesConstructor]
23+
public ChildrenDictionaryTreeController(IEntityService entityService, SignProviderCollection signProviders, IDictionaryItemService dictionaryItemService)
24+
: base(entityService, signProviders, dictionaryItemService)
25+
{
26+
}
27+
1928
[HttpGet("children")]
2029
[MapToApiVersion("1.0")]
2130
[ProducesResponseType(typeof(PagedViewModel<NamedEntityTreeItemResponseModel>), StatusCodes.Status200OK)]

src/Umbraco.Cms.Api.Management/Controllers/Dictionary/Tree/DictionaryTreeControllerBase.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.DependencyInjection;
34
using Umbraco.Cms.Api.Management.Controllers.Tree;
45
using Umbraco.Cms.Api.Management.Routing;
6+
using Umbraco.Cms.Api.Management.Services.Signs;
57
using Umbraco.Cms.Api.Management.ViewModels;
68
using Umbraco.Cms.Api.Management.ViewModels.Tree;
79
using Umbraco.Cms.Core;
10+
using Umbraco.Cms.Core.DependencyInjection;
811
using Umbraco.Cms.Core.Models;
912
using Umbraco.Cms.Core.Services;
1013
using Umbraco.Cms.Web.Common.Authorization;
@@ -18,8 +21,17 @@ namespace Umbraco.Cms.Api.Management.Controllers.Dictionary.Tree;
1821
// tree controller base. We'll keep it though, in the hope that we can mend EntityService.
1922
public class DictionaryTreeControllerBase : NamedEntityTreeControllerBase<NamedEntityTreeItemResponseModel>
2023
{
24+
[Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 18.")]
2125
public DictionaryTreeControllerBase(IEntityService entityService, IDictionaryItemService dictionaryItemService)
22-
: base(entityService) =>
26+
: this(
27+
entityService,
28+
StaticServiceProvider.Instance.GetRequiredService<SignProviderCollection>(),
29+
dictionaryItemService)
30+
{
31+
}
32+
33+
public DictionaryTreeControllerBase(IEntityService entityService, SignProviderCollection signProviders, IDictionaryItemService dictionaryItemService)
34+
: base(entityService, signProviders) =>
2335
DictionaryItemService = dictionaryItemService;
2436

2537
// dictionary items do not currently have a known UmbracoObjectType, so we'll settle with Unknown for now

src/Umbraco.Cms.Api.Management/Controllers/Dictionary/Tree/RootDictionaryTreeController.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using Asp.Versioning;
1+
using Asp.Versioning;
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.AspNetCore.Mvc;
4-
using Umbraco.Cms.Core.Models;
5-
using Umbraco.Cms.Core.Services;
4+
using Microsoft.Extensions.DependencyInjection;
65
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
6+
using Umbraco.Cms.Api.Management.Services.Signs;
77
using Umbraco.Cms.Api.Management.ViewModels.Tree;
8+
using Umbraco.Cms.Core.Models;
9+
using Umbraco.Cms.Core.Services;
810

911
namespace Umbraco.Cms.Api.Management.Controllers.Dictionary.Tree;
1012

@@ -16,6 +18,12 @@ public RootDictionaryTreeController(IEntityService entityService, IDictionaryIte
1618
{
1719
}
1820

21+
[ActivatorUtilitiesConstructor]
22+
public RootDictionaryTreeController(IEntityService entityService, SignProviderCollection signProviders, IDictionaryItemService dictionaryItemService)
23+
: base(entityService, signProviders, dictionaryItemService)
24+
{
25+
}
26+
1927
[HttpGet("root")]
2028
[MapToApiVersion("1.0")]
2129
[ProducesResponseType(typeof(PagedViewModel<NamedEntityTreeItemResponseModel>), StatusCodes.Status200OK)]

0 commit comments

Comments
 (0)