Skip to content

Commit

Permalink
dashboard: don't enable buttons that would fail (#881)
Browse files Browse the repository at this point in the history
With gamma users saving the dashboard model would fail if they
are not owner of the dashboard.
So if that's not the case just disable the "Add a new slice to
the dashboard" and "Save the current positioning and CSS".

Refs #359
  • Loading branch information
xrmx authored and mistercrunch committed Aug 11, 2016
1 parent 9b3b1f6 commit 71bdabe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion caravel/templates/caravel/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h2>{{ dashboard.dashboard_title }}</h2>
<button type="button" id="refresh_dash" class="btn btn-default" data-toggle="tooltip" title="Force refresh the whole dashboard">
<i class="fa fa-refresh"></i>
</button>
<button type="button" id="add-slice" class="btn btn-default" data-toggle="modal" data-target="#add_slice_modal">
<button type="button" id="add-slice" class="btn btn-default {{ "disabled disabledButton" if not dash_save_perm }}" data-toggle="modal" data-target="#add_slice_modal">
<i class="fa fa-plus" data-toggle="tooltip" title="Add a new slice to the dashboard"></i>
</button>
<button type="button" id="refresh_dash_periodic" class="btn btn-default" data-toggle="modal" data-target="#refresh_modal">
Expand Down
7 changes: 4 additions & 3 deletions caravel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,13 +1165,14 @@ def dashboard(self, dashboard_id):
def dashboard(**kwargs): # noqa
pass
dashboard(dashboard_id=dash.id)

dash_edit_perm = check_ownership(dash, raise_if_false=False)
dash_save_perm = dash_edit_perm and self.can_access('can_save_dash', 'Caravel')
return self.render_template(
"caravel/dashboard.html", dashboard=dash,
user_id=g.user.get_id(),
templates=templates,
dash_save_perm=self.can_access('can_save_dash', 'Caravel'),
dash_edit_perm=check_ownership(dash, raise_if_false=False))
dash_save_perm=dash_save_perm,
dash_edit_perm=dash_edit_perm)

@has_access
@expose("/sql/<database_id>/")
Expand Down

0 comments on commit 71bdabe

Please sign in to comment.