Puts back in some old APIs that were removed to maintain some backwards compat with < 7.7 for users

This commit is contained in:
Shannon
2017-07-25 18:39:23 +10:00
parent fa89bef11a
commit 17d17cfb82
8 changed files with 327 additions and 8 deletions

View File

@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
@@ -24,6 +26,12 @@ namespace Umbraco.Web.Models.ContentEditing
[DataMember(Name = "emailHash")]
public string EmailHash { get; set; }
[Obsolete("This should not be used it exists for legacy reasons only, use user groups instead, it will be removed in future versions")]
[EditorBrowsable(EditorBrowsableState.Never)]
[ReadOnly(true)]
[DataMember(Name = "userType")]
public string UserType { get; set; }
/// <summary>
/// Gets/sets the number of seconds for the user's auth ticket to expire
/// </summary>

View File

@@ -315,7 +315,34 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(
detail => detail.EmailHash,
opt => opt.MapFrom(user => user.Email.ToLowerInvariant().Trim().GenerateHash()))
.ForMember(detail => detail.SecondsUntilTimeout, opt => opt.Ignore());
.ForMember(detail => detail.SecondsUntilTimeout, opt => opt.Ignore())
.AfterMap((user, detail) =>
{
//we need to map the legacy UserType
//the best we can do here is to return the user's first user group as a IUserType object
//but we should attempt to return any group that is the built in ones first
var groups = user.Groups.ToArray();
if (groups.Length == 0)
{
//In backwards compatibility land, a user type cannot be null! so we need to return a fake one.
detail.UserType = "temp";
}
else
{
var builtIns = new[] { Constants.Security.AdminGroupAlias, "writer", "editor", "translator" };
var foundBuiltIn = groups.FirstOrDefault(x => builtIns.Contains(x.Alias));
if (foundBuiltIn != null)
{
detail.UserType = foundBuiltIn.Alias;
}
else
{
//otherwise return the first
detail.UserType = groups[0].Alias;
}
}
});
config.CreateMap<IProfile, UserProfile>()
.ForMember(detail => detail.UserId, opt => opt.MapFrom(profile => GetIntId(profile.Id)));