mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Added LegacyRulesEvaluator.
This will handle third-party modules that still implement the deprecated IRuleProvider.
This commit is contained in:
parent
bdca8a5564
commit
91fdba1e2c
@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Conditions.Providers;
|
||||
using Orchard.Conditions.Services;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.Widgets.RuleEngine;
|
||||
|
||||
namespace Orchard.Tests.Modules.Conditions.Providers {
|
||||
[TestFixture]
|
||||
|
@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using Orchard.Conditions.Services;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Mvc;
|
||||
|
||||
namespace Orchard.Widgets.RuleEngine {
|
||||
namespace Orchard.Conditions.Providers {
|
||||
public class UrlCondition : IConditionProvider {
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly ShellSettings _shellSettings;
|
||||
|
@ -3,41 +3,20 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using Orchard.Events;
|
||||
|
||||
namespace Orchard.Localization.RuleEngine {
|
||||
public interface IRuleProvider : IEventHandler {
|
||||
void Process(dynamic ruleContext);
|
||||
}
|
||||
namespace Orchard.Localization.Conditions {
|
||||
|
||||
public interface IConditionProvider : IEventHandler {
|
||||
void Evaluate(dynamic evaluationContext);
|
||||
}
|
||||
|
||||
public class CultureRuleProvider : IRuleProvider, IConditionProvider
|
||||
public class CultureConditionProvider : IConditionProvider
|
||||
{
|
||||
private readonly WorkContext _workContext;
|
||||
|
||||
public CultureRuleProvider(WorkContext workContext) {
|
||||
public CultureConditionProvider(WorkContext workContext) {
|
||||
_workContext = workContext;
|
||||
}
|
||||
|
||||
public void Process(dynamic ruleContext) {
|
||||
if (String.Equals(ruleContext.FunctionName, "culturecode", StringComparison.OrdinalIgnoreCase)) {
|
||||
ProcessCultureCode(ruleContext);
|
||||
}
|
||||
|
||||
if (String.Equals(ruleContext.FunctionName, "culturelcid", StringComparison.OrdinalIgnoreCase)) {
|
||||
ProcessCultureId(ruleContext);
|
||||
}
|
||||
|
||||
if (String.Equals(ruleContext.FunctionName, "cultureisrtl", StringComparison.OrdinalIgnoreCase)) {
|
||||
ProcessCurrentCultureIsRtl(ruleContext);
|
||||
}
|
||||
|
||||
if (String.Equals(ruleContext.FunctionName, "culturelang", StringComparison.OrdinalIgnoreCase)) {
|
||||
ProcessLanguageCode(ruleContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Evaluate(dynamic evaluationContext)
|
||||
{
|
||||
if (String.Equals(evaluationContext.FunctionName, "culturecode", StringComparison.OrdinalIgnoreCase)) {
|
||||
@ -93,7 +72,5 @@ namespace Orchard.Localization.RuleEngine {
|
||||
.Select(CultureInfo.GetCultureInfo)
|
||||
.Any(c => c.Name == currentUserCulture.Name);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -101,7 +101,7 @@
|
||||
<Compile Include="Selectors\RouteCultureSelector.cs" />
|
||||
<Compile Include="Selectors\BrowserCultureSelector.cs" />
|
||||
<Compile Include="Providers\ICultureStorageProvider.cs" />
|
||||
<Compile Include="RuleEngine\CultureRuleProvider.cs" />
|
||||
<Compile Include="Conditions\CultureConditionProvider.cs" />
|
||||
<Compile Include="Services\AdminDirectionalityFactory.cs" />
|
||||
<Compile Include="Services\AdminCultureSelectorFactory.cs" />
|
||||
<Compile Include="Services\LocalizationCultureFilter.cs" />
|
||||
|
@ -10,10 +10,10 @@ namespace Orchard.Roles.Conditions {
|
||||
void Evaluate(dynamic evaluationContext);
|
||||
}
|
||||
|
||||
public class RoleRuleProvider : IConditionProvider {
|
||||
public class RoleConditionProvider : IConditionProvider {
|
||||
private readonly IAuthenticationService _authenticationService;
|
||||
|
||||
public RoleRuleProvider(IAuthenticationService authenticationService) {
|
||||
public RoleConditionProvider(IAuthenticationService authenticationService) {
|
||||
_authenticationService = authenticationService;
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ namespace Orchard.Roles.Conditions {
|
||||
|
||||
var roles = ((object[])evaluationContext.Arguments).Cast<string>();
|
||||
var userRoles = user.As<IUserRoles>();
|
||||
evaluationContext.Result = userRoles != null ? userRoles.Roles.Intersect(roles).Count() > 0 : false;
|
||||
evaluationContext.Result = userRoles != null && userRoles.Roles.Intersect(roles).Any();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using Orchard.Conditions.Services;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Widgets.Services;
|
||||
|
||||
namespace Orchard.Widgets.Conditions {
|
||||
/// <summary>
|
||||
/// Evaluates rules implementing the deprecated IRuleProvider (third party modules).
|
||||
/// </summary>
|
||||
[Obsolete("This is here for backwards compatibility during the deprecation period.")]
|
||||
public class LegacyRulesEvaluator : IConditionProvider {
|
||||
private readonly IRuleProvider _ruleProviders;
|
||||
|
||||
public LegacyRulesEvaluator(IRuleProvider ruleProviders)
|
||||
{
|
||||
_ruleProviders = ruleProviders;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public void Evaluate(ConditionEvaluationContext evaluationContext) {
|
||||
var ruleContext = new RuleContext {
|
||||
FunctionName = evaluationContext.FunctionName,
|
||||
Arguments = evaluationContext.Arguments,
|
||||
Result = evaluationContext.Result
|
||||
};
|
||||
|
||||
_ruleProviders.Process(ruleContext);
|
||||
evaluationContext.Result = ruleContext.Result;
|
||||
}
|
||||
}
|
||||
}
|
@ -93,6 +93,7 @@
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Commands\LayerCommands.cs" />
|
||||
<Compile Include="Commands\WidgetCommands.cs" />
|
||||
<Compile Include="Conditions\LegacyRulesEvaluator.cs" />
|
||||
<Compile Include="Controllers\AdminController.cs" />
|
||||
<Compile Include="ControlWrapper.cs" />
|
||||
<Compile Include="Drivers\LayerPartDriver.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user