Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Carlos Casalicchio 169 posts 698 karma points
    Jun 30, 2016 @ 19:36
    Carlos Casalicchio
    0

    I have set the rule as follows:

     <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 yet it did not work. What am I missing?

  • Sotiris Filippidis 286 posts 1501 karma points
    Jun 30, 2016 @ 21:10
    Sotiris Filippidis
    0

    I created the following rule:

    <rule 
        parentDocType="LandingPage" 
        childDocType="TextPage" 
        maxNodes="1"
        showWarnings="true"
        customMessage="custom message"
        customMessageCategory="custom category"
        customWarningMessage="custom warning"
        customWarningMessageCategory="custom warning category"
        >
       </rule>
    

    And then I tested it on a test instance and got a custom warning message as expected:

    enter image description here

    And then I tried to add a second node and got a custom error message as expected:

    enter image description here

    (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.

  • Carlos Casalicchio 169 posts 698 karma points
    Jun 30, 2016 @ 22:02
    Carlos Casalicchio
    0

    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.

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    There should be only one "Categorias" allowed

    enter image description here

  • Sotiris Filippidis 286 posts 1501 karma points
    Jul 01, 2016 @ 09:35
    Sotiris Filippidis
    0

    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?

  • Sotiris Filippidis 286 posts 1501 karma points
    Jul 01, 2016 @ 11:47
    Sotiris Filippidis
    0

    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:

      <rule 
        parentDocType="folderPortfolioItems" 
        childDocType="pagePortfolioItem" 
        maxNodes="8"
        showWarnings="true"
        customMessage="custom message"
        customMessageCategory="custom category message"
        customWarningMessage="custom warning message"
        customWarningMessageCategory="custom warning category"
        >
       </rule>
    

    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?

     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.

  • Carlos Casalicchio 169 posts 698 karma points
    Jul 01, 2016 @ 14:37
    Carlos Casalicchio
    0

    I must be doing something wrong then.

    Have changed the config file to:

    <?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&atilde;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

  • Sotiris Filippidis 286 posts 1501 karma points
    Jul 01, 2016 @ 14:42
    Sotiris Filippidis
    0

    Why have you commented out the top node?

    Your config should be in this form:

    <?xml version="1.0" encoding="utf-8" ?>
    
    <nodeRestrict propertyAlias="umbracoRestrictNodes" showWarnings="true">
    
      <rule 
        parentDocType="xxx" 
        childDocType="yyy" 
        maxNodes="1"
        showWarnings="true"
        customMessage="blah blah"
        customMessageCategory="Oops!"
        customWarningMessage="blah blah"
        customWarningMessageCategory="Oops!"
        >
       </rule>
    
    
    </nodeRestrict>
    
  • Carlos Casalicchio 169 posts 698 karma points
    Jul 01, 2016 @ 14:49
    Carlos Casalicchio
    0

    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 &eacute; Permitida"
        customMessageCategory="Aviso"
        customWarningMessage="N&atilde;o &eacute; 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>
    

    It's still not working :(

    enter image description here

  • Sotiris Filippidis 286 posts 1501 karma points
    Jul 01, 2016 @ 14:52
    Sotiris Filippidis
    0

    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.

  • Carlos Casalicchio 169 posts 698 karma points
    Jul 01, 2016 @ 15:05
    Carlos Casalicchio
    0

    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 &eacute; Permitida"
        customMessageCategory="Aviso"
        customWarningMessage="N&atilde;o &eacute; possivel criar mais que uma lista de categorias"
        customWarningMessageCategory="Limite"
        >
       </rule>
    

    Added a restriction to the root (home) document type enter image description here

    Tested the restriction in the List View document type (from before) enter image description here

  • Sotiris Filippidis 286 posts 1501 karma points
    Jul 01, 2016 @ 15:16
    Sotiris Filippidis
    0

    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!

Please Sign in or register to post replies

Write your reply to:

Draft