<rule
parentDocType="subPagesListNews"
childDocType="categoryListGeneral"
maxNodes="1"
showWarnings="true"
customMessage="Somente uma lista de Categorias é Permitida"
customMessageCategory="Aviso"
customWarningMessage="Somente uma lista de Categorias é Permitida"
customWarningMessageCategory="Warning"
>
</rule>
And then I tested it on a test instance and got a custom warning message as expected:
And then I tried to add a second node and got a custom error message as expected:
(Pardon the ridiculous node names :) )
From what I can suspect you haven't touched your web.config file to reload the application. Rules are loaded once on application start and then cached for performance.
Other that that, the usual culprit is probably a typo in the doctype names, but I guess you have already checked that.
Please let me know if restarting the web application fixed the issue.
I was curious so I set it up in another demo site I'm working on and enabled list view for one doctype. As you will see, I allow 8 portfolio item nodes and I start with 7 and 2 unpublished, publishing the first (which just displays a warning) and then the second (which is not published). I stopped the capture earlier so you don't actually see the list again, but I checked and it was not published.
Which makes me wonder - it works on my computer :) (actually, it's a different computer this time :) )
The only other thing I can think of is maybe it can't find the file for some reason. I don't know if you are working Umbraco from a subfolder or as a stand-alone site, my tests did not include subfolders. Actually, I "swallow" any FileNotFoundException in case someone has forgotten to include the config file (which is wrong, now that I think of it).
This is from Restrictor.cs, and it's where it loads the configuration. It logs an error only if the file has been found but something else has gone horribly wrong. Do you happen to have any such message on your logs?
private void GetRulesFromConfigFile()
{
XmlDocument xmlConfig = new XmlDocument();
try
{
xmlConfig.Load(HostingEnvironment.MapPath(GlobalSettings.Path + "/../config/nodeRestrict.config"));
}
catch (FileNotFoundException ex) { return; }
catch (Exception ex)
{
Umbraco.Core.Logging.LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "There was a problem loading Restrictor configuration from the config file", ex);
return;
}
EDIT: I'm going to change this part of the code to write something to the Umbraco log file if the file is not found - I wonder why I didn't do that in the first place.
<?xml version="1.0" encoding="utf-8" ?>
<rule
parentDocType="subPagesListNews"
childDocType="categoryListGeneral"
maxNodes="1"
showWarnings="true"
customMessage="Somente uma lista de Categorias e Permitida"
customMessageCategory="Aviso"
customWarningMessage="Não possivel criar mais que uma lista de categorias"
customWarningMessageCategory="Limite"
>
</rule>
<!--
If you add a NUMERIC property named "umbracoRestrictNodes" to a node (or any other name you wish, as long as you define it below)
and give it a value (e.g. 5), then the node will only allow for 5 published children. No other rules will be processed, since this property
overrides any other rules. You can set showWarnings to "true" to see informational messages on remaining allowed children before the limit is reached.
-->
<!--<nodeRestrict propertyAlias="umbracoRestrictNodes" showWarnings="true">-->
<!--
These are the more generic rules that apply for document types.
Uncomment this and set the values you like to apply a child node restriction rule.
You can define as many rules as you like.
You can use an asterisk either for parentDocType or childDocType (or both, if you feel like it :) ).
Asterisk means "any document type".
If more than one rules apply to a document that is published, only the first matched rule will be checked,
regardless of whether there are more restrictive rules below. So define your rules putting more restrictive rules first.
Rules are processed in order of appearance in this configuration file.
-->
<!--
<rule
parentDocType="myParentDocType"
childDocType="myChildDocType"
maxNodes="10"
showWarnings="true"
customMessage=""
customMessageCategory=""
customWarningMessage=""
customWarningMessageCategory=""
>
</rule>
-->
<!--</nodeRestrict>-->
Is that what it should be? I've watched your screencast a couple of times and reviewed everything but wasn't able to figure it out yet. Do you see anything wrong in the config file?
PS: the log is not showing that error you asked about, have deleted the DependencyCache (App_Data/TEMP), have saved the web.config and have restarted the application, and yet, no dice
That's what it was before, and it didn't work either. Have even disabled List View just to make sure.
Changed the config again to this:
<?xml version="1.0" encoding="utf-8" ?>
<!--
If you add a NUMERIC property named "umbracoRestrictNodes" to a node (or any other name you wish, as long as you define it below)
and give it a value (e.g. 5), then the node will only allow for 5 published children. No other rules will be processed, since this property
overrides any other rules. You can set showWarnings to "true" to see informational messages on remaining allowed children before the limit is reached.
-->
<nodeRestrict propertyAlias="umbracoRestrictNodes" showWarnings="true">
<rule
parentDocType="subPagesListNews"
childDocType="categoryListGeneral"
maxNodes="1"
showWarnings="true"
customMessage="Somente uma lista de Categorias é Permitida"
customMessageCategory="Aviso"
customWarningMessage="Não é possivel criar mais que uma lista de categorias"
customWarningMessageCategory="Limite"
>
</rule>
<!--
These are the more generic rules that apply for document types.
Uncomment this and set the values you like to apply a child node restriction rule.
You can define as many rules as you like.
You can use an asterisk either for parentDocType or childDocType (or both, if you feel like it :) ).
Asterisk means "any document type".
If more than one rules apply to a document that is published, only the first matched rule will be checked,
regardless of whether there are more restrictive rules below. So define your rules putting more restrictive rules first.
Rules are processed in order of appearance in this configuration file.
-->
<!--
<rule
parentDocType="myParentDocType"
childDocType="myChildDocType"
maxNodes="10"
showWarnings="true"
customMessage=""
customMessageCategory=""
customWarningMessage=""
customWarningMessageCategory=""
>
</rule>
-->
</nodeRestrict>
Having tried it in multiple configurations and sites / computers, I'd say there's probably something that we probably don't see in your setup. I've sent you a connect on LinkedIn, let's talk there and exchange Skype info etc. so we can solve this quickly.
I may have figured out what is wrong. It appears the config files does not like & or accented symbols (used to display accents in Portuguese). After I've removed it started working.
I had the config before as :
<rule
parentDocType="subPagesListNews"
childDocType="categoryListGeneral"
maxNodes="1"
showWarnings="true"
customMessage="Somente uma lista de Categorias é Permitida"
customMessageCategory="Aviso"
customWarningMessage="Não é possivel criar mais que uma lista de categorias"
customWarningMessageCategory="Limite"
>
</rule>
Added a restriction to the root (home) document type
Tested the restriction in the List View document type (from before)
Good to know that XML was the culprit and that the package is working. :) I'm thinking of additionally exposing rule setup in code so that you don't have to use a config file if you don't want to. In my to-do list!
Not working
I have set the rule as follows:
And yet it did not work. What am I missing?
I created the following rule:
And then I tested it on a test instance and got a custom warning message as expected:
And then I tried to add a second node and got a custom error message as expected:
(Pardon the ridiculous node names :) )
From what I can suspect you haven't touched your web.config file to reload the application. Rules are loaded once on application start and then cached for performance.
Other that that, the usual culprit is probably a typo in the doctype names, but I guess you have already checked that.
Please let me know if restarting the web application fixed the issue.
Does it work in List View mode?
Cause I've set it up yet it's not working. Also restarted the app, no game. It could be something I did wrong, so ...
Here are the screenshot of everything.
There should be only one "Categorias" allowed
Hmmm! I never tested it with list view, since I never thought that things would be different there. I'll do some debugging and I'll let you know.
Does it still not work if you switch to normal view?
I was curious so I set it up in another demo site I'm working on and enabled list view for one doctype. As you will see, I allow 8 portfolio item nodes and I start with 7 and 2 unpublished, publishing the first (which just displays a warning) and then the second (which is not published). I stopped the capture earlier so you don't actually see the list again, but I checked and it was not published.
Here's the config:
And here's the screencast showing the whole process: http://screencast-o-matic.com/watch/cDiVXziuG3
Which makes me wonder - it works on my computer :) (actually, it's a different computer this time :) )
The only other thing I can think of is maybe it can't find the file for some reason. I don't know if you are working Umbraco from a subfolder or as a stand-alone site, my tests did not include subfolders. Actually, I "swallow" any FileNotFoundException in case someone has forgotten to include the config file (which is wrong, now that I think of it).
This is from Restrictor.cs, and it's where it loads the configuration. It logs an error only if the file has been found but something else has gone horribly wrong. Do you happen to have any such message on your logs?
EDIT: I'm going to change this part of the code to write something to the Umbraco log file if the file is not found - I wonder why I didn't do that in the first place.
I must be doing something wrong then.
Have changed the config file to:
Is that what it should be? I've watched your screencast a couple of times and reviewed everything but wasn't able to figure it out yet. Do you see anything wrong in the config file?
PS: the log is not showing that error you asked about, have deleted the DependencyCache (App_Data/TEMP), have saved the web.config and have restarted the application, and yet, no dice
Why have you commented out the top node?
Your config should be in this form:
That's what it was before, and it didn't work either. Have even disabled List View just to make sure.
Changed the config again to this:
It's still not working :(
Having tried it in multiple configurations and sites / computers, I'd say there's probably something that we probably don't see in your setup. I've sent you a connect on LinkedIn, let's talk there and exchange Skype info etc. so we can solve this quickly.
I may have figured out what is wrong. It appears the config files does not like
&
or accented symbols (used to display accents in Portuguese). After I've removed it started working.I had the config before as :
Added a restriction to the root (home) document type
Tested the restriction in the List View document type (from before)
Good to know that XML was the culprit and that the package is working. :) I'm thinking of additionally exposing rule setup in code so that you don't have to use a config file if you don't want to. In my to-do list!
is working on a reply...