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 896b5fbb16c86ff098281fe23d304c39ecaff342
Author: amitmiran137 <[email protected]>
AuthorDate: Sun Apr 11 15:01:45 2021 +0300

    feat: share chart  - can_share
---
 .../src/dashboard/components/SliceHeader/index.tsx |  3 +++
 .../components/SliceHeaderControls/index.jsx       | 29 ++++++++++++----------
 .../dashboard/components/gridComponents/Chart.jsx  |  3 +++
 .../src/dashboard/containers/Chart.jsx             |  1 +
 .../src/dashboard/reducers/getInitialState.js      |  1 +
 superset/security/manager.py                       |  1 +
 superset/views/core.py                             |  2 ++
 tests/security_tests.py                            |  3 +++
 8 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/superset-frontend/src/dashboard/components/SliceHeader/index.tsx 
b/superset-frontend/src/dashboard/components/SliceHeader/index.tsx
index 875852c..72bd089 100644
--- a/superset-frontend/src/dashboard/components/SliceHeader/index.tsx
+++ b/superset-frontend/src/dashboard/components/SliceHeader/index.tsx
@@ -46,6 +46,7 @@ type SliceHeaderProps = {
   annotationError?: object;
   sliceName?: string;
   supersetCanExplore?: boolean;
+  supersetCanShare?: boolean;
   supersetCanCSV?: boolean;
   sliceCanEdit?: boolean;
   componentId: string;
@@ -83,6 +84,7 @@ const SliceHeader: FC<SliceHeaderProps> = ({
   isExpanded = [],
   sliceName = '',
   supersetCanExplore = false,
+  supersetCanShare = false,
   supersetCanCSV = false,
   sliceCanEdit = false,
   slice,
@@ -172,6 +174,7 @@ const SliceHeader: FC<SliceHeaderProps> = ({
               exploreChart={exploreChart}
               exportCSV={exportCSV}
               supersetCanExplore={supersetCanExplore}
+              supersetCanShare={supersetCanShare}
               supersetCanCSV={supersetCanCSV}
               sliceCanEdit={sliceCanEdit}
               componentId={componentId}
diff --git 
a/superset-frontend/src/dashboard/components/SliceHeaderControls/index.jsx 
b/superset-frontend/src/dashboard/components/SliceHeaderControls/index.jsx
index edef021..2219991 100644
--- a/superset-frontend/src/dashboard/components/SliceHeaderControls/index.jsx
+++ b/superset-frontend/src/dashboard/components/SliceHeaderControls/index.jsx
@@ -43,6 +43,7 @@ const propTypes = {
   isExpanded: PropTypes.bool,
   updatedDttm: PropTypes.number,
   supersetCanExplore: PropTypes.bool,
+  supersetCanShare: PropTypes.bool,
   supersetCanCSV: PropTypes.bool,
   sliceCanEdit: PropTypes.bool,
   toggleExpandSlice: PropTypes.func,
@@ -61,6 +62,7 @@ const defaultProps = {
   isCached: [],
   isExpanded: false,
   supersetCanExplore: false,
+  supersetCanShare: false,
   supersetCanCSV: false,
   sliceCanEdit: false,
 };
@@ -72,7 +74,6 @@ const MENU_KEYS = {
   EXPLORE_CHART: 'explore_chart',
   EXPORT_CSV: 'export_csv',
   RESIZE_LABEL: 'resize_label',
-  SHARE_CHART: 'share_chart',
   DOWNLOAD_AS_IMAGE: 'download_as_image',
 };
 
@@ -253,18 +254,20 @@ class SliceHeaderControls extends React.PureComponent {
           </Menu.Item>
         )}
 
-        <ShareMenuItems
-          url={getDashboardUrl(
-            window.location.pathname,
-            getActiveFilters(),
-            componentId,
-          )}
-          copyMenuItemTitle={t('Copy chart URL')}
-          emailMenuItemTitle={t('Share chart by email')}
-          emailSubject={t('Superset chart')}
-          addSuccessToast={addSuccessToast}
-          addDangerToast={addDangerToast}
-        />
+        {this.props.supersetCanShare && (
+          <ShareMenuItems
+            url={getDashboardUrl(
+              window.location.pathname,
+              getActiveFilters(),
+              componentId,
+            )}
+            copyMenuItemTitle={t('Copy chart URL')}
+            emailMenuItemTitle={t('Share chart by email')}
+            emailSubject={t('Superset chart')}
+            addSuccessToast={addSuccessToast}
+            addDangerToast={addDangerToast}
+          />
+        )}
 
         <Menu.Item key={MENU_KEYS.RESIZE_LABEL}>{resizeLabel}</Menu.Item>
 
diff --git 
a/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx 
b/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx
index 18cec53..bfe775e 100644
--- a/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx
+++ b/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx
@@ -65,6 +65,7 @@ const propTypes = {
   isExpanded: PropTypes.bool.isRequired,
   isCached: PropTypes.bool,
   supersetCanExplore: PropTypes.bool.isRequired,
+  supersetCanShare: PropTypes.bool.isRequired,
   supersetCanCSV: PropTypes.bool.isRequired,
   sliceCanEdit: PropTypes.bool.isRequired,
   addSuccessToast: PropTypes.func.isRequired,
@@ -256,6 +257,7 @@ export default class Chart extends React.Component {
       toggleExpandSlice,
       timeout,
       supersetCanExplore,
+      supersetCanShare,
       supersetCanCSV,
       sliceCanEdit,
       addSuccessToast,
@@ -311,6 +313,7 @@ export default class Chart extends React.Component {
           updateSliceName={updateSliceName}
           sliceName={sliceName}
           supersetCanExplore={supersetCanExplore}
+          supersetCanShare={supersetCanShare}
           supersetCanCSV={supersetCanCSV}
           sliceCanEdit={sliceCanEdit}
           componentId={componentId}
diff --git a/superset-frontend/src/dashboard/containers/Chart.jsx 
b/superset-frontend/src/dashboard/containers/Chart.jsx
index 94f88d3..31c0e32 100644
--- a/superset-frontend/src/dashboard/containers/Chart.jsx
+++ b/superset-frontend/src/dashboard/containers/Chart.jsx
@@ -84,6 +84,7 @@ function mapStateToProps(
     editMode: dashboardState.editMode,
     isExpanded: !!dashboardState.expandedSlices[id],
     supersetCanExplore: !!dashboardInfo.superset_can_explore,
+    supersetCanShare: !!dashboardInfo.superset_can_share,
     supersetCanCSV: !!dashboardInfo.superset_can_csv,
     sliceCanEdit: !!dashboardInfo.slice_can_edit,
     ownCurrentState: dataMask.ownFilters?.[id]?.currentState,
diff --git a/superset-frontend/src/dashboard/reducers/getInitialState.js 
b/superset-frontend/src/dashboard/reducers/getInitialState.js
index 19ea54e..ecbb4fa 100644
--- a/superset-frontend/src/dashboard/reducers/getInitialState.js
+++ b/superset-frontend/src/dashboard/reducers/getInitialState.js
@@ -276,6 +276,7 @@ export default function getInitialState(bootstrapData) {
       dash_edit_perm: dashboard.dash_edit_perm,
       dash_save_perm: dashboard.dash_save_perm,
       superset_can_explore: dashboard.superset_can_explore,
+      superset_can_share: dashboard.superset_can_share,
       superset_can_csv: dashboard.superset_can_csv,
       slice_can_edit: dashboard.slice_can_edit,
       common: {
diff --git a/superset/security/manager.py b/superset/security/manager.py
index 1c4419c..42f70ea 100644
--- a/superset/security/manager.py
+++ b/superset/security/manager.py
@@ -556,6 +556,7 @@ 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")
 
     def create_missing_perms(self) -> None:
         """
diff --git a/superset/views/core.py b/superset/views/core.py
index 0093f50..13dfcc5 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1838,6 +1838,7 @@ 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_csv = security_manager.can_access("can_csv", "Superset")
         slice_can_edit = security_manager.can_access("can_edit", 
"SliceModelView")
         standalone_mode = ReservedUrlParameters.is_standalone_mode()
@@ -1876,6 +1877,7 @@ class Superset(BaseSupersetView):  # pylint: 
disable=too-many-public-methods
                 "dash_save_perm": dash_save_perm,
                 "dash_edit_perm": dash_edit_perm,
                 "superset_can_explore": superset_can_explore,
+                "superset_can_share": superset_can_share,
                 "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 0648104..0ed8dde 100644
--- a/tests/security_tests.py
+++ b/tests/security_tests.py
@@ -670,12 +670,14 @@ 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_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)
@@ -868,6 +870,7 @@ 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_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