Fixes how member is approved is set by defaut and adds unit test for it. Also ensures that it returns true if the property value is invalid for whatever odd reason.

This commit is contained in:
Shannon
2014-02-25 02:10:25 +11:00
parent cb09795280
commit 22b15a06f6
3 changed files with 24 additions and 5 deletions

View File

@@ -31,6 +31,7 @@ namespace Umbraco.Core.Models
: base(name, -1, contentType, new PropertyCollection())
{
_contentType = contentType;
IsApproved = true;
}
//TODO: Should we just get rid of this one? no reason to have a level set.
@@ -43,6 +44,7 @@ namespace Umbraco.Core.Models
_email = email;
_username = username;
_password = password;
IsApproved = true;
}
public Member(string name, string email, string username, string password, IMemberType contentType)
@@ -54,6 +56,7 @@ namespace Umbraco.Core.Models
_email = email;
_username = username;
_password = password;
IsApproved = true;
}
//public Member(string name, string email, string username, string password, IContentBase parent, IMemberType contentType)
@@ -230,7 +233,9 @@ namespace Umbraco.Core.Models
{
get
{
var a = WarnIfPropertyTypeNotFoundOnGet(Constants.Conventions.Member.IsApproved, "IsApproved", true);
var a = WarnIfPropertyTypeNotFoundOnGet(Constants.Conventions.Member.IsApproved, "IsApproved",
//This is the default value if the prop is not found
true);
if (a.Success == false) return a.Result;
var tryConvert = Properties[Constants.Conventions.Member.IsApproved].Value.TryConvertTo<bool>();
@@ -238,7 +243,8 @@ namespace Umbraco.Core.Models
{
return tryConvert.Result;
}
return default(bool);
//if the property exists but it cannot be converted, we will assume true
return true;
}
set
{
@@ -270,7 +276,7 @@ namespace Umbraco.Core.Models
{
return tryConvert.Result;
}
return default(bool);
return false;
}
set
{

View File

@@ -961,5 +961,19 @@ namespace Umbraco.Tests.Services
Assert.IsNull(colResult.First().VarChar);
}
[Test]
public void New_Member_Approved_By_Default()
{
IMemberType memberType = MockedContentTypes.CreateSimpleMemberType();
ServiceContext.MemberTypeService.Save(memberType);
var customMember = MockedMember.CreateSimpleMember(memberType, "hello", "hello@test.com", "hello", "hello");
ServiceContext.MemberService.Save(customMember);
var found = ServiceContext.MemberService.GetById(customMember.Id);
Assert.IsTrue(found.IsApproved);
}
}
}

View File

@@ -228,9 +228,8 @@ namespace umbraco.cms.businesslogic.member
var model = ApplicationContext.Current.Services.MemberService.CreateMemberWithIdentity(
loginName, Email.ToLower(), "", mbt.MemberTypeItem);
model.Name = Name;
model.IsApproved = true;
//The content object will only have the 'WasCancelled' flag set to 'True' if the 'Creating' event has been cancelled, so we return null.
//The content object will only have the 'WasCancelled' flag set to 'True' if the 'Saving' event has been cancelled, so we return null.
if (((Entity)model).WasCancelled)
return null;