Swap impersonate to select2 deferred load w/ filter. This adds a 'f_email' filter parameter to the Users api collection -- we should revisit this before the next stable release to decide how we want API filtering to actually work down the road.

This commit is contained in:
Dannon Baker
2013-11-20 16:59:01 -08:00
parent 5b4a8324ce
commit 2a91e276b4
2 changed files with 36 additions and 6 deletions
+3 -1
View File
@@ -14,7 +14,7 @@ log = logging.getLogger( __name__ )
class UserAPIController( BaseAPIController, UsesTagsMixin, CreatesUsersMixin, CreatesApiKeysMixin ):
@web.expose_api
def index( self, trans, deleted='False', **kwd ):
def index( self, trans, deleted='False', f_email=None, **kwd ):
"""
GET /api/users
GET /api/users/deleted
@@ -23,6 +23,8 @@ class UserAPIController( BaseAPIController, UsesTagsMixin, CreatesUsersMixin, Cr
rval = []
query = trans.sa_session.query( trans.app.model.User )
deleted = util.string_as_bool( deleted )
if f_email:
query = query.filter(trans.app.model.User.email.like("%%%s%%" % f_email))
if deleted:
query = query.filter( trans.app.model.User.table.c.deleted == True )
# only admins can see deleted users
+33 -5
View File
@@ -14,11 +14,8 @@
<label>
User to impersonate:
</label>
<select name="email" class='text-and-autocomplete-select'>
%for email in emails:
<option>${email}</option>
%endfor
</select>
<input type="hidden" id="email_select" name="email">
</input>
</div>
<div class="form-row">
<input type="submit" name="impersonate_button" value="Impersonate"/>
@@ -26,4 +23,35 @@
</form>
</div>
</div>
<script type="text/javascript">
/* This should be ripped out and made generic at some point for the
* various API bindings available, and once the API can filter list
* queries (term, below) */
$("#email_select").select2({
placeholder: "Select a user",
ajax: {
url: "/api/users/",
dataType: 'json',
quietMillis: 250,
matcher: function(term, text) { return text.toUpperCase().indexOf(term.toUpperCase())>=0; },
data: function (term) {
return {
f_email: term
};
},
results: function (data) {
var results = [];
$.each(data, function(index, item){
results.push({
id: item.email,
text: item.email
});
});
return {
results: results
};
}
}
});
</script>
%endif