Using logical operators in DNN Dynamic Roles

Logical operators are a powerful means to connect booleans. As you may know, you express the rules that make up a dynamic role in XML syntax. Each rule results in a boolean value when evaluated by the DNN Dynamic Roles module. Using the module’s logical operators is easy:

To connect a set of rules with the AND operator, just use this syntax:

<and>
    <rule1 />
    <rule2 />
</and>

To connect a set of rules with the OR operator, the syntax is as follows:

<or>
    <rule1 />
    <rule2 />
</or>

The NOT operators allows for negating a rule’s outcome:

<not>
    <rule />
</not>

You can even nest logical operators:

<and>
    <rule1 />
    <or>
        <rule2 />
        <not><rule3 /></not>
    </or>
</and>

To be a bit more concrete, image you want to build a dynamic role which triggers if a user is in the role “StoreUsers” or if the request parameter “store” is supplied:

<or>
    <member role="StoreUsers" />
    <requestParam name="store" />
</or>

In an advanced scenario, imaging the one above, but the user must not be located in Germany:

<and>
    <not><geoMaxMindCountry userId="..." licenseKey="..." service="city" country="DE" /></not>
    <or>
        <member role="StoreUsers" />
        <requestParam name="store" />
    </or>
</and>

You can find more detailed information on how to use the XML rule definition syntax and an overview on all the available rules on this page.

 

More information: