Skip to content

Commit

Permalink
[bugfix] save dash fails with CSRF related error (apache#2552)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch authored and will7200 committed Apr 14, 2017
1 parent 8daa57f commit 0e5d708
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
7 changes: 4 additions & 3 deletions superset/assets/javascripts/dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,10 @@ export function dashboardContainer(dashboard) {
}

$(document).ready(() => {
// Getting bootstrapped data from the DOM
const dashboardData = $('.dashboard').data('dashboard');
const contextData = $('.dashboard').data('context');
// Getting bootstrapped data from the DOM
utils.initJQueryAjaxCSRF();
const dashboardData = $('.dashboard').data('dashboard');
const contextData = $('.dashboard').data('context');

const state = getInitialState(dashboardData, contextData);
const dashboard = dashboardContainer(state.dashboard);
Expand Down
7 changes: 6 additions & 1 deletion superset/templates/superset/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
<div id="app" data-bootstrap="{{ bootstrap_data }}" >
<img src="/static/assets/images/loading.gif" style="width: 50px; margin: 10px;">
</div>
{{ csrf_token() if csrf_token else None }}
<input
type="hidden"
name="csrf_token"
id="csrf_token"
value="{{ csrf_token() if csrf_token else '' }}"
>
{% endblock %}

<!-- Modal for misc messages / alerts -->
Expand Down
6 changes: 6 additions & 0 deletions superset/templates/superset/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
{% include 'superset/flash_wrapper.html' %}
<div id="root"></div>
</div>
<input
type="hidden"
name="csrf_token"
id="csrf_token"
value="{{ csrf_token() if csrf_token else '' }}"
>
{% endblock %}
3 changes: 0 additions & 3 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2220,11 +2220,8 @@ def sqllab(self):
d = {
'defaultDbId': config.get('SQLLAB_DEFAULT_DBID'),
}
from flask_wtf import FlaskForm
ff = FlaskForm()
return self.render_template(
'superset/sqllab.html',
csrf_token=ff.csrf_token,
bootstrap_data=json.dumps(d, default=utils.json_iso_dttm_ser)
)
appbuilder.add_view_no_menu(Superset)
Expand Down

0 comments on commit 0e5d708

Please sign in to comment.