From 22b15a06f6f6f6f686c029ac02b40446c2d4a8a4 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 25 Feb 2014 02:10:25 +1100 Subject: [PATCH] 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. --- src/Umbraco.Core/Models/Member.cs | 12 +++++++++--- src/Umbraco.Tests/Services/MemberServiceTests.cs | 14 ++++++++++++++ src/umbraco.cms/businesslogic/member/Member.cs | 3 +-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/Models/Member.cs b/src/Umbraco.Core/Models/Member.cs index 99bf3827fe..4af0c79c13 100644 --- a/src/Umbraco.Core/Models/Member.cs +++ b/src/Umbraco.Core/Models/Member.cs @@ -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(); @@ -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 { diff --git a/src/Umbraco.Tests/Services/MemberServiceTests.cs b/src/Umbraco.Tests/Services/MemberServiceTests.cs index 527a7b9801..1e9f75b80f 100644 --- a/src/Umbraco.Tests/Services/MemberServiceTests.cs +++ b/src/Umbraco.Tests/Services/MemberServiceTests.cs @@ -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); + } + } } \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/member/Member.cs b/src/umbraco.cms/businesslogic/member/Member.cs index 923eb8ff10..fd34dcd123 100644 --- a/src/umbraco.cms/businesslogic/member/Member.cs +++ b/src/umbraco.cms/businesslogic/member/Member.cs @@ -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;