Fix member properties [#6227]

This commit is contained in:
Stephan
2019-08-29 15:12:53 +02:00
committed by Sebastiaan Janssen
parent e0d4168f3f
commit 280f4e7cbe
4 changed files with 89 additions and 13 deletions

View File

@@ -30,6 +30,16 @@
/// <remarks>Is used by <see cref="PublishedContentType"/> constructor to create special property types.</remarks>
IPublishedPropertyType CreatePropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations);
/// <summary>
/// Creates a core (non-user) published property type.
/// </summary>
/// <param name="contentType">The published content type owning the property.</param>
/// <param name="propertyTypeAlias">The property type alias.</param>
/// <param name="dataTypeId">The datatype identifier.</param>
/// <param name="variations">The variations.</param>
/// <remarks>Is used by <see cref="PublishedContentType"/> constructor to create special property types.</remarks>
IPublishedPropertyType CreateCorePropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations);
/// <summary>
/// Gets a published datatype.
/// </summary>

View File

@@ -92,26 +92,26 @@ namespace Umbraco.Core.Models.PublishedContent
{
var aliases = new HashSet<string>(propertyTypes.Select(x => x.Alias), StringComparer.OrdinalIgnoreCase);
foreach ((var alias, (var dataTypeId, var editorAlias)) in BuiltinMemberProperties)
foreach (var (alias, dataTypeId) in BuiltinMemberProperties)
{
if (aliases.Contains(alias)) continue;
propertyTypes.Add(factory.CreatePropertyType(this, alias, dataTypeId, ContentVariation.Nothing));
propertyTypes.Add(factory.CreateCorePropertyType(this, alias, dataTypeId, ContentVariation.Nothing));
}
}
// TODO: this list somehow also exists in constants, see memberTypeRepository => remove duplicate!
private static readonly Dictionary<string, (int, string)> BuiltinMemberProperties = new Dictionary<string, (int, string)>
private static readonly Dictionary<string, int> BuiltinMemberProperties = new Dictionary<string, int>
{
{ "Email", (Constants.DataTypes.Textbox, Constants.PropertyEditors.Aliases.TextBox) },
{ "Username", (Constants.DataTypes.Textbox, Constants.PropertyEditors.Aliases.TextBox) },
{ "PasswordQuestion", (Constants.DataTypes.Textbox, Constants.PropertyEditors.Aliases.TextBox) },
{ "Comments", (Constants.DataTypes.Textbox, Constants.PropertyEditors.Aliases.TextBox) },
{ "IsApproved", (Constants.DataTypes.Boolean, Constants.PropertyEditors.Aliases.Boolean) },
{ "IsLockedOut", (Constants.DataTypes.Boolean, Constants.PropertyEditors.Aliases.Boolean) },
{ "LastLockoutDate", (Constants.DataTypes.DateTime, Constants.PropertyEditors.Aliases.DateTime) },
{ "CreateDate", (Constants.DataTypes.DateTime, Constants.PropertyEditors.Aliases.DateTime) },
{ "LastLoginDate", (Constants.DataTypes.DateTime, Constants.PropertyEditors.Aliases.DateTime) },
{ "LastPasswordChangeDate", (Constants.DataTypes.DateTime, Constants.PropertyEditors.Aliases.DateTime) },
{ "Email", Constants.DataTypes.Textbox },
{ "Username", Constants.DataTypes.Textbox },
{ "PasswordQuestion", Constants.DataTypes.Textbox },
{ "Comments", Constants.DataTypes.Textbox },
{ "IsApproved", Constants.DataTypes.Boolean },
{ "IsLockedOut", Constants.DataTypes.Boolean },
{ "LastLockoutDate", Constants.DataTypes.DateTime },
{ "CreateDate", Constants.DataTypes.DateTime },
{ "LastLoginDate", Constants.DataTypes.DateTime },
{ "LastPasswordChangeDate", Constants.DataTypes.DateTime },
};
#region Content type

View File

@@ -61,6 +61,12 @@ namespace Umbraco.Core.Models.PublishedContent
return new PublishedPropertyType(contentType, propertyTypeAlias, dataTypeId, true, variations, _propertyValueConverters, _publishedModelFactory, this);
}
/// <inheritdoc />
public IPublishedPropertyType CreateCorePropertyType(IPublishedContentType contentType, string propertyTypeAlias, int dataTypeId, ContentVariation variations = ContentVariation.Nothing)
{
return new PublishedPropertyType(contentType, propertyTypeAlias, dataTypeId, false, variations, _propertyValueConverters, _publishedModelFactory, this);
}
/// <summary>
/// This method is for tests and is not intended to be used directly from application code.
/// </summary>

View File

@@ -11,15 +11,20 @@ using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
using Umbraco.Core.Persistence.Dtos;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using Umbraco.Tests.LegacyXmlPublishedCache;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Tests.Testing;
using Umbraco.Tests.Testing.Objects.Accessors;
using Umbraco.Web;
using Umbraco.Web.PublishedCache.NuCache;
using Umbraco.Web.Security.Providers;
namespace Umbraco.Tests.Services
@@ -43,6 +48,61 @@ namespace Umbraco.Tests.Services
((MemberService)ServiceContext.MemberService).MembershipProvider = provider;
}
[Test]
public void Can_Create_Member_With_Properties()
{
var memberType = ServiceContext.MemberTypeService.Get("member");
IMember member = new Member("xname", "xemail", "xusername", "xrawpassword", memberType, true);
ServiceContext.MemberService.Save(member);
member = ServiceContext.MemberService.GetById(member.Id);
Assert.AreEqual("xemail", member.Email);
var dataTypeService = ServiceContext.DataTypeService;
var contentTypeFactory = new PublishedContentTypeFactory(new NoopPublishedModelFactory(), new PropertyValueConverterCollection(Enumerable.Empty<IPropertyValueConverter>()), dataTypeService);
var pmemberType = new PublishedContentType(memberType, contentTypeFactory);
var publishedSnapshotAccessor = new TestPublishedSnapshotAccessor();
var variationContextAccessor = new TestVariationContextAccessor();
var pmember = PublishedMember.Create(member, pmemberType, false, publishedSnapshotAccessor, variationContextAccessor);
// contains the umbracoMember... properties created when installing, on the member type
// contains the other properties, that PublishedContentType adds (BuiltinMemberProperties)
//
// TODO: see TODO in PublishedContentType, this list contains duplicates
var aliases = new[]
{
"umbracoMemberPasswordRetrievalQuestion",
"umbracoMemberPasswordRetrievalAnswer",
"umbracoMemberComments",
"umbracoMemberFailedPasswordAttempts",
"umbracoMemberApproved",
"umbracoMemberLockedOut",
"umbracoMemberLastLockoutDate",
"umbracoMemberLastLogin",
"umbracoMemberLastPasswordChangeDate",
"Email",
"Username",
"PasswordQuestion",
"Comments",
"IsApproved",
"IsLockedOut",
"LastLockoutDate",
"CreateDate",
"LastLoginDate",
"LastPasswordChangeDate"
};
var properties = pmember.Properties.ToList();
for (var i = 0; i < aliases.Length; i++)
Assert.AreEqual(properties[i].Alias, aliases[i]);
var email = properties[aliases.IndexOf("Email")];
Assert.AreEqual("xemail", email.GetSourceValue());
}
[Test]
public void Can_Set_Password_On_New_Member()
{