Skip to content

Commit

Permalink
Merge pull request #1447 from umbraco/temp-u4-8906
Browse files Browse the repository at this point in the history
U4-8906 - optimize member perfs
  • Loading branch information
Warren Buckley committed Sep 15, 2016
2 parents 61b1102 + 9e82b8d commit 5397f2c
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions src/Umbraco.Web/Models/Mapping/MemberModelMapper.cs
Expand Up @@ -183,7 +183,7 @@ private static void MapGenericCustomProperties(IMemberService memberService, IMe
var url = urlHelper.GetUmbracoApiService<MemberTreeController>(controller => controller.GetTreeNode(display.Key.ToString("N"), null));
display.TreeNodeUrl = url;
}

var genericProperties = new List<ContentPropertyDisplay>
{
new ContentPropertyDisplay
Expand Down Expand Up @@ -234,7 +234,7 @@ private static void MapGenericCustomProperties(IMemberService memberService, IMe


TabsAndPropertiesResolver.MapGenericProperties(member, display, localizedText, genericProperties);

//check if there's an approval field
var provider = membersProvider as global::umbraco.providers.members.UmbracoMembershipProvider;
if (member.HasIdentity == false && provider != null)
Expand All @@ -258,7 +258,7 @@ private static void MapGenericCustomProperties(IMemberService memberService, IMe
/// <returns></returns>
/// <remarks>
/// If the membership provider installed is the umbraco membership provider, then we will allow changing the username, however if
/// the membership provider is a custom one, we cannot allow chaning the username because MembershipProvider's do not actually natively
/// the membership provider is a custom one, we cannot allow chaning the username because MembershipProvider's do not actually natively
/// allow that.
/// </remarks>
internal static ContentPropertyDisplay GetLoginProperty(IMemberService memberService, IMember member, MemberDisplay display, ILocalizedTextService localizedText)
Expand All @@ -267,11 +267,11 @@ internal static ContentPropertyDisplay GetLoginProperty(IMemberService memberSer
{
Alias = string.Format("{0}login", Constants.PropertyEditors.InternalGenericPropertiesPrefix),
Label = localizedText.Localize("login"),
Value = display.Username
Value = display.Username
};

var scenario = memberService.GetMembershipScenario();

//only allow editing if this is a new member, or if the membership provider is the umbraco one
if (member.HasIdentity == false || scenario == MembershipScenario.NativeUmbraco)
{
Expand All @@ -287,20 +287,21 @@ internal static ContentPropertyDisplay GetLoginProperty(IMemberService memberSer

internal static IDictionary<string, bool> GetMemberGroupValue(string username)
{
var result = new Dictionary<string, bool>();
foreach (var role in Roles.GetAllRoles().Distinct())
{
var userRoles = username.IsNullOrWhiteSpace() ? null : Roles.GetRolesForUser(username);

// create a dictionary of all roles (except internal roles) + "false"
var result = Roles.GetAllRoles().Distinct()
// if a role starts with __umbracoRole we won't show it as it's an internal role used for public access
if (role.StartsWith(Constants.Conventions.Member.InternalRolePrefix) == false)
{
result.Add(role, false);
if (username.IsNullOrWhiteSpace()) continue;
if (Roles.IsUserInRole(username, role))
{
result[role] = true;
}
}
}
.Where(x => x.StartsWith(Constants.Conventions.Member.InternalRolePrefix) == false)
.ToDictionary(x => x, x => false);

// if user has no roles, just return the dictionary
if (userRoles == null) return result;

// else update the dictionary to "true" for the user roles (except internal roles)
foreach (var userRole in userRoles.Where(x => x.StartsWith(Constants.Conventions.Member.InternalRolePrefix) == false))
result[userRole] = true;

return result;
}

Expand All @@ -318,7 +319,7 @@ protected override IEnumerable<ContentPropertyDto> ResolveCore(IMember source)

//remove all membership properties, these values are set with the membership provider.
var exclude = defaultProps.Select(x => x.Value.Alias).ToArray();

return source.Properties
.Where(x => exclude.Contains(x.Alias) == false)
.Select(Mapper.Map<Property, ContentPropertyDto>);
Expand All @@ -331,7 +332,7 @@ protected override IEnumerable<ContentPropertyDto> ResolveCore(IMember source)
/// </summary>
/// <remarks>
/// This also ensures that the IsLocked out property is readonly when the member is not locked out - this is because
/// an admin cannot actually set isLockedOut = true, they can only unlock.
/// an admin cannot actually set isLockedOut = true, they can only unlock.
/// </remarks>
internal class MemberTabsAndPropertiesResolver : TabsAndPropertiesResolver
{
Expand Down Expand Up @@ -370,7 +371,7 @@ protected override IEnumerable<Tab<ContentPropertyDisplay>> ResolveCore(IContent
isLockedOutProperty.Value = _localizedTextService.Localize("general/no");
}

return result;
return result;
}
else
{
Expand All @@ -386,10 +387,10 @@ protected override IEnumerable<Tab<ContentPropertyDisplay>> ResolveCore(IContent
isLockedOutProperty.Value = _localizedTextService.Localize("general/no");
}

return result;
return result;
}


}
}

Expand Down Expand Up @@ -433,7 +434,7 @@ internal class MemberProviderFieldMappingResolver : ValueResolver<IMember, IDict
{Constants.Conventions.Member.IsLockedOut, Constants.Conventions.Member.IsLockedOut},
{Constants.Conventions.Member.IsApproved, Constants.Conventions.Member.IsApproved},
{Constants.Conventions.Member.Comments, Constants.Conventions.Member.Comments}
};
};
}
else
{
Expand All @@ -444,12 +445,12 @@ internal class MemberProviderFieldMappingResolver : ValueResolver<IMember, IDict
{Constants.Conventions.Member.IsLockedOut, umbracoProvider.LockPropertyTypeAlias},
{Constants.Conventions.Member.IsApproved, umbracoProvider.ApprovedPropertyTypeAlias},
{Constants.Conventions.Member.Comments, umbracoProvider.CommentPropertyTypeAlias}
};
};
}


}
}
}

}
}

0 comments on commit 5397f2c

Please sign in to comment.