Forum Discussion
You can use below code in your custom component with this function to re-use in areas.
<#function user_has_role (id, roles)> <#assign liql = "SELECT id FROM users WHERE roles.name IN (${roles}) and id = '${id}'" /> <#assign query = rest("2.0","/search?q=" + liql?url) /> <#if (query.status == "success") && query.data.size gt 0> <#return true> <#else> <#return false> </#if> </#function>
and call it like this:
<#if user.registered && user_has_role(user.id,"'Administrator', 'Developer'")> ... </#if>
Parshant This works great for me! But I would like to also PREVENT a link from showing up for a certain role. Could you help me with that? I'm showing Software Notifications to anyone with role "CARRIER_CUSTOMER" - how can I hide Discussions from that same role?
<#function user_has_role (id, roles)>
<#assign liql = "SELECT id FROM users WHERE roles.name IN (${roles}) and id = '${id}'" />
<#assign query = rest("2.0","/search?q=" + liql?url) />
<#if (query.status == "success") && query.data.size gt 0>
<#return true>
<#else>
<#return false>
</#if>
</#function>
<a href="/t5/Discussion/ct-p/discussion">Discussions</a><br>
<a href="/t5/Product-Notices/ct-p/product-notices-doc">Product Notices</a><br>
<#if user.registered && user_has_role(user.id,"'Administrator'")>
<a href="/t5/Software-Notifications/ct-p/software-notifications">Software Notifications</a><br>
</#if>
- Parshant5 years agoBoss
Your code should be,
<#function user_has_role (id, roles)> <#assign liql = "SELECT id FROM users WHERE roles.name IN (${roles}) and id = '${id}'" /> <#assign query = rest("2.0","/search?q=" + liql?url) /> <#if (query.status == "success") && query.data.size gt 0> <#return true> <#else> <#return false> </#if> </#function> <#if user.registered && user_has_role(user.id,"'CARRIER_CUSTOMER'")> <#else> <a href="/t5/Discussion/ct-p/discussion">Discussions</a><br> </#if> <a href="/t5/Product-Notices/ct-p/product-notices-doc">Product Notices</a><br> <#if user.registered && user_has_role(user.id,"'CARRIER_CUSTOMER'")> <a href="/t5/Software-Notifications/ct-p/software-notifications">Software Notifications</a><br> </#if>
Related Content
- 11 months ago
- 2 years ago