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

amitmiran pushed a commit to branch feat/can_share_chart
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 1c6134ff4a14d4aa879daea6b018aaa335ac5503
Author: amitmiran137 <[email protected]>
AuthorDate: Sun Apr 11 20:19:40 2021 +0300

    feat: share chart  - can_share_chart
    share dashboard can_share_dashboard
---
 .../src/dashboard/components/Header.jsx            |  2 ++
 .../dashboard/components/HeaderActionsDropdown.jsx | 22 +++++++++++++---------
 .../src/dashboard/reducers/getInitialState.js      |  1 +
 superset/security/manager.py                       |  3 ++-
 superset/views/core.py                             |  6 ++++--
 tests/security_tests.py                            |  8 ++++----
 6 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/superset-frontend/src/dashboard/components/Header.jsx 
b/superset-frontend/src/dashboard/components/Header.jsx
index 8ad6c57..3bc68b0 100644
--- a/superset-frontend/src/dashboard/components/Header.jsx
+++ b/superset-frontend/src/dashboard/components/Header.jsx
@@ -376,6 +376,7 @@ class Header extends React.PureComponent {
     } = this.props;
 
     const userCanEdit = dashboardInfo.dash_edit_perm;
+    const userCanShare = dashboardInfo.dash_share_perm;
     const userCanSaveAs = dashboardInfo.dash_save_perm;
     const refreshLimit =
       dashboardInfo.common.conf.SUPERSET_DASHBOARD_PERIODICAL_REFRESH_LIMIT;
