Forum Discussion

AaronBenjamin67's avatar
13 years ago

Component Permissions

Is it possible to only show certain components to select user groups? 

 

Ex..

 

Only "Power users" will be able to see 'Custom Component 1'

 

thanks,

  • Within your custom component, you'll need to wrap your content with a freemarker expression that will dictate when to display the content. Use the following links as refrence guides, but i'm imaginging you would write something like...

     

    Using FreeMarker expressions to personalize annoucements and custom components

     

    Context Objects for Custom Components

     

     

     

    <#assign user_has_role = false />
       <#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
          <#if role.name?? && ((role.name == "PowerUser"))>
             <#assign user_has_role = true />
          </#if>
       </#list>
       <#if user_has_role >
        <!-- Content goes here -->
       <#else>
       </#if>

     

     

    However writing your freemarker around premissions instead of roles is preferred because roles can be changed but generally permissions aren't.  e.g.: a component for admin and mod users (or anyone else) who has the premission to update the community (orig exmaple and thread here)

     

    <#if coreNode.permissions.hasPermission("update_community")>
      <!-- Content goes here -->
    </#if>

     Hope that helps.

4 Replies

  • MoniqueL's avatar
    MoniqueL
    Lithium Alumni (Retired)
    13 years ago

    Within your custom component, you'll need to wrap your content with a freemarker expression that will dictate when to display the content. Use the following links as refrence guides, but i'm imaginging you would write something like...

     

    Using FreeMarker expressions to personalize annoucements and custom components

     

    Context Objects for Custom Components

     

     

     

    <#assign user_has_role = false />
       <#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
          <#if role.name?? && ((role.name == "PowerUser"))>
             <#assign user_has_role = true />
          </#if>
       </#list>
       <#if user_has_role >
        <!-- Content goes here -->
       <#else>
       </#if>

     

     

    However writing your freemarker around premissions instead of roles is preferred because roles can be changed but generally permissions aren't.  e.g.: a component for admin and mod users (or anyone else) who has the premission to update the community (orig exmaple and thread here)

     

    <#if coreNode.permissions.hasPermission("update_community")>
      <!-- Content goes here -->
    </#if>

     Hope that helps.

  • Can't see those links... I'm getting "Sorry, you do not have sufficient privileges for that action.
    Please click the Back button on your browser."
  • KaelaC's avatar
    KaelaC
    Lithium Alumni (Retired)
    13 years ago

    To have access to those links you will need to have the Customer role in the Lithosphere.  The Customer link in the top nav will be clickable.  If you don't have that, open a support case or contact your account manager.