cancel
Showing results for 
Search instead for 
Did you mean: 

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

Astroraf
11 - Data Pipeline

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 wanted to see if there are any solutions out there. 

@DRay @Liliia_DevX 

2 ACCEPTED SOLUTIONS

AssafHanina
Sisense Team Member

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

AssafHanina_0-1740429854323.png

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();
    }
});

AssafHanina_1-1740430181506.png

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

Assaf

View solution in original post

Astroraf
11 - Data Pipeline

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)
    }
})

 

 

View solution in original post

7 REPLIES 7

DRay
Community Team Leader

Astroraf
11 - Data Pipeline

HI @DRay

This does seem to be what I am looking for, but I have a question regarding the code. Hey @rapidbisupport, regarding this solution { https://community.sisense.com/t5/build-analytics/hide-blox-title-header-based-on-customer-group-id/t...}, in the code: 

 

dashboard.on('domready', () => {
    console.log('dashboard initialized');
    const userGroups = prism.user.groups;

    // Hide #cashflow for specific group
    if (userGroups.includes("659740b5f1a21c003908f3a4")) {
        $('#ITEM1').hide();
    } else {
        // hide cashoutflow
        //$('#cashoutflow').remove();
    }
});

 

The userGroup is the ID of the group I want the JTD BloX widget to be hidden and #ITEM is the title of the JTD I give in the BloX editor? 

 

AssafHanina
Sisense Team Member

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

AssafHanina_0-1740429854323.png

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();
    }
});

AssafHanina_1-1740430181506.png

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

Assaf

DRay
Community Team Leader

Hello @Astroraf,

I’m following up to see if the solution offered by @AssafHanina worked for you.

If so, please click the 'Accept as Solution' button on the appropriate post. That way other users with the same questions can find the answer. If not, please let us know so that we can continue to help.

Thank you.

David Raynor (DRay)

Astroraf
11 - Data Pipeline

Hey @DRay I found another solution to this. Thanks 

DRay
Community Team Leader

Thank you for the update @Astroraf. How did you end up resolving it?

David Raynor (DRay)

Astroraf
11 - Data Pipeline

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)
    }
})

 

 

Type a product name