Forum Discussion

Maikinos's avatar
Maikinos
Contributor
9 years ago

Freemarker With Roles

I have a problem with a plug are not getting data from a function with freemarker.
My goal is to visualize the role of the user who entered the community and according to this display a banner.
However, this is only possible to be visible for users with administrator role.

I have new roles called Nivel_Test1, Nivel_Test2 and Nivel_Test3 only those roles are the ones that should be the banner but only manages to do with administrator and that's not what I want.

 

<#assign userStar = rest("2.0","/search?q=" + "SELECT roles FROM users WHERE login = '${user.login}'"?url) />

<#list userStar.data.items as usuario1>

<#assign roles1 = rest("2.0","/search?q=" + "${usuario1.roles.query}"?url) />

<#list roles1.data.items as role>

<#switch role.name>

<#case 'Nivel_Test1'>
<div class="banner_cr"><img src="
${asset.get("/html/assets/imagen.jpg")}" /></div>
<#break>
<#case 'Nivel_Test2'>
<div class="banner_cr"><img src="
${asset.get("/html/assets/imagen.jpg")}" /></div>
<#break>
<#case 'Nivel_Test3'>
<div class="banner_cr"><img src="
${asset.get("/html/assets/imagen.jpg")}" /></div>
<#break>

<#default>

<div></div>

</#switch>

</#list>

</#list>

 

 

Please Help Me :catembarrassed:

1 Reply

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

    Maikinos try this code:

     

    <#assign userStar = rest("2.0","/search?q=" + "SELECT * FROM roles WHERE users.id = '${user.id}'"?url) />
    
    <#list userStar.data.items as role >
        <p>${role.name}</p>
    
    <#switch role.name>
    
    <#case 'Nivel_Test1'>
    <div class="banner_cr"><img src="
    ${asset.get("/html/assets/imagen.jpg")}" /></div>
    <#break>
    <#case 'Nivel_Test2'>
    <div class="banner_cr"><img src="
    ${asset.get("/html/assets/imagen.jpg")}" /></div>
    <#break>
    <#case 'Nivel_Test3'>
    <div class="banner_cr"><img src="
    ${asset.get("/html/assets/imagen.jpg")}" /></div>
    <#break>
    
    <#case 'Administrator'>
    <div class="banner_cr">Welcome Administrator!</div>
    <#break>
    
    <#default>
    
    <div></div>
    
    </#switch>
    
    </#list>
    

    You can remove this line, it was just for debugging purpose:

     

    <p>${role.name}</p>

    And this line too, it's just because I don't have your roles:

    <#case 'Administrator'>
    <div class="banner_cr">Welcome Administrator!</div>
    <#break>