Skip to content

Commit

Permalink
fix superset error message flow (#5540)
Browse files Browse the repository at this point in the history
  • Loading branch information
timifasubaa authored Aug 1, 2018
1 parent 1a9c459 commit 4bf69a7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion superset/assets/src/SqlLab/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function runQuery(query) {
if (msg.indexOf('CSRF token') > 0) {
msg = COMMON_ERR_MESSAGES.SESSION_TIMED_OUT;
}
dispatch(queryFailed(query, msg, getErrorLink(msg)));
dispatch(queryFailed(query, msg, getErrorLink(err)));
},
});
};
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/src/SqlLab/components/ResultSet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default class ResultSet extends React.PureComponent {
return (
<Alert bsStyle="danger">
{query.errorMessage}
{query.link && <a href={query.link}> {t('(Common errors and their resolutions)')} </a>}
{query.link && <a href={query.link}> {t('(Request Access)')} </a>}
</Alert>);
} else if (query.state === 'success' && query.ctas) {
return (
Expand Down
14 changes: 11 additions & 3 deletions superset/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def get_table_access_error_msg(self, table_name):
return """You need access to the following tables: {}, all database access or
`all_datasource_access` permission""".format(table_name)

def get_table_access_link(self, tables):
from superset import conf
return conf.get('PERMISSION_INSTRUCTIONS_LINK')

def datasource_access_by_name(
self, database, datasource_name, schema=None):
from superset import db
Expand All @@ -147,15 +151,19 @@ def datasource_access_by_name(
return True
return False

def datasource_access_by_fullname(
self, database, full_table_name, schema):
table_name_pieces = full_table_name.split('.')
def get_schema_and_table(self, table_in_query, schema):
table_name_pieces = table_in_query.split('.')
if len(table_name_pieces) == 2:
table_schema = table_name_pieces[0]
table_name = table_name_pieces[1]
else:
table_schema = schema
table_name = table_name_pieces[0]
return (table_schema, table_name)

def datasource_access_by_fullname(
self, database, table_in_query, schema):
table_schema, table_name = self.get_schema_and_table(table_in_query, schema)
return self.datasource_access_by_name(
database, table_name, schema=table_schema)

Expand Down
5 changes: 3 additions & 2 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def json_error_response(msg=None, status=500, stacktrace=None, payload=None, lin
payload = {'error': str(msg)}
if stacktrace:
payload['stacktrace'] = stacktrace
if link:
payload['link'] = link
if link:
payload['link'] = link

return Response(
json.dumps(payload, default=utils.json_iso_dttm_ser),
status=status, mimetype='application/json')
Expand Down
5 changes: 2 additions & 3 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2426,9 +2426,8 @@ def sql_json(self):
rejected_tables = security_manager.rejected_datasources(sql, mydb, schema)
if rejected_tables:
return json_error_response(
security_manager.get_datasource_access_error_msg('{}'.format(
rejected_tables)),
link=security_manager.get_table_error_link(rejected_tables))
security_manager.get_table_access_error_msg(rejected_tables),
link=security_manager.get_table_access_link(rejected_tables))
session.commit()

select_as_cta = request.form.get('select_as_cta') == 'true'
Expand Down

0 comments on commit 4bf69a7

Please sign in to comment.