You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2018/03/20 05:16:19 UTC
[incubator-superset] branch master updated: [sql lab] search to use
fist&last name instead of username (#4628)
This is an automated email from the ASF dual-hosted git repository.
maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new fc47729 [sql lab] search to use fist&last name instead of username (#4628)
fc47729 is described below
commit fc47729233e7ce44e225edbeb628f6a5f0376eda
Author: Maxime Beauchemin <ma...@gmail.com>
AuthorDate: Mon Mar 19 22:16:17 2018 -0700
[sql lab] search to use fist&last name instead of username (#4628)
In our environment username are not readable coming out of oauth, so
we'd rather use first&last when available.
---
.../javascripts/SqlLab/components/QuerySearch.jsx | 39 ++++++++++++++++------
superset/models/sql_lab.py | 4 +--
superset/utils.py | 9 +++++
3 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx b/superset/assets/javascripts/SqlLab/components/QuerySearch.jsx
index 10c1c88..a3e4bf4 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}
/>
</div>
<div className="col-sm-2">
<AsyncSelect
- onChange={this.onChange.bind(this)}
+ onChange={this.onChange}
dataEndpoint="/databaseasync/api/read?_flt_0_expose_in_sqllab=1"
value={this.state.databaseId}
- mutator={this.dbMutator.bind(this)}
+ mutator={this.dbMutator}
/>
</div>
<div className="col-sm-4">
<input
type="text"
- onChange={this.changeSearch.bind(this)}
+ onChange={this.changeSearch}
className="form-control input-sm"
placeholder={t('Search Results')}
/>
@@ -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}
/>
<Select
@@ -171,7 +188,7 @@ class QuerySearch extends React.PureComponent {
options={TIME_OPTIONS.map(xt => ({ value: xt, label: xt }))}
value={this.state.to}
autosize={false}
- onChange={this.changeTo.bind(this)}
+ onChange={this.changeTo}
/>
<Select
@@ -181,10 +198,10 @@ class QuerySearch extends React.PureComponent {
value={this.state.status}
isLoading={false}
autosize={false}
- onChange={this.changeStatus.bind(this)}
+ onChange={this.changeStatus}
/>
- <Button bsSize="small" bsStyle="success" onClick={this.refreshQueries.bind(this)}>
+ <Button bsSize="small" bsStyle="success" onClick={this.refreshQueries}>
{t('Search')}
</Button>
</div>
@@ -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 bf37db7..81ee41a 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 bb43edc..78fb12b 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
--
To stop receiving notification emails like this one, please contact
maximebeauchemin@apache.org.