mistercrunch closed pull request #4900: Hide restricted ui elements, remove 
<br> from error message
URL: https://github.com/apache/incubator-superset/pull/4900
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/assets/src/dashboard/components/Controls.jsx 
b/superset/assets/src/dashboard/components/Controls.jsx
index 00cb6d56dc..feacf961ba 100644
--- a/superset/assets/src/dashboard/components/Controls.jsx
+++ b/superset/assets/src/dashboard/components/Controls.jsx
@@ -143,20 +143,22 @@ class Controls extends React.PureComponent {
               />
             }
           />
-          <SaveModal
-            dashboard={dashboard}
-            filters={filters}
-            serialize={serialize}
-            onSave={onSave}
-            css={this.state.css}
-            triggerNode={
-              <MenuItemContent
-                text={saveText}
-                tooltip={t('Save the dashboard')}
-                faIcon="save"
-              />
-            }
-          />
+          {dashboard.dash_save_perm &&
+            <SaveModal
+              dashboard={dashboard}
+              filters={filters}
+              serialize={serialize}
+              onSave={onSave}
+              css={this.state.css}
+              triggerNode={
+                <MenuItemContent
+                  text={saveText}
+                  tooltip={t('Save the dashboard')}
+                  faIcon="save"
+                />
+              }
+            />
+          }
           {editMode &&
             <ActionMenuItem
               text={t('Edit properties')}
diff --git a/superset/assets/src/dashboard/components/SaveModal.jsx 
b/superset/assets/src/dashboard/components/SaveModal.jsx
index da465a0057..a849954bd6 100644
--- a/superset/assets/src/dashboard/components/SaveModal.jsx
+++ b/superset/assets/src/dashboard/components/SaveModal.jsx
@@ -69,7 +69,7 @@ class SaveModal extends React.PureComponent {
       error(error) {
         saveModal.close();
         const errorMsg = getAjaxErrorMsg(error);
-        notify.error(t('Sorry, there was an error saving this dashboard: ') + 
'</ br>' + errorMsg);
+        notify.error(t('Sorry, there was an error saving this dashboard: ') + 
errorMsg);
       },
     });
   }
diff --git a/superset/assets/src/dashboard/components/SliceHeader.jsx 
b/superset/assets/src/dashboard/components/SliceHeader.jsx
index 8abcc86d61..6db9c683c9 100644
--- a/superset/assets/src/dashboard/components/SliceHeader.jsx
+++ b/superset/assets/src/dashboard/components/SliceHeader.jsx
@@ -1,6 +1,7 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 import moment from 'moment';
+import { connect } from 'react-redux';
 
 import { t } from '../../locales';
 import EditableTitle from '../../components/EditableTitle';
@@ -8,6 +9,8 @@ import TooltipWrapper from '../../components/TooltipWrapper';
 
 const propTypes = {
   slice: PropTypes.object.isRequired,
+  supersetCanExplore: PropTypes.bool,
+  sliceCanEdit: PropTypes.bool,
   isExpanded: PropTypes.bool,
   isCached: PropTypes.bool,
   cachedDttm: PropTypes.string,
@@ -72,6 +75,7 @@ class SliceHeader extends React.PureComponent {
               title={slice.slice_name}
               canEdit={!!this.props.updateSliceName && this.props.editMode}
               onSaveTitle={this.onSaveTitle}
+              showTooltip={this.props.editMode}
               noPermitTooltip={'You don\'t have the rights to alter this 
dashboard.'}
             />
             {!!Object.values(this.props.annotationQuery || {}).length &&
@@ -126,15 +130,17 @@ class SliceHeader extends React.PureComponent {
                 </TooltipWrapper>
               </a>
               }
-              <a href={slice.edit_url} target="_blank">
-                <TooltipWrapper
-                  placement="top"
-                  label="edit"
-                  tooltip={t('Edit chart')}
-                >
-                  <i className="fa fa-pencil" />
-                </TooltipWrapper>
-              </a>
+              {this.props.sliceCanEdit &&
+                <a href={slice.edit_url} target="_blank">
+                  <TooltipWrapper
+                    placement="top"
+                    label="edit"
+                    tooltip={t('Edit chart')}
+                  >
+                    <i className="fa fa-pencil" />
+                  </TooltipWrapper>
+                </a>
+              }
               <a className="exportCSV" onClick={this.exportCSV}>
                 <TooltipWrapper
                   placement="top"
@@ -144,15 +150,17 @@ class SliceHeader extends React.PureComponent {
                   <i className="fa fa-table" />
                 </TooltipWrapper>
               </a>
-              <a className="exploreChart" onClick={this.exploreChart}>
-                <TooltipWrapper
-                  placement="top"
-                  label="exploreChart"
-                  tooltip={t('Explore chart')}
-                >
-                  <i className="fa fa-share" />
-                </TooltipWrapper>
-              </a>
+              {this.props.supersetCanExplore &&
+                <a className="exploreChart" onClick={this.exploreChart}>
+                  <TooltipWrapper
+                    placement="top"
+                    label="exploreChart"
+                    tooltip={t('Explore chart')}
+                  >
+                    <i className="fa fa-share" />
+                  </TooltipWrapper>
+                </a>
+              }
               {this.props.editMode &&
                 <a className="remove-chart" onClick={this.removeSlice}>
                   <TooltipWrapper
@@ -175,4 +183,12 @@ class SliceHeader extends React.PureComponent {
 SliceHeader.propTypes = propTypes;
 SliceHeader.defaultProps = defaultProps;
 
-export default SliceHeader;
+function mapStateToProps({ dashboard }) {
+  return {
+    supersetCanExplore: dashboard.dashboard.superset_can_explore,
+    sliceCanEdit: dashboard.dashboard.slice_can_edit,
+  };
+}
+
+export { SliceHeader };
+export default connect(mapStateToProps, () => ({}))(SliceHeader);
diff --git a/superset/views/core.py b/superset/views/core.py
index a79ff2b4da..0359cae739 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -2046,6 +2046,8 @@ def dashboard(**kwargs):  # noqa
         dash_edit_perm = check_ownership(dash, raise_if_false=False)
         dash_save_perm = \
             dash_edit_perm and security_manager.can_access('can_save_dash', 
'Superset')
+        superset_can_explore = security_manager.can_access('can_explore', 
'Superset')
+        slice_can_edit = security_manager.can_access('can_edit', 
'SliceModelView')
 
         standalone_mode = request.args.get('standalone') == 'true'
 
@@ -2054,6 +2056,8 @@ def dashboard(**kwargs):  # noqa
             'standalone_mode': standalone_mode,
             'dash_save_perm': dash_save_perm,
             'dash_edit_perm': dash_edit_perm,
+            'superset_can_explore': superset_can_explore,
+            'slice_can_edit': slice_can_edit,
         })
 
         bootstrap_data = {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to