You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2021/08/17 15:29:20 UTC

[superset] 01/01: setup rbac

This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch hugh/rbac-global
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 542353b4d5587620302fa72e01d14e9cbd8aa377
Author: hughhhh <hu...@gmail.com>
AuthorDate: Mon Aug 16 19:48:38 2021 -0400

    setup rbac
---
 .../src/components/Menu/MenuRight.tsx              | 46 ++++++++++++++++------
 1 file changed, 35 insertions(+), 11 deletions(-)

diff --git a/superset-frontend/src/components/Menu/MenuRight.tsx b/superset-frontend/src/components/Menu/MenuRight.tsx
index 35d2cb0..2aff1d3 100644
--- a/superset-frontend/src/components/Menu/MenuRight.tsx
+++ b/superset-frontend/src/components/Menu/MenuRight.tsx
@@ -21,24 +21,44 @@ import { MainNav as Menu } from 'src/common/components';
 import { t, styled, css, SupersetTheme } from '@superset-ui/core';
 import { Link } from 'react-router-dom';
 import Icons from 'src/components/Icons';
+import findPermission from 'src/dashboard/util/findPermission';
 import LanguagePicker from './LanguagePicker';
 import { NavBarProps, MenuObjectProps } from './Menu';
 
+const appContainer = document.getElementById('app') || '{}';
+const bootstrapData = JSON.parse(appContainer.getAttribute('data-bootstrap'));
+console.log('userRoles', bootstrapData.user.roles);
+
+const { roles } = bootstrapData.user;
+console.log(findPermission('can_dashboard', 'Superset', roles));
+console.log(findPermission('can_sqllab', 'Superset', roles));
+console.log(findPermission('can_slice', 'Superset', roles));
+
+const canChart = findPermission('can_write', 'Chart', roles);
+const canSql = findPermission('can_sqllab', 'Superset', roles);
+const canDashboard = findPermission('can_write', 'Dashboard', roles);
+
+// if user has any of these roles the dropdown will appear
+const showActionDropdown = canChart || canSql || canDashboard;
+
 export const dropdownItems = [
   {
     label: t('SQL query'),
     url: '/superset/sqllab?new=true',
     icon: 'fa-fw fa-search',
+    show: canSql,
   },
   {
     label: t('Chart'),
     url: '/chart/add',
     icon: 'fa-fw fa-bar-chart',
+    show: canChart,
   },
   {
     label: t('Dashboard'),
     url: '/dashboard/new',
     icon: 'fa-fw fa-dashboard',
+    show: canDashboard,
   },
 ];
 
@@ -94,17 +114,21 @@ const RightMenu = ({
           }
           icon={<Icons.TriangleDown />}
         >
-          {dropdownItems.map(menu => (
-            <Menu.Item key={menu.label}>
-              <a href={menu.url}>
-                <i
-                  data-test={`menu-item-${menu.label}`}
-                  className={`fa ${menu.icon}`}
-                />{' '}
-                {menu.label}
-              </a>
-            </Menu.Item>
-          ))}
+          {showActionDropdown &&
+            dropdownItems.map(
+              menu =>
+                menu.show && (
+                  <Menu.Item key={menu.label}>
+                    <a href={menu.url}>
+                      <i
+                        data-test={`menu-item-${menu.label}`}
+                        className={`fa ${menu.icon}`}
+                      />{' '}
+                      {menu.label}
+                    </a>
+                  </Menu.Item>
+                ),
+            )}
         </SubMenu>
       )}
       <SubMenu title="Settings" icon={<Icons.TriangleDown iconSize="xl" />}>