From e0619edabb9964bd5998994b2b16af559c3817ce Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 14 Oct 2015 10:19:39 +0200 Subject: [PATCH 1/6] U4-6962 Public access in multiple levels is broken in 7.3 #U4-6962 Fixed --- src/Umbraco.Core/Services/PublicAccessService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Services/PublicAccessService.cs b/src/Umbraco.Core/Services/PublicAccessService.cs index 7dd35142d2..2f033740fa 100644 --- a/src/Umbraco.Core/Services/PublicAccessService.cs +++ b/src/Umbraco.Core/Services/PublicAccessService.cs @@ -121,7 +121,7 @@ namespace Umbraco.Core.Services if (entry == null) return Attempt>.Fail(); - var existingRule = entry.Rules.FirstOrDefault(x => x.RuleType == ruleType); + var existingRule = entry.Rules.FirstOrDefault(x => x.RuleType == ruleType && x.RuleValue == newRuleValue); if (existingRule == null) { entry.AddRule(newRuleValue, ruleType); From 62897f70640182a548d9ddf3344c76575f6012c1 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 14 Oct 2015 11:13:23 +0200 Subject: [PATCH 2/6] Test was wrong, 2 rules were added and was expecting 1 to be returned, now that the code is fixed, this test needs to be corrected --- src/Umbraco.Tests/Services/PublicAccessServiceTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs b/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs index 0768a38c7f..9b7cd196be 100644 --- a/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs +++ b/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs @@ -119,7 +119,7 @@ namespace Umbraco.Tests.Services // Assert Assert.IsTrue(updated.Success); Assert.AreEqual(OperationStatusType.Success, updated.Result.StatusType); - Assert.AreEqual(1, entry.Rules.Count()); + Assert.AreEqual(2, entry.Rules.Count()); Assert.AreEqual("AnotherVal", entry.Rules.ElementAt(0).RuleValue); } } From 65d421b6191a393436bc862ba43ce9f756c43e39 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 14 Oct 2015 11:32:55 +0200 Subject: [PATCH 3/6] Can_Update_Rule was wrong, it's not possible to "update" a rule, can only add or remove - added a test for removing --- .../Services/PublicAccessServiceTests.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs b/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs index 9b7cd196be..8f5a37376c 100644 --- a/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs +++ b/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs @@ -91,7 +91,7 @@ namespace Umbraco.Tests.Services } [Test] - public void Can_Update_Rule() + public void Can_Remove_Rule() { // Arrange var contentService = ServiceContext.ContentService; @@ -110,16 +110,17 @@ namespace Umbraco.Tests.Services }, }); publicAccessService.Save(entry); + publicAccessService.AddOrUpdateRule(c, "TestType", "AnotherVal"); // Act - var updated = publicAccessService.AddOrUpdateRule(c, "TestType", "AnotherVal"); + var removed = publicAccessService.RemoveRule(c, "TestType", "TestValue"); //re-get entry = publicAccessService.GetEntryForContent(c); // Assert - Assert.IsTrue(updated.Success); - Assert.AreEqual(OperationStatusType.Success, updated.Result.StatusType); - Assert.AreEqual(2, entry.Rules.Count()); + Assert.IsTrue(removed.Success); + Assert.AreEqual(OperationStatusType.Success, removed.Result.StatusType); + Assert.AreEqual(1, entry.Rules.Count()); Assert.AreEqual("AnotherVal", entry.Rules.ElementAt(0).RuleValue); } } From c514ce8da3086698af4c2dc04a5430a3eeba66b0 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 15 Oct 2015 17:06:00 +0200 Subject: [PATCH 4/6] Fixes: U4-7248 Can't update roles on public access, obsolete AddOrUpdateRule --- .../Services/IPublicAccessService.cs | 11 ++-- .../Services/PublicAccessService.cs | 23 +++++--- .../Services/PublicAccessServiceTests.cs | 53 ++++++++++++++++--- src/umbraco.cms/businesslogic/web/Access.cs | 10 ++-- 4 files changed, 76 insertions(+), 21 deletions(-) diff --git a/src/Umbraco.Core/Services/IPublicAccessService.cs b/src/Umbraco.Core/Services/IPublicAccessService.cs index 617a8f220d..7f7da72c62 100644 --- a/src/Umbraco.Core/Services/IPublicAccessService.cs +++ b/src/Umbraco.Core/Services/IPublicAccessService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using Umbraco.Core.Models; using Umbraco.Core.Security; @@ -42,14 +43,18 @@ namespace Umbraco.Core.Services /// Attempt IsProtected(string contentPath); + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Use AddRule instead, this method will be removed in future versions")] + Attempt> AddOrUpdateRule(IContent content, string ruleType, string ruleValue); + /// - /// Adds/updates a rule, if an entry doesn't exist one will be created with the new rule + /// Adds a rule if the entry doesn't already exist /// /// /// - /// + /// /// - Attempt> AddOrUpdateRule(IContent content, string ruleType, string newRuleValue); + Attempt> AddRule(IContent content, string ruleType, string ruleValue); /// /// Removes a rule diff --git a/src/Umbraco.Core/Services/PublicAccessService.cs b/src/Umbraco.Core/Services/PublicAccessService.cs index 2f033740fa..bb966309dc 100644 --- a/src/Umbraco.Core/Services/PublicAccessService.cs +++ b/src/Umbraco.Core/Services/PublicAccessService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using Umbraco.Core.Events; using Umbraco.Core.Logging; @@ -104,14 +105,21 @@ namespace Umbraco.Core.Services return Attempt.If(result != null, result); } + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete("Use AddRule instead, this method will be removed in future versions")] + public Attempt> AddOrUpdateRule(IContent content, string ruleType, string ruleValue) + { + return AddRule(content, ruleType, ruleValue); + } + /// - /// Adds/updates a rule + /// Adds a rule /// /// /// - /// + /// /// - public Attempt> AddOrUpdateRule(IContent content, string ruleType, string newRuleValue) + public Attempt> AddRule(IContent content, string ruleType, string ruleValue) { var evtMsgs = EventMessagesFactory.Get(); var uow = UowProvider.GetUnitOfWork(); @@ -121,15 +129,16 @@ namespace Umbraco.Core.Services if (entry == null) return Attempt>.Fail(); - var existingRule = entry.Rules.FirstOrDefault(x => x.RuleType == ruleType && x.RuleValue == newRuleValue); + var existingRule = entry.Rules.FirstOrDefault(x => x.RuleType == ruleType && x.RuleValue == ruleValue); if (existingRule == null) { - entry.AddRule(newRuleValue, ruleType); + entry.AddRule(ruleValue, ruleType); } else { - existingRule.RuleType = ruleType; - existingRule.RuleValue = newRuleValue; + //If they are both the same already then there's nothing to update, exit + return Attempt>.Succeed( + new OperationStatus(entry, OperationStatusType.Success, evtMsgs)); } if (Saving.IsRaisedEventCancelled( diff --git a/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs b/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs index 8f5a37376c..57fe377262 100644 --- a/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs +++ b/src/Umbraco.Tests/Services/PublicAccessServiceTests.cs @@ -80,7 +80,7 @@ namespace Umbraco.Tests.Services publicAccessService.Save(entry); // Act - var updated = publicAccessService.AddOrUpdateRule(c, "TestType2", "AnotherVal"); + var updated = publicAccessService.AddRule(c, "TestType2", "AnotherVal"); //re-get entry = publicAccessService.GetEntryForContent(c); @@ -90,6 +90,42 @@ namespace Umbraco.Tests.Services Assert.AreEqual(2, entry.Rules.Count()); } + [Test] + public void Can_Add_Multiple_Value_For_Same_Rule_Type() + { + // Arrange + var contentService = ServiceContext.ContentService; + var contentTypeService = ServiceContext.ContentTypeService; + var ct = MockedContentTypes.CreateSimpleContentType("blah", "Blah"); + contentTypeService.Save(ct); + var c = MockedContent.CreateSimpleContent(ct, "Test", -1); + contentService.Save(c); + var publicAccessService = ServiceContext.PublicAccessService; + var entry = new PublicAccessEntry(c, c, c, new[] + { + new PublicAccessRule() + { + RuleType = "TestType", + RuleValue = "TestVal" + }, + }); + publicAccessService.Save(entry); + + // Act + var updated1 = publicAccessService.AddRule(c, "TestType", "AnotherVal1"); + var updated2 = publicAccessService.AddRule(c, "TestType", "AnotherVal2"); + + //re-get + entry = publicAccessService.GetEntryForContent(c); + + // Assert + Assert.IsTrue(updated1.Success); + Assert.IsTrue(updated2.Success); + Assert.AreEqual(OperationStatusType.Success, updated1.Result.StatusType); + Assert.AreEqual(OperationStatusType.Success, updated2.Result.StatusType); + Assert.AreEqual(3, entry.Rules.Count()); + } + [Test] public void Can_Remove_Rule() { @@ -106,14 +142,18 @@ namespace Umbraco.Tests.Services new PublicAccessRule() { RuleType = "TestType", - RuleValue = "TestValue" + RuleValue = "TestValue1" + }, + new PublicAccessRule() + { + RuleType = "TestType", + RuleValue = "TestValue2" }, }); - publicAccessService.Save(entry); - publicAccessService.AddOrUpdateRule(c, "TestType", "AnotherVal"); + publicAccessService.Save(entry); // Act - var removed = publicAccessService.RemoveRule(c, "TestType", "TestValue"); + var removed = publicAccessService.RemoveRule(c, "TestType", "TestValue1"); //re-get entry = publicAccessService.GetEntryForContent(c); @@ -121,7 +161,8 @@ namespace Umbraco.Tests.Services Assert.IsTrue(removed.Success); Assert.AreEqual(OperationStatusType.Success, removed.Result.StatusType); Assert.AreEqual(1, entry.Rules.Count()); - Assert.AreEqual("AnotherVal", entry.Rules.ElementAt(0).RuleValue); + Assert.AreEqual("TestValue2", entry.Rules.ElementAt(0).RuleValue); } + } } \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/web/Access.cs b/src/umbraco.cms/businesslogic/web/Access.cs index b2d4b4c103..bcbbbb9c69 100644 --- a/src/umbraco.cms/businesslogic/web/Access.cs +++ b/src/umbraco.cms/businesslogic/web/Access.cs @@ -71,7 +71,7 @@ namespace umbraco.cms.businesslogic.web if (e.Cancel) return; - var entry = ApplicationContext.Current.Services.PublicAccessService.AddOrUpdateRule( + var entry = ApplicationContext.Current.Services.PublicAccessService.AddRule( doc.ContentEntity, Constants.Conventions.PublicAccess.MemberRoleRuleType, role); @@ -95,7 +95,7 @@ namespace umbraco.cms.businesslogic.web if (content == null) throw new Exception("No content found with document id " + DocumentId); - if (ApplicationContext.Current.Services.PublicAccessService.AddOrUpdateRule( + if (ApplicationContext.Current.Services.PublicAccessService.AddRule( content, Constants.Conventions.PublicAccess.MemberGroupIdRuleType, MemberGroupId.ToString(CultureInfo.InvariantCulture))) @@ -113,7 +113,7 @@ namespace umbraco.cms.businesslogic.web if (content == null) throw new Exception("No content found with document id " + DocumentId); - if (ApplicationContext.Current.Services.PublicAccessService.AddOrUpdateRule( + if (ApplicationContext.Current.Services.PublicAccessService.AddRule( content, Constants.Conventions.PublicAccess.MemberIdRuleType, MemberId.ToString(CultureInfo.InvariantCulture))) @@ -132,7 +132,7 @@ namespace umbraco.cms.businesslogic.web if (e.Cancel) return; - var entry = ApplicationContext.Current.Services.PublicAccessService.AddOrUpdateRule( + var entry = ApplicationContext.Current.Services.PublicAccessService.AddRule( doc.ContentEntity, Constants.Conventions.PublicAccess.MemberUsernameRuleType, membershipUserName); @@ -155,7 +155,7 @@ namespace umbraco.cms.businesslogic.web { var doc = new Document(DocumentId); - var entry = ApplicationContext.Current.Services.PublicAccessService.AddOrUpdateRule( + var entry = ApplicationContext.Current.Services.PublicAccessService.AddRule( doc.ContentEntity, Constants.Conventions.PublicAccess.MemberGroupIdRuleType, MemberGroupId.ToString(CultureInfo.InvariantCulture)); From 2c11f0be0f4e6690e13deac10f8c4c2d03b98660 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 15 Oct 2015 17:07:46 +0200 Subject: [PATCH 5/6] updates method to use the available request instance instead of using HttpContext.Current! no idea why it was using that. --- src/Umbraco.Web/HttpRequestExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web/HttpRequestExtensions.cs b/src/Umbraco.Web/HttpRequestExtensions.cs index e700f96571..d7f9e409c8 100644 --- a/src/Umbraco.Web/HttpRequestExtensions.cs +++ b/src/Umbraco.Web/HttpRequestExtensions.cs @@ -32,7 +32,7 @@ namespace Umbraco.Web /// public static string GetItemAsString(this HttpRequest request, string key, string valueIfNotFound = "") { - return new HttpRequestWrapper(request).GetItemAsString(key); + return new HttpRequestWrapper(request).GetItemAsString(key, valueIfNotFound); } /// @@ -44,7 +44,7 @@ namespace Umbraco.Web /// public static string GetItemAsString(this HttpRequestBase request, string key, string valueIfNotFound = "") { - var val = HttpContext.Current.Request[key]; + var val = request[key]; return !val.IsNullOrWhiteSpace() ? val : valueIfNotFound; } @@ -57,7 +57,7 @@ namespace Umbraco.Web /// public static T GetItemAs(this HttpRequestBase request, string key) { - var val = HttpContext.Current.Request[key]; + var val = request[key]; var whitespaceCheck = !val.IsNullOrWhiteSpace() ? val : string.Empty; if (whitespaceCheck.IsNullOrWhiteSpace()) return (T) typeof (T).GetDefaultValue(); From 30ad3f5aa6b1f927bdccb2508c36bd1e2351b508 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 15 Oct 2015 17:12:13 +0200 Subject: [PATCH 6/6] bumps version --- build/UmbracoVersion.txt | 2 +- src/Umbraco.Core/Configuration/UmbracoVersion.cs | 2 +- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/UmbracoVersion.txt b/build/UmbracoVersion.txt index ed2ae80c6e..02c2b2fdb9 100644 --- a/build/UmbracoVersion.txt +++ b/build/UmbracoVersion.txt @@ -1,2 +1,2 @@ # Usage: on line 2 put the release version, on line 3 put the version comment (example: beta) -7.3.0 \ No newline at end of file +7.3.1 \ No newline at end of file diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Core/Configuration/UmbracoVersion.cs index e61d091d84..19b9f8f746 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/UmbracoVersion.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration { public class UmbracoVersion { - private static readonly Version Version = new Version("7.3.0"); + private static readonly Version Version = new Version("7.3.1"); /// /// Gets the current version of Umbraco. diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index 811295a34d..c7f2374c99 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -2413,7 +2413,7 @@ xcopy "$(ProjectDir)"..\packages\SqlServerCE.4.0.0.0\x86\*.* "$(TargetDir)x86\" True 7300 / - http://localhost:7300 + http://localhost:7310 False False