From a3bcc99ed07f58daac9d1e111eb76f47c7ee893c Mon Sep 17 00:00:00 2001 From: Zeegaan Date: Tue, 5 Jul 2022 08:41:55 +0200 Subject: [PATCH] Fix up so manifestParser can deserialize new property "supportsReadOnly" --- .../PropertyEditors/DataValueEditor.cs | 2 + .../Manifest/DataEditorConverter.cs | 10 ++++ .../Manifest/ManifestParserTests.cs | 57 +++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs index c75844bfa2..41389a165d 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs @@ -79,6 +79,8 @@ public class DataValueEditor : IDataValueEditor /// public virtual object? Configuration { get; set; } + public bool SupportsReadOnly { get; set; } + /// /// Gets the validator used to validate the special property type -level "required". /// diff --git a/src/Umbraco.Infrastructure/Manifest/DataEditorConverter.cs b/src/Umbraco.Infrastructure/Manifest/DataEditorConverter.cs index 70e05c3ff5..0af289876e 100644 --- a/src/Umbraco.Infrastructure/Manifest/DataEditorConverter.cs +++ b/src/Umbraco.Infrastructure/Manifest/DataEditorConverter.cs @@ -110,6 +110,11 @@ internal class DataEditorConverter : JsonReadConverter throw new InvalidOperationException("Missing 'editor' value."); } + if (jobject.Property("supportsReadOnly") is null) + { + jobject["supportsReadOnly"] = false; + } + // explicitly assign a value editor of type ValueEditor // (else the deserializer will try to read it before setting it) // (and besides it's an interface) @@ -204,6 +209,11 @@ internal class DataEditorConverter : JsonReadConverter jobject.Property("view")?.Remove(); } + if (jobject.Property("supportsReadOnly") is null) + { + jobject["supportsReadOnly"] = false; + } + // in the manifest, default configuration is named 'config', rename if (jobject["config"] is JObject config) { diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs index 43c0460511..03f635b2cd 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/ManifestParserTests.cs @@ -505,4 +505,61 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 Assert.IsFalse(manifest.AllowPackageTelemetry); } + + [Test] + public void CanParseManifest_ParameterEditors_SupportsReadOnly() + { + const string json = @"{'parameterEditors': [ + { + alias: 'parameter1', + name: 'My Parameter', + view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html', + supportsReadOnly: true + }]}"; + + + var manifest = _parser.ParseManifest(json); + Assert.IsTrue(manifest.ParameterEditors.FirstOrDefault().SupportsReadOnly); + } + + [Test] + public void CanParseManifest_PropertyEditors_SupportsReadOnly() + { + const string json = @"{'propertyEditors': [ + { + alias: 'Test.Test1', + name: 'Test 1', + supportsReadOnly: true, + editor: { + view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html', + valueType: 'int', + hideLabel: true, + validation: { + 'required': true, + 'Regex': '\\d*' + } + }, + prevalues: { + fields: [ + { + label: 'Some config 1', + key: 'key1', + view: '~/App_Plugins/MyPackage/PropertyEditors/Views/pre-val1.html', + validation: { + required: true + } + }, + { + label: 'Some config 2', + key: 'key2', + view: '~/App_Plugins/MyPackage/PropertyEditors/Views/pre-val2.html' + } + ] + } + }]}"; + + + var manifest = _parser.ParseManifest(json); + Assert.IsTrue(manifest.PropertyEditors.FirstOrDefault().SupportsReadOnly); + } }