@@ -543,6 +544,7 @@ class Header extends React.PureComponent {
             editMode={editMode}
             hasUnsavedChanges={hasUnsavedChanges}
             userCanEdit={userCanEdit}
+            userCanShare={userCanShare}
             userCanSave={userCanSaveAs}
             isLoading={isLoading}
             showPropertiesModal={this.showPropertiesModal}
diff --git 
a/superset-frontend/src/dashboard/components/HeaderActionsDropdown.jsx 
b/superset-frontend/src/dashboard/components/HeaderActionsDropdown.jsx
index 5d27f1f..ba255fb 100644
--- a/superset-frontend/src/dashboard/components/HeaderActionsDropdown.jsx
+++ b/superset-frontend/src/dashboard/components/HeaderActionsDropdown.jsx
@@ -54,6 +54,7 @@ const propTypes = {
   startPeriodicRender: PropTypes.func.isRequired,
   editMode: PropTypes.bool.isRequired,
   userCanEdit: PropTypes.bool.isRequired,
+  userCanShare: PropTypes.bool.isRequired,
   userCanSave: PropTypes.bool.isRequired,
   isLoading: PropTypes.bool.isRequired,
   layout: PropTypes.object.isRequired,
@@ -192,6 +193,7 @@ class HeaderActionsDropdown extends React.PureComponent {
       expandedSlices,
       onSave,
       userCanEdit,
+      userCanShare,
       userCanSave,
       isLoading,
       refreshLimit,
@@ -241,15 +243,17 @@ class HeaderActionsDropdown extends React.PureComponent {
             />
           </Menu.Item>
         )}
-        <ShareMenuItems
-          url={url}
-          copyMenuItemTitle={t('Copy dashboard URL')}
-          emailMenuItemTitle={t('Share dashboard by email')}
-          emailSubject={emailSubject}
-          emailBody={emailBody}
-          addSuccessToast={addSuccessToast}
-          addDangerToast={addDangerToast}
-        />
+        {userCanShare && (
+          <ShareMenuItems
+            url={url}
+            copyMenuItemTitle={t('Copy dashboard URL')}
+            emailMenuItemTitle={t('Share dashboard by email')}
+            emailSubject={emailSubject}
+            emailBody={emailBody}
+            addSuccessToast={addSuccessToast}
+            addDangerToast={addDangerToast}
+          />
+        )}
         <Menu.Item
           key={MENU_KEYS.REFRESH_DASHBOARD}
           data-test="refresh-dashboard-menu-item"
diff --git a/superset-frontend/src/dashboard/reducers/getInitialState.js 
b/superset-frontend/src/dashboard/reducers/getInitialState.js
index ecbb4fa..2a05ca6 100644
--- a/superset-frontend/src/dashboard/reducers/getInitialState.js
+++ b/superset-frontend/src/dashboard/reducers/getInitialState.js
@@ -274,6 +274,7 @@ export default function getInitialState(bootstrapData) {
       metadata: dashboard.metadata,
       userId: user_id,
       dash_edit_perm: dashboard.dash_edit_perm,
+      dash_share_perm: dashboard.dash_share_perm,
       dash_save_perm: dashboard.dash_save_perm,
       superset_can_explore: dashboard.superset_can_explore,
       superset_can_share: dashboard.superset_can_share,
diff --git a/superset/security/manager.py b/superset/security/manager.py
index 42f70ea..6472af6 100644
--- a/superset/security/manager.py
+++ b/superset/security/manager.py
@@ -556,7 +556,8 @@ class SupersetSecurityManager(  # pylint: 
disable=too-many-public-methods
         self.add_permission_view_menu("all_datasource_access", 
"all_datasource_access")
         self.add_permission_view_menu("all_database_access", 
"all_database_access")
         self.add_permission_view_menu("all_query_access", "all_query_access")
-        self.add_permission_view_menu("can_share", "Superset")
+        self.add_permission_view_menu("can_share_dashboard", "Superset")
+        self.add_permission_view_menu("can_share_chart", "Superset")
 
     def create_missing_perms(self) -> None:
         """
diff --git a/superset/views/core.py b/superset/views/core.py
index 13dfcc5..5f6d093 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1838,7 +1838,8 @@ class Superset(BaseSupersetView):  # pylint: 
disable=too-many-public-methods
         ) and security_manager.can_access("can_save_dash", "Superset")
         dash_save_perm = security_manager.can_access("can_save_dash", 
"Superset")
         superset_can_explore = security_manager.can_access("can_explore", 
"Superset")
-        superset_can_share = security_manager.can_access("can_share", 
"Superset")
+        superset_can_share_chart = 
security_manager.can_access("can_share_chart", "Superset")
+        superset_can_share_dashboard = 
security_manager.can_access("can_share_dashboard", "Superset")
         superset_can_csv = security_manager.can_access("can_csv", "Superset")
         slice_can_edit = security_manager.can_access("can_edit", 
"SliceModelView")
         standalone_mode = ReservedUrlParameters.is_standalone_mode()
@@ -1875,9 +1876,10 @@ class Superset(BaseSupersetView):  # pylint: 
disable=too-many-public-methods
                 **data["dashboard"],
                 "standalone_mode": standalone_mode,
                 "dash_save_perm": dash_save_perm,
+                "dash_share_perm": superset_can_share_dashboard,
                 "dash_edit_perm": dash_edit_perm,
                 "superset_can_explore": superset_can_explore,
-                "superset_can_share": superset_can_share,
+                "superset_can_share": superset_can_share_chart,
                 "superset_can_csv": superset_can_csv,
                 "slice_can_edit": slice_can_edit,
             },
diff --git a/tests/security_tests.py b/tests/security_tests.py
index 0ed8dde..f7e5517 100644
--- a/tests/security_tests.py
+++ b/tests/security_tests.py
@@ -670,14 +670,13 @@ class TestRolePermission(SupersetTestCase):
         self.assertIn(("can_csv", "Superset"), perm_set)
         self.assertIn(("can_dashboard", "Superset"), perm_set)
         self.assertIn(("can_explore", "Superset"), perm_set)
-        self.assertIn(("can_share", "Superset"), perm_set)
+        self.assertIn(("can_share_chart", "Superset"), perm_set)
+        self.assertIn(("can_share_dashboard", "Superset"), perm_set)
         self.assertIn(("can_explore_json", "Superset"), perm_set)
         self.assertIn(("can_fave_dashboards", "Superset"), perm_set)
         self.assertIn(("can_fave_slices", "Superset"), perm_set)
         self.assertIn(("can_save_dash", "Superset"), perm_set)
         self.assertIn(("can_slice", "Superset"), perm_set)
-        self.assertIn(("can_explore", "Superset"), perm_set)
-        self.assertIn(("can_share", "Superset"), perm_set)
         self.assertIn(("can_explore_json", "Superset"), perm_set)
         self.assertIn(("can_userinfo", "UserDBModelView"), perm_set)
         self.assert_can_menu("Databases", perm_set)
@@ -870,7 +869,8 @@ class TestRolePermission(SupersetTestCase):
         self.assertIn(("can_csv", "Superset"), gamma_perm_set)
         self.assertIn(("can_dashboard", "Superset"), gamma_perm_set)
         self.assertIn(("can_explore", "Superset"), gamma_perm_set)
-        self.assertIn(("can_share", "Superset"), gamma_perm_set)
+        self.assertIn(("can_share_chart", "Superset"), gamma_perm_set)
+        self.assertIn(("can_share_dashboard", "Superset"), gamma_perm_set)
         self.assertIn(("can_explore_json", "Superset"), gamma_perm_set)
         self.assertIn(("can_fave_dashboards", "Superset"), gamma_perm_set)
         self.assertIn(("can_fave_slices", "Superset"), gamma_perm_set)

Reply via email to