diff --git a/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx b/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx
index 10c1c88e79..a3e4bf4dfd 100644
--- a/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx
+++ b/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx
@@ -31,6 +31,17 @@ class QuerySearch extends React.PureComponent {
queriesArray: [],
queriesLoading: true,
};
+ this.userMutator = this.userMutator.bind(this);
+ this.changeUser = this.changeUser.bind(this);
+ this.dbMutator = this.dbMutator.bind(this);
+ this.onChange = this.onChange.bind(this);
+ this.changeSearch = this.changeSearch.bind(this);
+ this.changeFrom = this.changeFrom.bind(this);
+ this.changeTo = this.changeTo.bind(this);
+ this.changeStatus = this.changeStatus.bind(this);
+ this.refreshQueries = this.refreshQueries.bind(this);
+ this.onUserClicked = this.onUserClicked.bind(this);
+ this.onDbClicked = this.onDbClicked.bind(this);
}
componentDidMount() {
this.refreshQueries();
@@ -90,10 +101,16 @@ class QuerySearch extends React.PureComponent {
changeSearch(event) {
this.setState({ searchText: event.target.value });
}
+ userLabel(user) {
+ if (user.first_name && user.last_name) {
+ return user.first_name + ' ' + user.last_name;
+ }
+ return user.username;
+ }
userMutator(data) {
const options = [];
for (let i = 0; i < data.pks.length; i++) {
- options.push({ value: data.pks[i], label: data.result[i].username });
+ options.push({ value: data.pks[i], label: this.userLabel(data.result[i]) });
}
return options;
}
@@ -135,21 +152,21 @@ class QuerySearch extends React.PureComponent {
dataEndpoint="/users/api/read"
mutator={this.userMutator}
value={this.state.userId}
- onChange={this.changeUser.bind(this)}
+ onChange={this.changeUser}
/>
@@ -162,7 +179,7 @@ class QuerySearch extends React.PureComponent {
.slice(1, TIME_OPTIONS.length).map(xt => ({ value: xt, label: xt }))}
value={this.state.from}
autosize={false}
- onChange={this.changeFrom.bind(this)}
+ onChange={this.changeFrom}
/>
@@ -203,8 +220,8 @@ class QuerySearch extends React.PureComponent {
'state', 'db', 'user', 'time',
'progress', 'rows', 'sql', 'querylink',
]}
- onUserClicked={this.onUserClicked.bind(this)}
- onDbClicked={this.onDbClicked.bind(this)}
+ onUserClicked={this.onUserClicked}
+ onDbClicked={this.onDbClicked}
queries={this.state.queriesArray}
actions={this.props.actions}
/>
diff --git a/superset/models/sql_lab.py b/superset/models/sql_lab.py
index bf37db75f6..81ee41a160 100644
--- a/superset/models/sql_lab.py
+++ b/superset/models/sql_lab.py
@@ -19,7 +19,7 @@ from sqlalchemy.orm import backref, relationship
from superset import sm
from superset.models.helpers import AuditMixinNullable
-from superset.utils import QueryStatus
+from superset.utils import QueryStatus, user_label
install_aliases()
@@ -109,7 +109,7 @@ class Query(Model):
'tab': self.tab_name,
'tempTable': self.tmp_table_name,
'userId': self.user_id,
- 'user': self.user.username,
+ 'user': user_label(self.user),
'limit_reached': self.limit_reached,
'resultsKey': self.results_key,
'trackingUrl': self.tracking_url,
diff --git a/superset/utils.py b/superset/utils.py
index bb43edcf1b..78fb12b669 100644
--- a/superset/utils.py
+++ b/superset/utils.py
@@ -825,3 +825,12 @@ def merge_request_params(form_data, params):
def get_update_perms_flag():
val = os.environ.get('SUPERSET_UPDATE_PERMS')
return val.lower() not in ('0', 'false', 'no') if val else True
+
+
+def user_label(user):
+ """Given a user ORM FAB object, returns a label"""
+ if user:
+ if user.first_name and user.last_name:
+ return user.first_name + ' ' + user.last_name
+ else:
+ return user.username