Fixes: U4-7248 Can't update roles on public access, obsolete AddOrUpdateRule

This commit is contained in:
Shannon
2015-10-15 17:06:00 +02:00
parent 65d421b619
commit c514ce8da3
4 changed files with 76 additions and 21 deletions

View File

@@ -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
/// <returns></returns>
Attempt<PublicAccessEntry> IsProtected(string contentPath);
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Use AddRule instead, this method will be removed in future versions")]
Attempt<OperationStatus<PublicAccessEntry, OperationStatusType>> AddOrUpdateRule(IContent content, string ruleType, string ruleValue);
/// <summary>
/// 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
/// </summary>
/// <param name="content"></param>
/// <param name="ruleType"></param>
/// <param name="newRuleValue"></param>
/// <param name="ruleValue"></param>
/// <returns></returns>
Attempt<OperationStatus<PublicAccessEntry, OperationStatusType>> AddOrUpdateRule(IContent content, string ruleType, string newRuleValue);
Attempt<OperationStatus<PublicAccessEntry, OperationStatusType>> AddRule(IContent content, string ruleType, string ruleValue);
/// <summary>
/// Removes a rule

View File

@@ -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<OperationStatus<PublicAccessEntry, OperationStatusType>> AddOrUpdateRule(IContent content, string ruleType, string ruleValue)
{
return AddRule(content, ruleType, ruleValue);
}
/// <summary>
/// Adds/updates a rule
/// Adds a rule
/// </summary>
/// <param name="content"></param>
/// <param name="ruleType"></param>
/// <param name="newRuleValue"></param>
/// <param name="ruleValue"></param>
/// <returns></returns>
public Attempt<OperationStatus<PublicAccessEntry, OperationStatusType>> AddOrUpdateRule(IContent content, string ruleType, string newRuleValue)
public Attempt<OperationStatus<PublicAccessEntry, OperationStatusType>> 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<OperationStatus<PublicAccessEntry, OperationStatusType>>.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<OperationStatus<PublicAccessEntry, OperationStatusType>>.Succeed(
new OperationStatus<PublicAccessEntry, OperationStatusType>(entry, OperationStatusType.Success, evtMsgs));
}
if (Saving.IsRaisedEventCancelled(