Forum Discussion
Parshant
6 years agoBoss
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>
diptikaushikkar
6 years agoGuide
Is there any way where i can avoid making this rest call to fetch roles?? Some predefined function which returns me roles??