From a982df97a64452f17acb5b65c1b50cdf19b1f602 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Thu, 11 Apr 2024 10:42:22 +0200 Subject: [PATCH] Remove manifest validators (#16027) * Remove manifest validators * Remove "Configuration" from RegexValidator --- .../UmbracoBuilder.Collections.cs | 15 ----- .../IManifestValueValidator.cs | 13 ----- .../ManifestValueValidatorCollection.cs | 32 ---------- ...ManifestValueValidatorCollectionBuilder.cs | 8 --- .../Validators/DecimalValidator.cs | 5 +- .../Validators/DelimitedValueValidator.cs | 58 ------------------- .../Validators/EmailValidator.cs | 5 +- .../Validators/IntegerValidator.cs | 5 +- .../Validators/RegexValidator.cs | 33 +---------- .../Validators/RequiredValidator.cs | 5 +- 10 files changed, 6 insertions(+), 173 deletions(-) delete mode 100644 src/Umbraco.Core/PropertyEditors/IManifestValueValidator.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollection.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollectionBuilder.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Collections.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Collections.cs index 1fe9383ee3..a54e2acdc2 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Collections.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Collections.cs @@ -10,7 +10,6 @@ using Umbraco.Cms.Core.HealthChecks.NotificationMethods; using Umbraco.Cms.Core.Mapping; using Umbraco.Cms.Core.Media.EmbedProviders; using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.PropertyEditors.Validators; using Umbraco.Cms.Core.Routing; using Umbraco.Cms.Core.Snippets; using Umbraco.Cms.Core.Strings; @@ -69,13 +68,6 @@ public static partial class UmbracoBuilderExtensions builder.DataValueReferenceFactories(); builder.PropertyValueConverters().Append(builder.TypeLoader.GetTypes()); builder.UrlSegmentProviders().Append(); - builder.ManifestValueValidators() - .Add() - .Add() - .Add() - .Add() - .Add() - .Add(); builder.MediaUrlGenerators(); // register OEmbed providers - no type scanning - all explicit opt-in of adding types, IEmbedProvider is not IDiscoverable builder.EmbedProviders() @@ -212,13 +204,6 @@ public static partial class UmbracoBuilderExtensions public static UrlSegmentProviderCollectionBuilder UrlSegmentProviders(this IUmbracoBuilder builder) => builder.WithCollectionBuilder(); - /// - /// Gets the validators collection builder. - /// - /// The builder. - internal static ManifestValueValidatorCollectionBuilder ManifestValueValidators(this IUmbracoBuilder builder) - => builder.WithCollectionBuilder(); - /// /// Gets the content finders collection builder. /// diff --git a/src/Umbraco.Core/PropertyEditors/IManifestValueValidator.cs b/src/Umbraco.Core/PropertyEditors/IManifestValueValidator.cs deleted file mode 100644 index 31078649a5..0000000000 --- a/src/Umbraco.Core/PropertyEditors/IManifestValueValidator.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Defines a value validator that can be referenced in a manifest. -/// -/// If the manifest can be configured, then it should expose a Configuration property. -public interface IManifestValueValidator : IValueValidator -{ - /// - /// Gets the name of the validator. - /// - string ValidationName { get; } -} diff --git a/src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollection.cs b/src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollection.cs deleted file mode 100644 index f2a08076b9..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollection.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Umbraco.Cms.Core.Composing; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.PropertyEditors; - -public class ManifestValueValidatorCollection : BuilderCollectionBase -{ - public ManifestValueValidatorCollection(Func> items) - : base(items) - { - } - - public IManifestValueValidator? Create(string name) - { - IManifestValueValidator v = GetByName(name); - - // TODO: what is this exactly? - // we cannot return this instance, need to clone it? - return (IManifestValueValidator?)Activator.CreateInstance(v.GetType()); // ouch - } - - public IManifestValueValidator GetByName(string name) - { - IManifestValueValidator? v = this.FirstOrDefault(x => x.ValidationName.InvariantEquals(name)); - if (v == null) - { - throw new InvalidOperationException($"Could not find a validator named \"{name}\"."); - } - - return v; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollectionBuilder.cs b/src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollectionBuilder.cs deleted file mode 100644 index 044c7f2c0c..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ManifestValueValidatorCollectionBuilder.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Umbraco.Cms.Core.Composing; - -namespace Umbraco.Cms.Core.PropertyEditors; - -public class ManifestValueValidatorCollectionBuilder : SetCollectionBuilderBase -{ - protected override ManifestValueValidatorCollectionBuilder This => this; -} diff --git a/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs index cc00b4614e..3dc3774d2f 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/DecimalValidator.cs @@ -6,11 +6,8 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators; /// /// A validator that validates that the value is a valid decimal /// -public sealed class DecimalValidator : IManifestValueValidator +public sealed class DecimalValidator : IValueValidator { - /// - public string ValidationName => "Decimal"; - /// public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { diff --git a/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs deleted file mode 100644 index 73907a4266..0000000000 --- a/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Text.RegularExpressions; - -namespace Umbraco.Cms.Core.PropertyEditors.Validators; - -/// -/// A validator that validates a delimited set of values against a common regex -/// -public sealed class DelimitedValueValidator : IManifestValueValidator -{ - /// - /// Gets or sets the configuration, when parsed as . - /// - public DelimitedValueValidatorConfig? Configuration { get; set; } - - /// - public string ValidationName => "Delimited"; - - /// - public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) - { - // TODO: localize these! - if (value != null) - { - var delimiter = Configuration?.Delimiter ?? ","; - Regex? regex = Configuration?.Pattern != null ? new Regex(Configuration.Pattern) : null; - - var stringVal = value.ToString(); - var split = stringVal!.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); - for (var i = 0; i < split.Length; i++) - { - var s = split[i]; - - // next if we have a regex statement validate with that - if (regex != null) - { - if (regex.IsMatch(s) == false) - { - yield return new ValidationResult( - "The item at index " + i + " did not match the expression " + regex, - new[] - { - // make the field name called 'value0' where 0 is the index - "value" + i, - }); - } - } - } - } - } -} - -public class DelimitedValueValidatorConfig -{ - public string? Delimiter { get; set; } - - public string? Pattern { get; set; } -} diff --git a/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs index 8b984dc533..69b7dafff9 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/EmailValidator.cs @@ -5,11 +5,8 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators; /// /// A validator that validates an email address /// -public sealed class EmailValidator : IManifestValueValidator +public sealed class EmailValidator : IValueValidator { - /// - public string ValidationName => "Email"; - /// public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { diff --git a/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs index 2123d213f6..4e344dffff 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/IntegerValidator.cs @@ -6,11 +6,8 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators; /// /// A validator that validates that the value is a valid integer /// -public sealed class IntegerValidator : IManifestValueValidator +public sealed class IntegerValidator : IValueValidator { - /// - public string ValidationName => "Integer"; - /// public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { diff --git a/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs index 5c7a172ec8..4e985937cc 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs @@ -10,7 +10,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators; /// /// A validator that validates that the value against a regular expression. /// -public sealed class RegexValidator : IValueFormatValidator, IManifestValueValidator +public sealed class RegexValidator : IValueFormatValidator, IValueValidator { private string _regex; @@ -31,9 +31,7 @@ public sealed class RegexValidator : IValueFormatValidator, IManifestValueValida /// /// /// Use this constructor when the validator is used as an , - /// and the regular expression is supplied at validation time. This constructor is also used when - /// the validator is used as an and the regular expression - /// is supplied via the method. + /// and the regular expression is supplied at validation time. /// public RegexValidator() : this(string.Empty) @@ -50,33 +48,6 @@ public sealed class RegexValidator : IValueFormatValidator, IManifestValueValida public RegexValidator(string regex) => _regex = regex; - /// - /// Gets or sets the configuration, when parsed as . - /// - public string Configuration - { - get => _regex; - set - { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException( - "Value can't be empty or consist only of white-space characters.", - nameof(value)); - } - - _regex = value; - } - } - - /// - public string ValidationName => "Regex"; - /// public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { diff --git a/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs index 33a7c45afe..6caa7593ab 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs @@ -7,7 +7,7 @@ namespace Umbraco.Cms.Core.PropertyEditors.Validators; /// /// A validator that validates that the value is not null or empty (if it is a string) /// -public sealed class RequiredValidator : IValueRequiredValidator, IManifestValueValidator +public sealed class RequiredValidator : IValueRequiredValidator, IValueValidator { [Obsolete($"Use the constructor that does not accept {nameof(ILocalizedTextService)}. Will be removed in V15.")] public RequiredValidator(ILocalizedTextService textService) @@ -19,9 +19,6 @@ public sealed class RequiredValidator : IValueRequiredValidator, IManifestValueV { } - /// - public string ValidationName => "Required"; - /// public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) => ValidateRequired(value, valueType);