-
Notifications
You must be signed in to change notification settings - Fork 75
Fix: #870 - Migrate Filter and StartNodeId values for pickers from v13 #873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9614096
Fix: #870 - Migrate Filter and StartNodeId values for pickers from v13
KevinJump 69aacc9
Update uSync.Core/DataTypes/PickerConfigurationSerializerBase.cs
KevinJump 682154c
Update uSync.Core/DataTypes/PickerConfigurationSerializerBase.cs
KevinJump 2e10039
Update uSync.Core/Mapping/Mappers/MediaPicker3Mapper.cs
KevinJump 48876f3
Update uSync.Core/DataTypes/PickerConfigurationSerializerBase.cs
KevinJump 808cc32
revert mapper service injection (not required)
KevinJump 95c2c1b
Add test coverage for MediaPickerConfigSerializer v13 migration logic…
Copilot 1a841ac
Add migration tests for ContentPicker and MediaPicker configuration s…
Copilot 4f7fb4d
fixup richtext tst
KevinJump File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
uSync.Core/DataTypes/DataTypeSerializers/ContentPickerConfigSerializer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using Umbraco.Cms.Core; | ||
| using Umbraco.Cms.Core.Models; | ||
| using Umbraco.Cms.Core.Services; | ||
|
|
||
| namespace uSync.Core.DataTypes.DataTypeSerializers; | ||
|
|
||
| internal class ContentPickerConfigSerializer : PickerConfigurationSerializerBase<IContentType>, IConfigurationSerializer | ||
| { | ||
| private readonly IContentTypeService _contentTypeService; | ||
| public ContentPickerConfigSerializer(IContentTypeService contentTypeService) | ||
| { | ||
| _contentTypeService = contentTypeService; | ||
| } | ||
| public string Name => nameof(ContentPickerConfigSerializer); | ||
| public string[] Editors => [Constants.PropertyEditors.Aliases.ContentPicker]; | ||
|
|
||
| protected override IContentType? GetByAlias(string alias) | ||
| => _contentTypeService.Get(alias); | ||
| } | ||
22 changes: 16 additions & 6 deletions
22
uSync.Core/DataTypes/DataTypeSerializers/MediaPickerConfigSerializer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,32 @@ | ||
| using Umbraco.Cms.Core; | ||
| using Umbraco.Cms.Core.Models; | ||
| using Umbraco.Cms.Core.Services; | ||
| using Umbraco.Extensions; | ||
| using uSync.Core.Extensions; | ||
|
|
||
| namespace uSync.Core.DataTypes.DataTypeSerializers; | ||
| internal class MediaPickerConfigSerializer : ConfigurationSerializerBase, IConfigurationSerializer | ||
| internal class MediaPickerConfigSerializer : PickerConfigurationSerializerBase<IMediaType>, IConfigurationSerializer | ||
| { | ||
| private readonly IMediaTypeService _mediaTypeService; | ||
|
|
||
| public MediaPickerConfigSerializer(IMediaTypeService mediaTypeService) | ||
| { | ||
| _mediaTypeService = mediaTypeService; | ||
| } | ||
|
|
||
| public string Name => nameof(MediaPickerConfigSerializer); | ||
|
|
||
| public string[] Editors => [ | ||
| "Umbraco.MediaPicker", | ||
| "Umbraco.MediaPicker2"]; | ||
| "Umbraco.MediaPicker2", | ||
| "Umbraco.MediaPicker3"]; | ||
|
|
||
| /// <summary> | ||
| /// we migrate this one, from "Umbraco.MediaPicker" to "Umbraco.MediaPicker3" | ||
| /// </summary> | ||
| public string? GetEditorAlias() | ||
| => Constants.PropertyEditors.Aliases.MediaPicker3; | ||
|
|
||
| public override IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration) | ||
| { | ||
| return base.GetConfigurationImport(configuration); | ||
| } | ||
| protected override IMediaType? GetByAlias(string alias) | ||
| => _mediaTypeService.Get(alias); | ||
| } | ||
KevinJump marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| using Umbraco.Cms.Core; | ||
| using Umbraco.Cms.Core.Models; | ||
| using Umbraco.Extensions; | ||
|
|
||
| namespace uSync.Core.DataTypes; | ||
|
|
||
| internal abstract class PickerConfigurationSerializerBase<TContentType> : ConfigurationSerializerBase | ||
| where TContentType : IContentTypeBase | ||
| { | ||
| public override IDictionary<string, object> GetConfigurationImport(IDictionary<string, object> configuration) | ||
| { | ||
| if (configuration.TryGetValue("filter", out var filterValue) is true) | ||
| configuration["filter"] = ConvertAliasesToGuidValues(filterValue) ?? filterValue; | ||
|
|
||
| if (configuration.TryGetValue("startNodeId", out var startNodeValue) is true) | ||
| configuration["startNodeId"] = ConvertUdiToGuid(startNodeValue) ?? startNodeValue; | ||
|
|
||
| return base.GetConfigurationImport(configuration); | ||
| } | ||
|
|
||
| protected abstract TContentType? GetByAlias(string alias); | ||
| protected string? ConvertAliasesToGuidValues(object? filterValue) | ||
| { | ||
| var item = filterValue?.ToString(); | ||
| if (string.IsNullOrWhiteSpace(item) || item.Equals("null", System.StringComparison.OrdinalIgnoreCase)) return item; | ||
|
|
||
| List<string> result = []; | ||
|
|
||
| foreach (var value in item.ToDelimitedList()) | ||
| { | ||
| // if this item is already a guid, we return it. | ||
| if (Guid.TryParse(value, out _) is true) | ||
| { | ||
| result.Add(value); | ||
| continue; | ||
| } | ||
|
|
||
| // Lookup the content type by alias - return the guid. | ||
| var mediaType = GetByAlias(value); | ||
| if (mediaType != null) | ||
| { | ||
| result.Add(mediaType.Key.ToString()); | ||
| continue; | ||
| } | ||
|
|
||
| result.Add(value); | ||
| } | ||
|
|
||
| return string.Join(',', result); | ||
| } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// converts a string from UDI to Guid (if they are set) | ||
| /// </summary> | ||
| protected static string? ConvertUdiToGuid(object? idValue) | ||
| { | ||
| var id = idValue?.ToString(); | ||
|
|
||
| if (string.IsNullOrWhiteSpace(id)) return id; | ||
| if (Guid.TryParse(id, out _) is true) return id; | ||
|
|
||
| if (UdiParser.TryParse(id, out GuidUdi? guidUdi) is false || guidUdi is null) | ||
| return id; | ||
|
|
||
| return guidUdi.Guid.ToString(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| using System.Text.Json.Nodes; | ||
|
|
||
| using Umbraco.Cms.Core; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| using System; | ||
|
|
||
| using Moq; | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| using Umbraco.Cms.Core.Models; | ||
| using Umbraco.Cms.Core.Services; | ||
|
|
||
| using uSync.Core.DataTypes.DataTypeSerializers; | ||
|
|
||
| namespace uSync.Tests.Migrations; | ||
|
|
||
| [TestFixture] | ||
| internal class ContentPickerMigrationTests : MigrationTestBase | ||
| { | ||
| private ContentPickerConfigSerializer _serializer; | ||
| private Mock<IContentTypeService> _contentTypeServiceMock; | ||
|
|
||
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| _contentTypeServiceMock = new Mock<IContentTypeService>(); | ||
| _serializer = new ContentPickerConfigSerializer(_contentTypeServiceMock.Object); | ||
| } | ||
|
|
||
| [Test] | ||
| public void FilterMigrationFromAliasToGuid() | ||
| { | ||
| // Arrange | ||
| var contentTypeGuid = Guid.Parse("a1b2c3d4-e5f6-7890-abcd-ef1234567890"); | ||
| var contentTypeMock = new Mock<IContentType>(); | ||
| contentTypeMock.Setup(x => x.Key).Returns(contentTypeGuid); | ||
|
|
||
| _contentTypeServiceMock | ||
| .Setup(x => x.Get("myContentType")) | ||
| .Returns(contentTypeMock.Object); | ||
|
|
||
| var source = @"{ | ||
| ""filter"": ""myContentType"", | ||
| ""ignoreUserStartNodes"": false | ||
| }"; | ||
|
|
||
| var target = @"{ | ||
| ""filter"": ""a1b2c3d4-e5f6-7890-abcd-ef1234567890"", | ||
| ""ignoreUserStartNodes"": false | ||
| }"; | ||
|
|
||
| // Act & Assert | ||
| TestSerializerPropertyMigration(_serializer, source, target); | ||
| } | ||
|
|
||
| [Test] | ||
| public void FilterMigrationAlreadyGuid() | ||
| { | ||
| // Arrange - filter is already a GUID, should not change | ||
| var source = @"{ | ||
| ""filter"": ""a1b2c3d4-e5f6-7890-abcd-ef1234567890"", | ||
| ""ignoreUserStartNodes"": false | ||
| }"; | ||
|
|
||
| var target = @"{ | ||
| ""filter"": ""a1b2c3d4-e5f6-7890-abcd-ef1234567890"", | ||
| ""ignoreUserStartNodes"": false | ||
| }"; | ||
|
|
||
| // Act & Assert | ||
| TestSerializerPropertyMigration(_serializer, source, target); | ||
| } | ||
|
|
||
| [Test] | ||
| public void FilterMigrationMultipleAliasesToGuids() | ||
| { | ||
| // Arrange | ||
| var contentType1Guid = Guid.Parse("11111111-1111-1111-1111-111111111111"); | ||
| var contentType2Guid = Guid.Parse("22222222-2222-2222-2222-222222222222"); | ||
| var contentType3Guid = Guid.Parse("33333333-3333-3333-3333-333333333333"); | ||
|
|
||
| var contentType1Mock = new Mock<IContentType>(); | ||
| contentType1Mock.Setup(x => x.Key).Returns(contentType1Guid); | ||
|
|
||
| var contentType2Mock = new Mock<IContentType>(); | ||
| contentType2Mock.Setup(x => x.Key).Returns(contentType2Guid); | ||
|
|
||
| var contentType3Mock = new Mock<IContentType>(); | ||
| contentType3Mock.Setup(x => x.Key).Returns(contentType3Guid); | ||
|
|
||
| _contentTypeServiceMock | ||
| .Setup(x => x.Get("contentTypeOne")) | ||
| .Returns(contentType1Mock.Object); | ||
|
|
||
| _contentTypeServiceMock | ||
| .Setup(x => x.Get("contentTypeTwo")) | ||
| .Returns(contentType2Mock.Object); | ||
|
|
||
| _contentTypeServiceMock | ||
| .Setup(x => x.Get("contentTypeThree")) | ||
| .Returns(contentType3Mock.Object); | ||
|
|
||
| var source = @"{ | ||
| ""filter"": ""contentTypeOne,contentTypeTwo,contentTypeThree"", | ||
| ""ignoreUserStartNodes"": false | ||
| }"; | ||
|
|
||
| var target = @"{ | ||
| ""filter"": ""11111111-1111-1111-1111-111111111111,22222222-2222-2222-2222-222222222222,33333333-3333-3333-3333-333333333333"", | ||
| ""ignoreUserStartNodes"": false | ||
| }"; | ||
|
|
||
| // Act & Assert | ||
| TestSerializerPropertyMigration(_serializer, source, target); | ||
| } | ||
|
|
||
| [Test] | ||
| public void FilterMigrationMixedAliasesAndGuids() | ||
| { | ||
| // Arrange - mix of aliases and GUIDs | ||
| var contentType1Guid = Guid.Parse("11111111-1111-1111-1111-111111111111"); | ||
|
|
||
| var contentType1Mock = new Mock<IContentType>(); | ||
| contentType1Mock.Setup(x => x.Key).Returns(contentType1Guid); | ||
|
|
||
| _contentTypeServiceMock | ||
| .Setup(x => x.Get("contentTypeOne")) | ||
| .Returns(contentType1Mock.Object); | ||
|
|
||
| var source = @"{ | ||
| ""filter"": ""contentTypeOne,22222222-2222-2222-2222-222222222222"", | ||
| ""ignoreUserStartNodes"": false | ||
| }"; | ||
|
|
||
| var target = @"{ | ||
| ""filter"": ""11111111-1111-1111-1111-111111111111,22222222-2222-2222-2222-222222222222"", | ||
| ""ignoreUserStartNodes"": false | ||
| }"; | ||
|
|
||
| // Act & Assert | ||
| TestSerializerPropertyMigration(_serializer, source, target); | ||
| } | ||
|
|
||
| [Test] | ||
| public void StartNodeIdMigrationFromUdiToGuid() | ||
| { | ||
| // Arrange | ||
| var source = @"{ | ||
| ""ignoreUserStartNodes"": false, | ||
| ""startNodeId"": ""umb://document/a1b2c3d4e5f67890abcdef1234567890"" | ||
| }"; | ||
|
|
||
| var target = @"{ | ||
| ""ignoreUserStartNodes"": false, | ||
| ""startNodeId"": ""a1b2c3d4-e5f6-7890-abcd-ef1234567890"" | ||
| }"; | ||
|
|
||
| // Act & Assert | ||
| TestSerializerPropertyMigration(_serializer, source, target); | ||
| } | ||
|
|
||
| [Test] | ||
| public void StartNodeIdMigrationAlreadyGuid() | ||
| { | ||
| // Arrange - startNodeId is already a GUID, should not change | ||
| var source = @"{ | ||
| ""ignoreUserStartNodes"": false, | ||
| ""startNodeId"": ""a1b2c3d4-e5f6-7890-abcd-ef1234567890"" | ||
| }"; | ||
|
|
||
| var target = @"{ | ||
| ""ignoreUserStartNodes"": false, | ||
| ""startNodeId"": ""a1b2c3d4-e5f6-7890-abcd-ef1234567890"" | ||
| }"; | ||
|
|
||
| // Act & Assert | ||
| TestSerializerPropertyMigration(_serializer, source, target); | ||
| } | ||
|
|
||
| [Test] | ||
| public void StartNodeIdMigrationEmpty() | ||
| { | ||
| // Arrange - empty startNodeId should remain empty | ||
| var source = @"{ | ||
| ""ignoreUserStartNodes"": false, | ||
| ""startNodeId"": """" | ||
| }"; | ||
|
|
||
| var target = @"{ | ||
| ""ignoreUserStartNodes"": false, | ||
| ""startNodeId"": """" | ||
| }"; | ||
|
|
||
| // Act & Assert | ||
| TestSerializerPropertyMigration(_serializer, source, target); | ||
| } | ||
|
|
||
| [Test] | ||
| public void FilterAndStartNodeIdMigrationTogether() | ||
| { | ||
| // Arrange - test both filter and startNodeId migration in the same config | ||
| var contentTypeGuid = Guid.Parse("a1b2c3d4-e5f6-7890-abcd-ef1234567890"); | ||
| var contentTypeMock = new Mock<IContentType>(); | ||
| contentTypeMock.Setup(x => x.Key).Returns(contentTypeGuid); | ||
|
|
||
| _contentTypeServiceMock | ||
| .Setup(x => x.Get("myContentType")) | ||
| .Returns(contentTypeMock.Object); | ||
|
|
||
| var source = @"{ | ||
| ""filter"": ""myContentType"", | ||
| ""ignoreUserStartNodes"": false, | ||
| ""startNodeId"": ""umb://document/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"" | ||
| }"; | ||
|
|
||
| var target = @"{ | ||
| ""filter"": ""a1b2c3d4-e5f6-7890-abcd-ef1234567890"", | ||
| ""ignoreUserStartNodes"": false, | ||
| ""startNodeId"": ""bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"" | ||
| }"; | ||
|
|
||
| // Act & Assert | ||
| TestSerializerPropertyMigration(_serializer, source, target); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.