Forum Discussion

Quelyn's avatar
Quelyn
Genius
10 years ago

Help with Freemarker & Menu Permissions

Hello!  We have a menu to browse the sections of the community that different roles have access to.  The way I have this setup is using if and elseif commands.  

<li class=""><a href="/t5/Forums/ct-p/forums">Forums</a>
<ul class="menu menu-flash-array">
<!-- Registered User Forum Menu --> 
    <#if user_has_role == "reguser" >
        <li><a href="/t5/Forum1/bd-p/forum1">Forum 1</a></li>
<!-- Customer Forum Menu -->
    <#elseif user_has_role == "customer" >
        <li><a href="/t5/Forum1/bd-p/forum1">Forum 1</a></li>
        <li><a href="/t5/Forum2/bd-p/forum2">Forum 2</a></li>
        <li><a href="/t5/Forum3/bd-p/forum3">Forum 3</a></li>
<!-- Partner Forum Menu -->
	<#elseif user_has_role == "partner" >
        <li><a href="/t5/Forum1/bd-p/forum1">Forum 1</a></li>
        <li><a href="/t5/Forum2/bd-p/forum2">Forum 2</a></li>
        <li><a href="/t5/Forum3/bd-p/forum3">Forum 3</a></li>
        <li><a href="/t5/Forum4/bd-p/forum4">Forum 4</a></li>
<!-- Employee Forum Menu -->
	<#elseif user_has_role == "employee" >
        <li><a href="/t5/Forum1/bd-p/forum1">Forum 1</a></li>
        <li><a href="/t5/Forum2/bd-p/forum2">Forum 2</a></li>
        <li><a href="/t5/Forum3/bd-p/forum3">Forum 3</a></li>
        <li><a href="/t5/Forum4/bd-p/forum4">Forum 4</a></li>
        <li><a href="/t5/Forum5/bd-p/forum5">Forum 5</a></li>
<!-- Support Forum Menu -->
	<#elseif user_has_role?? && (user_has_role == "support" || user_has_role == "admin") >
        <li><a href="/t5/Forum1/bd-p/forum1">Forum 1</a></li>
        <li><a href="/t5/Forum2/bd-p/forum2">Forum 2</a></li>
        <li><a href="/t5/Forum3/bd-p/forum3">Forum 3</a></li>
        <li><a href="/t5/Forum4/bd-p/forum4">Forum 4</a></li>
        <li><a href="/t5/Forum5/bd-p/forum5">Forum 5</a></li>
        <li><a href="/t5/Forum6/bd-p/forum6">Forum 6</a></li>
    </#if>
</ul>

What is happening is that we have some users with two roles.  Employee AND Support.  So, when they get to the point in the code where it assigns them "employee", it stops looking further and they see those menu items only.  

 

I use Support as a role that's for access only, and they get their baseline defaults from Employee.  This is the only place where this causes an issue.  Is there a way to fix this in the freemarker code? 

 

Any assistance is greatly appreciated! 

 

 

 

6 Replies

  • OlivierS's avatar
    OlivierS
    Lithium Alumni (Retired)
    10 years ago

    Quelyn maybe something like:

     

    <!-- Employee Forum Menu -->
    	<#elseif user_has_role == "employee" >
              <#if user_has_role == "support">
    <!-- user has employee and support role -->
    <!-- display what you want to display -->
               <#elseif>
            <li><a href="/t5/Forum1/bd-p/forum1">Forum 1</a></li>
            <li><a href="/t5/Forum2/bd-p/forum2">Forum 2</a></li>
            <li><a href="/t5/Forum3/bd-p/forum3">Forum 3</a></li>
            <li><a href="/t5/Forum4/bd-p/forum4">Forum 4</a></li>
            <li><a href="/t5/Forum5/bd-p/forum5">Forum 5</a></li>
    <#/if> <!-- Support Forum Menu --> <#elseif user_has_role?? && (user_has_role == "support" || user_has_role == "admin") > <#if user_has_role == "employee"> <!-- user has employee and support role --> <!-- display what you want to display --> <!-- note: not sure this condition is necessary --> <#elseif> <li><a href="/t5/Forum1/bd-p/forum1">Forum 1</a></li> <li><a href="/t5/Forum2/bd-p/forum2">Forum 2</a></li> <li><a href="/t5/Forum3/bd-p/forum3">Forum 3</a></li> <li><a href="/t5/Forum4/bd-p/forum4">Forum 4</a></li> <li><a href="/t5/Forum5/bd-p/forum5">Forum 5</a></li> <li><a href="/t5/Forum6/bd-p/forum6">Forum 6</a></li>
    <#/if>

  • Quelyn's avatar
    Quelyn
    Genius
    10 years ago

    Trying this and getting an error: 

    Freemarker template 'ContentWrapper' parsing failed:

    ParseException:Parsing error in template "ContentWrapper" in line 102, column 18:
    Unknown directive: #elseif. Help (latest version): http://freemarker.org/docs/ref_directive_alphaidx.html; you're using FreeMarker 2.3.20.

     

    I'll try variations on this... Definitely seems closer.  The elseif in the middle needs to be "else", but that still doens't work.  Back to the drawing board :)

  • OlivierS's avatar
    OlivierS
    Lithium Alumni (Retired)
    10 years ago

    Quelyn correct ... bothe elseif should be else ... I just wrote the code like that to show the logic ... it might be full of errors!

  • OlivierS's avatar
    OlivierS
    Lithium Alumni (Retired)
    10 years ago

    Quelyn I thin k the apporach is not the best here ... you should build your menu based on the role(s) the user have ...

     

    First, you set up a 'menu' string: 

    <#assign my_li=''>

    Then you build your menu string depending on the role(s):

     

    if user has role admin then my_li += '<li>admin link</li>'
    if user has role employees then my_li += '<li>employee link</li>'

    Sorry, it's just the theory, not hte actual freemarker code ... but that's a much better approach I think ...

  • Quelyn's avatar
    Quelyn
    Genius
    10 years ago

    OlivierS Well, I *thought* that's what I was doing!  But the problem comes into play because the way we are setup some users have more than one role.  And that's when things don't really work.  

     

    But we define all the roles, and we say, "If someone is Employee, they see this menu", and "If someone is Support they see this OTHER menu".  But the people who are support have both the Employee and Support roles, for access to KB / Forums.  

     

    So, that's the use case that is having the problem. 

     

     

    Ideally we would like a menu that is dynamic like the "Community Browser" but customizable.