Hide a component on workspace based on role

Tapish Sharma1
Kilo Sage

Hi Folks, 

I have added a data visualization single score component on landing page of a workspace. I want to make it visible to only certain roles .... How can I configure it ? 

1 ACCEPTED SOLUTION

kamlesh kjmar
Mega Sage
Mega Sage

Hello Tapish,

You can use componen visibilty for this. Follow the below steps to acheive it :

 

1. To do this click on the component that you need to hide and go to the configuration panel and click on 'Edit component visibility' button indicated by 'eye' symbol, shown below

kamlesh8_0-1666190679267.png

 

2. Hover over the Hide component, it will show you some buttons. Click on the code button indicated by '</>' sysmbol. This will open a popup page where you can script

kamlesh8_1-1666191032818.png

 

3. Use the below script and modify role as per your requirement:

 

/**
 * @Param {params} params
 * @Param {api} params.api
 * @Param {TransformApiHelpers} params.helpers
 */
function evaluateProperty({
    api,
    helpers
}) {
    var roles = api.context.session.user.roles;
    if (roles.indexOf('admin') > -1 || roles.indexOf('cmdb_manager') > -1)
        return false;
    else
        return true;

}
 
kamlesh8_2-1666191329209.png

 

 
Above script says show the report only to people having admin role or cmdb_manager role. For every one else it will be hidden.
 
Please let me know if this works/don't works for you.
 

I Hope this helps.

 

Please mark this helpful if this helps and mark as correct if this solves your issue.

 

Regards,

Kamlesh

 

 

 

 

View solution in original post

10 REPLIES 10

Vivek Verma
Mega Sage
Mega Sage

Hello @kamlesh kjmar , Thank you for the solution. I have an additional question: can you help me find out how to show the component to users from a specific group only?