From 45b7458d2a39c86879f1bbabdfb6814e30d3713b Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Wed, 15 Jul 2020 16:17:54 +0100 Subject: [PATCH] Fix #142 - Member type property keys are ignored for built in types. --- uSync8.BackOffice/Config/uSync8.config | 2 +- .../Serializers/ContentTypeBaseSerializer.cs | 4 +- .../Serializers/MemberTypeSerializer.cs | 38 ++++++++++++++++++- uSync8.sln | 1 + 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/uSync8.BackOffice/Config/uSync8.config b/uSync8.BackOffice/Config/uSync8.config index 73ee981d..f1fe5979 100644 --- a/uSync8.BackOffice/Config/uSync8.config +++ b/uSync8.BackOffice/Config/uSync8.config @@ -21,7 +21,7 @@ - + diff --git a/uSync8.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs b/uSync8.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs index 5dab8aab..859eb1bd 100644 --- a/uSync8.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs +++ b/uSync8.Core/Serialization/Serializers/ContentTypeBaseSerializer.cs @@ -65,7 +65,7 @@ protected XElement SerializeTabs(TObject item) return tabs; } - protected XElement SerializeProperties(TObject item) + protected virtual XElement SerializeProperties(TObject item) { var node = new XElement("GenericProperties"); @@ -607,7 +607,7 @@ private void RemoveProperties(IContentTypeBase item, XElement properties) List removals = new List(); var nodes = properties.Elements("GenericProperty") - .Where(x => x.Element("Key") != null) + .Where(x => x.Element("Key").ValueOrDefault(Guid.Empty) != Guid.Empty) .Select(x => new { diff --git a/uSync8.Core/Serialization/Serializers/MemberTypeSerializer.cs b/uSync8.Core/Serialization/Serializers/MemberTypeSerializer.cs index e5947b3e..8d3cc393 100644 --- a/uSync8.Core/Serialization/Serializers/MemberTypeSerializer.cs +++ b/uSync8.Core/Serialization/Serializers/MemberTypeSerializer.cs @@ -1,6 +1,8 @@ using System; using System.Linq; using System.Xml.Linq; + +using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; @@ -18,7 +20,7 @@ public class MemberTypeSerializer : ContentTypeBaseSerializer, ISyn public MemberTypeSerializer( IEntityService entityService, ILogger logger, IDataTypeService dataTypeService, - IMemberTypeService memberTypeService) + IMemberTypeService memberTypeService) : base(entityService, logger, dataTypeService, memberTypeService, UmbracoObjectTypes.Unknown) { this.memberTypeService = memberTypeService; @@ -61,6 +63,39 @@ protected override void SerializeExtraProperties(XElement node, IMemberType item node.Add(new XElement("IsSensitive", item.IsSensitiveProperty(property.Alias))); } + // + // for the member type, the built in properties are created with guid's that are really int values + // as a result the Key value you get back for them, can change between reboots. + // + // here we tag on to the SerializeProperties step, and blank the Key value for any of the built in + // properties. + // + // this means we don't get false posistives between reboots, + // it also means that these properties won't get deleted if/when they are removed - but + // we limit it only to these items by listing them (so custom items in a member type will still + // get removed when required. + // + + private static string[] buildInProperties = new string[] { + "umbracoMemberApproved", "umbracoMemberComments", "umbracoMemberFailedPasswordAttempts", + "umbracoMemberLastLockoutDate", "umbracoMemberLastLogin", "umbracoMemberLastPasswordChangeDate", + "umbracoMemberLockedOut", "umbracoMemberPasswordRetrievalAnswer", "umbracoMemberPasswordRetrievalQuestion" + }; + + protected override XElement SerializeProperties(IMemberType item) + { + var node = base.SerializeProperties(item); + foreach(var property in node.Elements("GenericProperty")) + { + var alias = property.Element("Alias").ValueOrDefault(string.Empty); + if (!string.IsNullOrWhiteSpace(alias) && buildInProperties.InvariantContains(alias)) + { + property.Element("Key").Value = Guid.Empty.ToString(); + } + } + return node; + } + protected override SyncAttempt DeserializeCore(XElement node, SyncSerializerOptions options) { var item = FindOrCreate(node); @@ -85,7 +120,6 @@ protected override void DeserializeExtraProperties(IMemberType item, PropertyTyp item.SetMemberCanEditProperty(property.Alias, node.Element("CanEdit").ValueOrDefault(false)); item.SetMemberCanViewProperty(property.Alias, node.Element("CanView").ValueOrDefault(false)); item.SetIsSensitiveProperty(property.Alias, node.Element("IsSensitive").ValueOrDefault(true)); - } protected override IMemberType CreateItem(string alias, ITreeEntity parent, string extra) diff --git a/uSync8.sln b/uSync8.sln index 17eccc55..40470838 100644 --- a/uSync8.sln +++ b/uSync8.sln @@ -16,6 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionFiles", "SolutionFi Dist\package.cmd = Dist\package.cmd Dist\package.ContentEdition.xml = Dist\package.ContentEdition.xml Dist\package.xml = Dist\package.xml + Dist\pre-release.md = Dist\pre-release.md readme-content.txt = readme-content.txt readme.txt = readme.txt Dist\single.cmd = Dist\single.cmd