Forum Discussion

mayank's avatar
11 years ago

Only Group creators can see Groups

Can anyone please help me so that only Group Creators(Role) can see Groups.

 

<#if user.anonymous == false>
    <@component id="groups.widget.group-list-view"/>
</#if>

 

How can i used a group role check here...Please help

  • I'm a little late to the party, but I wanted to share a function that I'll often use for seeing if a user has a specific role:

    <#-- function: userHasRole
    	Returns true if the user with the specified userId has been granted the role specified by testRole 
    	param: userId - Number (not a string) corresponding to the user id of the user to obtain the setting data for
    	param: testRole - String containing the name of the role
    	return: true if the user has been granted the role, false otherwise
    	usage: ${userHasRole(user.id,"Administrator")?string}
    -->
    <#function userHasRole userId testRole>
    	<#if (userId)?? && userId?is_number && (userId gt 0) >
    		<#attempt>
    			<#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
    			    <#if role.name?? && (role.name == testRole)>
    					<#return true />
    				</#if>
    			</#list>
    		<#recover>
    			<#return false />
    		</#attempt>
    	</#if>
    	<#return false />
    </#function>

     Sample usage:

    <#if userHasRole(user.id,"Administrator")>
    You're an admin!
    </#if>
    <#if userHasRole(user.id,"VIP")>
    You're a VIP!
    </#if>

     

     

  • AdamN's avatar
    AdamN
    Khoros Oracle

    I'm a little late to the party, but I wanted to share a function that I'll often use for seeing if a user has a specific role:

    <#-- function: userHasRole
    	Returns true if the user with the specified userId has been granted the role specified by testRole 
    	param: userId - Number (not a string) corresponding to the user id of the user to obtain the setting data for
    	param: testRole - String containing the name of the role
    	return: true if the user has been granted the role, false otherwise
    	usage: ${userHasRole(user.id,"Administrator")?string}
    -->
    <#function userHasRole userId testRole>
    	<#if (userId)?? && userId?is_number && (userId gt 0) >
    		<#attempt>
    			<#list restadmin("/users/id/${user.id?c}/roles").roles.role as role>
    			    <#if role.name?? && (role.name == testRole)>
    					<#return true />
    				</#if>
    			</#list>
    		<#recover>
    			<#return false />
    		</#attempt>
    	</#if>
    	<#return false />
    </#function>

     Sample usage:

    <#if userHasRole(user.id,"Administrator")>
    You're an admin!
    </#if>
    <#if userHasRole(user.id,"VIP")>
    You're a VIP!
    </#if>

     

     

  • Hi,

     

    You can try this snippet

     

    <#assign restStr = "/users/id/${user.id}/roles">
    <#assign matchedRoles=[]>
    <#assign userRoles = restadmin(restStr).roles.role>

     

    <#list userRoles as role>
            <#assign matchedRoles=matchedRoles+role.name>
    </#list>


    <#if (matchedRoles?seq_contains("Group Creators") >
           <@component id="groups.widget.group-list-view"/>
    </#if>

     

    Hope this helps. If yes, please accept this as a solution. 

     

    Thanks,
    Premkumar

    • mayank's avatar
      mayank
      Ace
      Freemarker template 'preview' parsing failed:
      ParseException:Parsing error in template "preview" in line 13, column 8:
      Encountered "<", but was expecting one of:
          
      • premkumar's avatar
        premkumar
        Advisor

        Please check your code for the Syntax. Else share your code which I can have a look at. 

         

        Thanks,
        Premkumar