Forum Discussion

fxbauer's avatar
fxbauer
Lithium Alumni (Retired)
13 years ago

How do I show custom text based on permissions?

Hello

 

a customer is asking to show certain text based on a permission granted to a user.

 

In this case the customer wants to show a link "Private Message" instead of just the envelope icon.

I reviewed the REST API doc but was not able to get a way how to retrieve the information if a user has a certainpermission granted or not. Only Roles are available.

 

 

  • We did this exact same thing with the Private Messages icon --> text.  However, we create roles to represent certain actions (as I have not seen a way to access permissions programmatically).  You could add the specific permissions to those roles, or simply use the roles as a placeholder.  For example, we created a Publisher role that we assign to certain users.  We can control content using:

     

    <#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
      <#if role.name?? && ((role.name == "Administrator") || (role.name == "Publisher"))>
        <#assign user_has_role = true />
      </#if>
    </#list>
    
    ...
    
    <#if user_has_role>
    
    ...
    
    </#if>

     

  • We did this exact same thing with the Private Messages icon --> text.  However, we create roles to represent certain actions (as I have not seen a way to access permissions programmatically).  You could add the specific permissions to those roles, or simply use the roles as a placeholder.  For example, we created a Publisher role that we assign to certain users.  We can control content using:

     

    <#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
      <#if role.name?? && ((role.name == "Administrator") || (role.name == "Publisher"))>
        <#assign user_has_role = true />
      </#if>
    </#list>
    
    ...
    
    <#if user_has_role>
    
    ...
    
    </#if>