RuleProvider not working in Production environment

Topics: Customizing Orchard
May 10, 2011 at 10:59 AM

I have created the below Rule provider and it works fine on my dev and test environment.

When I deploy to my hosted environment I get the error:

The rule is not valid: Expression is not a boolean value

Both my dev, test and hosted environments have all the same modules enabled.

Any suggestions please...

using System;
using Orchard.ContentManagement;
using Orchard.Roles.Models;
using Orchard.Security;
using Orchard.Widgets.Services;

namespace Orchard.MyModule.RuleEngine
{
	public class MyModuleRuleProvider : IRuleProvider
	{
		private readonly IAuthenticationService _authenticationService;

		public MyModuleRuleProvider (IAuthenticationService authenticationService)
		{
			_authenticationService = authenticationService;
		}

		public void Process(RuleContext ruleContext)
		{
			if (!"broker,brokeradmin,consultant".Contains(ruleContext.FunctionName.ToLower()))
			{
				return;
			}

			var user = _authenticationService.GetAuthenticatedUser();
			if (user != null)
			{
				var roles = user.As<IUserRoles>().Roles;
				switch (ruleContext.FunctionName.ToLower())
				{
					case "broker":
						if (roles.Contains("Broker") || roles.Contains("broker"))
						{
							ruleContext.Result = true;
							return;
						}
						break;
					case "brokeradmin":
						if (roles.Contains("Broker Admin") || roles.Contains("broker admin") || roles.Contains("BrokerAdmin") || roles.Contains("brokeradmin"))
						{
							ruleContext.Result = true;
							return;
						}
						break;
					case "consultant":
						if (roles.Contains("Consultant") || roles.Contains("consultant"))
						{
							ruleContext.Result = true;
							return;
						}
						break;
				}
			}
			ruleContext.Result = false;
		}
	}
}

 

 

Coordinator
May 10, 2011 at 5:19 PM

[summoning Renaud]

Coordinator
May 10, 2011 at 5:36 PM

Your provider looks fine at first sight, could it be that one of the rules defined in your production database is syntactically incorrect?

May 11, 2011 at 4:46 AM

Hi Renaud, it is when I try to create a Layer on the production environment. I try to add Layer: [Name] = Broker, [Layer Rule] = broker then I get the above error. Could it be that somehow the environment does not recognize my rule. Strange though as all my widgets and functionality I added works fine. I can add my custom widget to any existing layer create any other layer but I can not add a Layer with above Rule Provider.

Coordinator
May 11, 2011 at 5:30 AM

Hmm.. Are you sure your provider is enabled and recognized on the production server?

The reason I am asking is that I get the exact same error message ("The rule is not valid: Expression is not a boolean value") when I enter a "fake" rule (e.g. [LayerRule] = foo), so it looks like your provider is not recognized for some reason.

May 11, 2011 at 7:04 AM

Renaud, I have a custom module and the rule is part of that module. I have a source code instance of orchard, an installed (WPI) instance and then a hosted instance (Deployed via FTP) of orchard. My process of deployment is to dev on the source instance, then deploy to my installed instance test and if all is working FTP to hosted environment. Now strangely on both dev and installed instance the rule works fine, yet the hosted instance does not. My custom module is definitely enabled on all instances as all the other functionality widgets, etc. works fine. I agree that for some reason the rule is not recognized on my hosted instance, the question is why not and how do I determine why not?

I will create a separate module with just the rule in it and deploy to my hosted environment to see if it makes any difference and if the standalone version will be recognized. 

Coordinator
May 12, 2011 at 12:10 AM

The first thing i would do is go to the "Features" screen and make sure your module is enabled. The second thing would be to add a "Logger" instance property to your provider, activate logging (see the log4net.config file) and see if your provider is called at all.

Dec 3, 2012 at 2:16 PM

I had exactly the same issue, module was enabled but I was getting the same error, expression is not a boolean value.

Turned out that I forgot to publish the .dll file of my module on my production server.