diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Conditions/RoleCondition.cs b/src/Orchard.Web/Modules/Orchard.Roles/Conditions/RoleCondition.cs new file mode 100644 index 000000000..7660c8596 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Roles/Conditions/RoleCondition.cs @@ -0,0 +1,32 @@ +using Orchard.Conditions.Services; +using Orchard.ContentManagement; +using Orchard.Roles.Models; +using Orchard.Security; +using System; +using System.Linq; + +namespace Orchard.Roles.Conditions { + public class RoleRuleProvider : IConditionProvider { + private readonly IAuthenticationService _authenticationService; + + public RoleRuleProvider(IAuthenticationService authenticationService) { + _authenticationService = authenticationService; + } + + public void Evaluate(ConditionEvaluationContext evaluationContext) { + if (!String.Equals(evaluationContext.FunctionName, "role", StringComparison.OrdinalIgnoreCase)) { + return; + } + + var user = _authenticationService.GetAuthenticatedUser(); + if (user == null) { + evaluationContext.Result = false; + return; + } + + var roles = evaluationContext.Arguments.Cast(); + var userRoles = user.As(); + evaluationContext.Result = userRoles != null ? userRoles.Roles.Intersect(roles).Count() > 0 : false; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Orchard.Roles.csproj b/src/Orchard.Web/Modules/Orchard.Roles/Orchard.Roles.csproj index 72493aade..7c2384cd2 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Orchard.Roles.csproj +++ b/src/Orchard.Web/Modules/Orchard.Roles/Orchard.Roles.csproj @@ -125,7 +125,7 @@ - + @@ -157,6 +157,10 @@ Orchard.Core false + + {98251eae-a41b-47b2-aa91-e28b8482da70} + Orchard.Conditions + {642a49d7-8752-4177-80d6-bfbbcfad3de0} Orchard.Forms diff --git a/src/Orchard.Web/Modules/Orchard.Roles/RuleEngine/RoleRuleProvider.cs b/src/Orchard.Web/Modules/Orchard.Roles/RuleEngine/RoleRuleProvider.cs deleted file mode 100644 index ce3b6a398..000000000 --- a/src/Orchard.Web/Modules/Orchard.Roles/RuleEngine/RoleRuleProvider.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Orchard.ContentManagement; -using Orchard.Events; -using Orchard.Roles.Models; -using Orchard.Security; -using System; -using System.Linq; - -namespace Orchard.Roles.RuleEngine { - public interface IRuleProvider : IEventHandler { - void Process(dynamic ruleContext); - } - - public class RoleRuleProvider : IRuleProvider { - private readonly IAuthenticationService _authenticationService; - - public RoleRuleProvider(IAuthenticationService authenticationService) { - _authenticationService = authenticationService; - } - - public void Process(dynamic ruleContext) { - if (!String.Equals(ruleContext.FunctionName, "role", StringComparison.OrdinalIgnoreCase)) { - return; - } - - var user = _authenticationService.GetAuthenticatedUser(); - if (user == null) { - ruleContext.Result = false; - return; - } - - var roles = ((object[])ruleContext.Arguments).Cast(); - var userRoles = user.As(); - ruleContext.Result = userRoles != null ? userRoles.Roles.Intersect(roles).Count() > 0 : false; - } - } -} \ No newline at end of file