Skip to content

Commit

Permalink
Fix #142 - Member type property keys are ignored for built in types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jump committed Jul 15, 2020
1 parent c788b81 commit 45b7458
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion uSync8.BackOffice/Config/uSync8.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Handler Alias="languageHandler" Enabled="true" />
<Handler Alias="macroHandler" Enabled="true" />
<Handler Alias="mediaTypeHandler" Enabled="true" />
<Handler Alias="memberTypeHandler" Enabled="true" />
<Handler Alias="memberTypeHandler" Enabled="false" />
<Handler Alias="templateHandler" Enabled="true" />
<Handler Alias="contentTypeHandler" Enabled="true" />
<Handler Alias="contentHandler" Enabled="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -607,7 +607,7 @@ private void RemoveProperties(IContentTypeBase item, XElement properties)
List<string> removals = new List<string>();

var nodes = properties.Elements("GenericProperty")
.Where(x => x.Element("Key") != null)
.Where(x => x.Element("Key").ValueOrDefault(Guid.Empty) != Guid.Empty)
.Select(x =>
new
{
Expand Down
38 changes: 36 additions & 2 deletions uSync8.Core/Serialization/Serializers/MemberTypeSerializer.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,7 +20,7 @@ public class MemberTypeSerializer : ContentTypeBaseSerializer<IMemberType>, ISyn
public MemberTypeSerializer(
IEntityService entityService, ILogger logger,
IDataTypeService dataTypeService,
IMemberTypeService memberTypeService)
IMemberTypeService memberTypeService)
: base(entityService, logger, dataTypeService, memberTypeService, UmbracoObjectTypes.Unknown)
{
this.memberTypeService = memberTypeService;
Expand Down Expand Up @@ -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<IMemberType> DeserializeCore(XElement node, SyncSerializerOptions options)
{
var item = FindOrCreate(node);
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions uSync8.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 45b7458

Please sign in to comment.