diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/MetaFields.cs b/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/MetaFields.cs deleted file mode 100644 index c00de35d4..000000000 --- a/backend/src/Squidex.Domain.Apps.Core.Model/Schemas/MetaFields.cs +++ /dev/null @@ -1,46 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschraenkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using System.Collections.Generic; -using System.Reflection; - -namespace Squidex.Domain.Apps.Core.Schemas -{ - public static class MetaFields - { - private static readonly HashSet AllList = new HashSet(); - - public static ISet All - { - get { return AllList; } - } - - public static readonly string Id = "meta.id"; - public static readonly string Created = "meta.created"; - public static readonly string CreatedByAvatar = "meta.createdBy.avatar"; - public static readonly string CreatedByName = "meta.createdBy.name"; - public static readonly string LastModified = "meta.lastModified"; - public static readonly string LastModifiedByAvatar = "meta.lastModifiedBy.avatar"; - public static readonly string LastModifiedByName = "meta.lastModifiedBy.name"; - public static readonly string Status = "meta.status"; - public static readonly string StatusColor = "meta.status.color"; - public static readonly string Version = "meta.version"; - - static MetaFields() - { - foreach (var field in typeof(MetaFields).GetFields(BindingFlags.Public | BindingFlags.Static)) - { - if (field.FieldType == typeof(string)) - { - var value = field.GetValue(null) as string; - - AllList.Add(value!); - } - } - } - } -} diff --git a/backend/src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs b/backend/src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs index 173826c50..353f84e2d 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System; using System.Collections.Generic; using System.Linq; using Squidex.Domain.Apps.Core; @@ -113,8 +114,8 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards Validate.It(() => "Cannot configure UI fields.", e => { - ValidateFieldNames(schema, command.FieldsInLists, nameof(command.FieldsInLists), e, true); - ValidateFieldNames(schema, command.FieldsInReferences, nameof(command.FieldsInReferences), e); + ValidateFieldNames(schema, command.FieldsInLists, nameof(command.FieldsInLists), e, IsMetaField); + ValidateFieldNames(schema, command.FieldsInReferences, nameof(command.FieldsInReferences), e, IsNotAllowed); }); } @@ -162,8 +163,8 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards } } - ValidateFieldNames(command, command.FieldsInLists, nameof(command.FieldsInLists), e, true); - ValidateFieldNames(command, command.FieldsInReferences, nameof(command.FieldsInReferences), e); + ValidateFieldNames(command, command.FieldsInLists, nameof(command.FieldsInLists), e, IsMetaField); + ValidateFieldNames(command, command.FieldsInReferences, nameof(command.FieldsInReferences), e, IsNotAllowed); } private static void ValidateRootField(UpsertSchemaField field, UpsertCommand command, string prefix, AddValidation e) @@ -261,7 +262,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards } } - private static void ValidateFieldNames(Schema schema, FieldNames? fields, string path, AddValidation e, bool withMeta = false) + private static void ValidateFieldNames(Schema schema, FieldNames? fields, string path, AddValidation e, Func isAllowed) { if (fields != null) { @@ -279,7 +280,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards { e(Not.Defined("Field"), fieldPrefix); } - else if (field == null && (!withMeta || !MetaFields.All.Contains(fieldName))) + else if (field == null && !isAllowed(fieldName)) { e($"Field is not part of the schema.", fieldPrefix); } @@ -299,7 +300,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards } } - private static void ValidateFieldNames(UpsertCommand command, FieldNames? fields, string path, AddValidation e, bool withMeta = false) + private static void ValidateFieldNames(UpsertCommand command, FieldNames? fields, string path, AddValidation e, Func isAllowed) { if (fields != null) { @@ -317,7 +318,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards { e(Not.Defined("Field"), fieldPrefix); } - else if (field == null && (!withMeta || !MetaFields.All.Contains(fieldName))) + else if (field == null && !isAllowed(fieldName)) { e($"Field is not part of the schema.", fieldPrefix); } @@ -337,6 +338,16 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards } } + private static bool IsMetaField(string field) + { + return field.StartsWith("meta.", StringComparison.Ordinal); + } + + private static bool IsNotAllowed(string field) + { + return false; + } + private static void ValidateFieldIds(ReorderFields c, IReadOnlyDictionary fields, AddValidation e) { if (c.FieldIds != null && (c.FieldIds.Count != fields.Count || c.FieldIds.Any(x => !fields.ContainsKey(x))))