Fixes: U4-3558 members tree syncing is a bit strange and not showing the selected member
This commit is contained in:
@@ -54,6 +54,16 @@ namespace Umbraco.Web.Editors
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure all GUIDs are formatted without hyphens
|
||||
/// </summary>
|
||||
/// <param name="controllerContext"></param>
|
||||
protected override void Initialize(System.Web.Http.Controllers.HttpControllerContext controllerContext)
|
||||
{
|
||||
base.Initialize(controllerContext);
|
||||
controllerContext.SetOutgoingNoHyphenGuidFormat();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the currently configured membership scenario for members in umbraco
|
||||
/// </summary>
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Umbraco.Web.Models.Mapping
|
||||
.ForMember(member => member.CreateDate, expression => expression.MapFrom(user => user.CreationDate))
|
||||
.ForMember(member => member.UpdateDate, expression => expression.MapFrom(user => user.LastActivityDate))
|
||||
.ForMember(member => member.LastPasswordChangeDate, expression => expression.MapFrom(user => user.LastPasswordChangedDate))
|
||||
.ForMember(member => member.Key, expression => expression.MapFrom(user => user.ProviderUserKey.TryConvertTo<Guid>().Result))
|
||||
.ForMember(member => member.Key, expression => expression.MapFrom(user => user.ProviderUserKey.TryConvertTo<Guid>().Result.ToString("N")))
|
||||
//This is a special case for password - we don't actually care what the password is but it either needs to be something or nothing
|
||||
// so we'll set it to something if the member is actually created, otherwise nothing if it is a new member.
|
||||
.ForMember(member => member.Password, expression => expression.MapFrom(user => user.CreationDate > DateTime.MinValue ? Guid.NewGuid().ToString("N") : ""))
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Umbraco.Web.Trees
|
||||
int total;
|
||||
nodes.AddRange(
|
||||
Membership.Provider.FindUsersByName(id + "%", 0, 9999, out total).Cast<MembershipUser>()
|
||||
.Select(m => CreateTreeNode(m.ProviderUserKey.ToString(), id, queryStrings, m.UserName, "icon-user")));
|
||||
.Select(m => CreateTreeNode(GetNodeIdForCustomProvider(m.ProviderUserKey), id, queryStrings, m.UserName, "icon-user")));
|
||||
}
|
||||
}
|
||||
else if (id == "others")
|
||||
@@ -75,6 +75,22 @@ namespace Umbraco.Web.Trees
|
||||
return nodes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// We'll see if it is a GUID, if so we'll ensure to format it without hyphens
|
||||
/// </summary>
|
||||
/// <param name="providerUserKey"></param>
|
||||
/// <returns></returns>
|
||||
private string GetNodeIdForCustomProvider(object providerUserKey)
|
||||
{
|
||||
if (providerUserKey == null) throw new ArgumentNullException("providerUserKey");
|
||||
var guidAttempt = providerUserKey.TryConvertTo<Guid>();
|
||||
if (guidAttempt.Success)
|
||||
{
|
||||
return guidAttempt.Result.ToString("N");
|
||||
}
|
||||
return providerUserKey.ToString();
|
||||
}
|
||||
|
||||
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
|
||||
{
|
||||
var menu = new MenuItemCollection();
|
||||
|
||||
@@ -655,6 +655,7 @@
|
||||
<Compile Include="WebApi\Filters\HttpQueryStringFilterAttribute.cs" />
|
||||
<Compile Include="WebApi\Filters\OutgoingDateTimeFormatAttribute.cs" />
|
||||
<Compile Include="WebApi\Filters\UmbracoApplicationAuthorizeAttribute.cs" />
|
||||
<Compile Include="WebApi\GuidNoHyphenConverter.cs" />
|
||||
<Compile Include="WebApi\HttpRequestMessageExtensions.cs" />
|
||||
<Compile Include="WebApi\MemberAuthorizeAttribute.cs" />
|
||||
<Compile Include="WebApi\UmbracoApiController.cs" />
|
||||
|
||||
@@ -5,6 +5,17 @@ namespace Umbraco.Web.WebApi
|
||||
{
|
||||
internal static class ControllerContextExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the JSON GUID format to not have hyphens
|
||||
/// </summary>
|
||||
/// <param name="controllerContext"></param>
|
||||
internal static void SetOutgoingNoHyphenGuidFormat(this HttpControllerContext controllerContext)
|
||||
{
|
||||
var jsonFormatter = controllerContext.Configuration.Formatters.JsonFormatter;
|
||||
jsonFormatter.SerializerSettings.Converters.Add(new GuidNoHyphenConverter());
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sets the JSON datetime format to be a custom one
|
||||
/// </summary>
|
||||
|
||||
40
src/Umbraco.Web/WebApi/GuidNoHyphenConverter.cs
Normal file
40
src/Umbraco.Web/WebApi/GuidNoHyphenConverter.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace Umbraco.Web.WebApi
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom converter for GUID's to format without hyphens
|
||||
/// </summary>
|
||||
internal class GuidNoHyphenConverter : JsonConverter
|
||||
{
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
switch (reader.TokenType)
|
||||
{
|
||||
case JsonToken.Null:
|
||||
return Guid.Empty;
|
||||
case JsonToken.String:
|
||||
var guidAttempt = reader.Value.TryConvertTo<Guid>();
|
||||
if (guidAttempt.Success)
|
||||
{
|
||||
return guidAttempt.Result;
|
||||
}
|
||||
throw new FormatException("Could not convert " + reader.Value + " to a GUID");
|
||||
default:
|
||||
throw new ArgumentException("Invalid token type");
|
||||
}
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
writer.WriteValue(Guid.Empty.Equals(value) ? "" : ((Guid) value).ToString("N"));
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return typeof(Guid) == objectType;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user