Skip to content

Commit

Permalink
Add permission checks to save_or_overwrite_slice (#4346)
Browse files Browse the repository at this point in the history
* Add permissions checks for save_or_overwrite_slice

* Change is_owner to check_ownership

* Add translation to chart and dashboard error messages

* Appease the python linter by using single quotes
  • Loading branch information
Jay Lindquist authored and mistercrunch committed Feb 9, 2018
1 parent 5ab4915 commit 54d3875
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,12 @@ def explore(self, datasource_type, datasource_id):

if action == 'overwrite' and not slice_overwrite_perm:
return json_error_response(
"You don't have the rights to alter this slice",
_('You don\'t have the rights to ') + _('alter this ') + _('chart'),
status=400)

if action == 'saveas' and not slice_add_perm:
return json_error_response(
_('You don\'t have the rights to ') + _('create a ') + _('chart'),
status=400)

if action in ('saveas', 'overwrite'):
Expand Down Expand Up @@ -1300,12 +1305,28 @@ def save_or_overwrite_slice(
.filter_by(id=int(request.args.get('save_to_dashboard_id')))
.one()
)

# check edit dashboard permissions
dash_overwrite_perm = check_ownership(dash, raise_if_false=False)
if not dash_overwrite_perm:
return json_error_response(
_('You don\'t have the rights to ') + _('alter this ') +
_('dashboard'),
status=400)

flash(
'Slice [{}] was added to dashboard [{}]'.format(
slc.slice_name,
dash.dashboard_title),
'info')
elif request.args.get('add_to_dash') == 'new':
# check create dashboard permissions
dash_add_perm = self.can_access('can_add', 'DashboardModelView')
if not dash_add_perm:
return json_error_response(
_('You don\'t have the rights to ') + _('create a ') + _('dashboard'),
status=400)

dash = models.Dashboard(
dashboard_title=request.args.get('new_dashboard_name'),
owners=[g.user] if g.user else [])
Expand Down

0 comments on commit 54d3875

Please sign in to comment.