V14: Add reserved fields to config endpoints (#15919)

* Add reserved fields to documents

* Add member configuration endpoint

* Add reserved field to media configuration

* Refactor to use service instead on hardcoded methods

* Clean up, aligning

* Update OpenApi

---------

Co-authored-by: Elitsa <elm@umbraco.dk>
This commit is contained in:
Nikolaj Geisle
2024-03-22 12:11:38 +01:00
committed by GitHub
parent 0ed65671bb
commit dd68a6da7f
17 changed files with 317 additions and 37 deletions

View File

@@ -35,6 +35,7 @@ public static class UmbracoBuilderExtensions
builder.Services.TryAddTransient(factory => new PublishedSnapshotServiceOptions());
builder.SetPublishedSnapshotService<PublishedSnapshotService>();
builder.Services.TryAddSingleton<IPublishedSnapshotStatus, PublishedSnapshotStatus>();
builder.Services.TryAddTransient<IReservedFieldNamesService, ReservedFieldNamesService>();
// replace this service since we want to improve the content/media
// mapping lookups if we are using nucache.

View File

@@ -0,0 +1,54 @@
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Services;
using Umbraco.Extensions;
namespace Umbraco.Cms.Infrastructure.PublishedCache;
internal class ReservedFieldNamesService : IReservedFieldNamesService
{
private readonly ContentPropertySettings _contentPropertySettings;
private readonly MemberPropertySettings _memberPropertySettings;
private readonly MediaPropertySettings _mediaPropertySettings;
public ReservedFieldNamesService(
IOptions<ContentPropertySettings> contentPropertySettings,
IOptions<MemberPropertySettings> memberPropertySettings,
IOptions<MediaPropertySettings> mediaPropertySettings)
{
_contentPropertySettings = contentPropertySettings.Value;
_memberPropertySettings = memberPropertySettings.Value;
_mediaPropertySettings = mediaPropertySettings.Value;
}
public ISet<string> GetDocumentReservedFieldNames()
{
var reservedProperties = typeof(IPublishedContent).GetPublicProperties().Select(x => x.Name).ToHashSet();
var reservedMethods = typeof(IPublishedContent).GetPublicMethods().Select(x => x.Name).ToHashSet();
reservedProperties.UnionWith(reservedMethods);
reservedProperties.UnionWith(_contentPropertySettings.ReservedFieldNames);
return reservedProperties;
}
public ISet<string> GetMediaReservedFieldNames()
{
var reservedProperties = typeof(IPublishedContent).GetPublicProperties().Select(x => x.Name).ToHashSet();
var reservedMethods = typeof(IPublishedContent).GetPublicMethods().Select(x => x.Name).ToHashSet();
reservedProperties.UnionWith(reservedMethods);
reservedProperties.UnionWith(_mediaPropertySettings.ReservedFieldNames);
return reservedProperties;
}
public ISet<string> GetMemberReservedFieldNames()
{
var reservedProperties = typeof(PublishedMember).GetPublicProperties().Select(x => x.Name).ToHashSet();
var reservedMethods = typeof(PublishedMember).GetPublicMethods().Select(x => x.Name).ToHashSet();
reservedProperties.UnionWith(reservedMethods);
reservedProperties.UnionWith(_memberPropertySettings.ReservedFieldNames);
return reservedProperties;
}
}