Forum Discussion

Astroraf's avatar
Astroraf
Data Pipeline
02-13-2025
Solved

How to limit use of a Blox Button based on a user

I am working with a dashboard that uses multiple JTD BloX widgets, where I want one of these JTD BloX Widgets to hide based on a user who is accessing it. This will be set for multiple users, but I w...
  • AssafHanina's avatar
    AssafHanina
    02-24-2025

    Hey Astroraf ,

    You may leverage the Solution shared in the following Article which provide a dashboard script to hide a list of widgets per certain groups. 

    Dashboard Script:

    1. Exclude list of Group ID's (it's better to maintain it by Groups)
    2. Exclude list of Widget OID's 

    Notes:

    1. If the widget to hide is one widget in a row, the widget will be completely gone
    2. If the widget to hide is not a single widget, it will present as Blanc. 
      for the Blanc, it's possible to add Custom text such as "No Data" 

    Please find examples

    Before adding the dashboard script

    After Applying the Dashboard Script

    dashboard.on('widgetrefreshed', function (se, ev) {
        
        let groupList = ['6304bbc0b983e6001a5565dc']; // List of restricted groups
        let widgetList = ['67bc96075d519d0040285d02', '67bc9a975d519d0040285d1f']; // List of widgets to hide
    
        let isRestrictedUser = prism.user.groups.some(group => groupList.includes(group));
    
    
        // Hide widget if it's in widgetList and the user is in a restricted group
        if (isRestrictedUser && widgetList.includes(ev.widget.oid)) {
    
            let widgetElement = $(`widget[widgetid="${ev.widget.oid}"]`).closest('.dashboard-layout-subcell-host');
            
            // Remove the widget from the dashboard layout
            widgetElement.remove();
        }
    });

    Dashboard Script with custom Text 

     

    dashboard.on('widgetrefreshed', function (se, ev) {
        
        let groupList = ['6304bbc0b983e6001a5565dc']; // List of restricted groups
        let widgetList = ['67bc96075d519d0040285d02','67bc9a975d519d0040285d1f']; // List of widgets to hide
        var text = "No Content"; // Text to display when widget is hidden
    
        let isRestrictedUser = prism.user.groups.some(group => groupList.includes(group));
    
        // Hide widget if it's in widgetList and the user is in a restricted group
        if (isRestrictedUser && widgetList.includes(ev.widget.oid)) {
            console.log(`Replacing widget content with: "${text}" for widget: ${ev.widget.oid}`);
    
            let widgetElement = $(`widget[widgetid="${ev.widget.oid}"]`).closest('.dashboard-layout-subcell-host');
            
            // Clear widget content and replace it with custom text
            widgetElement.html(`<div class="no-content-message" style="text-align:center; padding:20px; font-size:16px; font-weight:bold; color:#888;">${text}</div>`);
        }
    });

    Best Regards

  • Astroraf's avatar
    03-07-2025

    Hi DRay, this is the code that rapidbisupport  provided. 

    The oid is the ID of the BloX widget I was trying to hide or even the widget you may be trying to hide, and the hideGroup is the name of the group given in your environment that you need to Block access to. 

     

    let widgetHideRules = [
        {
            "oid": "67b31d3ffd9c6500324085bb",
            "hideGroupName": "hideGroup"
        },
    	{
            "oid": "67b31d4cfd9c6500324085bf",
            "hideGroupName": "hideGroup"
        }
    	
    ]
    
    function hideWidget(widgetOid) {
        let a, b, c, d
        // remove the widget
        // find widget position in $$widgets
        const wPos = dashboard.widgets.$$widgets.map((w) => { return w.oid }).indexOf(widgetOid)
        dashboard.widgets.$$widgets.splice(wPos, 1)
        // remove the subcell containing the widget from the layout
        dashboard.layout.columns.forEach((column, i) => {
            column.cells.forEach((cell, j) => {
                cell.subcells.forEach((subcell, k) => {
                    subcell.elements.forEach((element, l) => {
                        if (!defined(element.widgetid)) { return }
                        if (element.widgetid === widgetOid) {
                            a = i
                            b = j
                            c = k
                            d = l
                        }
                    })
                })
            })
        })
        dashboard.layout.columns[a].cells[b].subcells.splice(c, 1)
    }
    
    dashboard.on('initialized', (dashboard) => {
        const hideRulesLength = widgetHideRules.length
        for (let i = 0; i < hideRulesLength; i++) {
            const hideRule = widgetHideRules[i]
            if (!prism.user.groupsName.map((gn) => { return gn.name }).includes(hideRule.hideGroupName)) { return }
            hideWidget(hideRule.oid)
        }
    })