Impersonation refactoring, condense functionality into user grid, optimize some stuff.

This commit is contained in:
Dannon Baker
2018-05-18 14:26:13 -04:00
parent 96b4532e99
commit 3bd8b3b18b
4 changed files with 13 additions and 86 deletions
@@ -82,12 +82,6 @@ var AdminPanel = Backbone.View.extend({
url: "admin/api_keys",
target: "__use_router__",
id: "admin-link-api-keys"
},
{
title: _l("Impersonate a user"),
url: "admin/impersonate",
enabled: self.config.allow_user_impersonation,
id: "admin-link-impersonate"
}
]
},
+12 -16
View File
@@ -796,27 +796,23 @@ class AdminGalaxy(controller.JSAppLauncher, AdminActions, UsesQuotaMixin, QuotaP
@web.expose
@web.require_admin
def impersonate(self, trans, email=None, **kwd):
def impersonate(self, trans, **kwd):
if not trans.app.config.allow_user_impersonation:
return trans.show_error_message("User impersonation is not enabled in this instance of Galaxy.")
message = ''
status = 'done'
show_emails = True
user = None
user_id = kwd.get('id', None)
if user_id is not None:
user = trans.sa_session.query(trans.app.model.User).get(trans.security.decode_id(user_id))
elif email is not None:
user = trans.sa_session.query(trans.app.model.User).filter_by(email=email).first()
if user:
trans.handle_user_logout()
trans.handle_user_login(user)
message = 'You are now logged in as %s, <a target="_top" href="%s">return to the home page</a>' % (user.email, url_for(controller='root'))
show_emails = False
elif user_id or email:
message = 'Invalid user selected'
status = 'error'
return trans.fill_template('admin/impersonate.mako', show_emails=show_emails, message=message, status=status)
try:
user = trans.sa_session.query(trans.app.model.User).get(trans.security.decode_id(user_id))
if user:
trans.handle_user_logout()
trans.handle_user_login(user)
return trans.show_message('You are now logged in as %s, <a target="_top" href="%s">return to the home page</a>' % (user.email, url_for(controller='root')), use_panels=True)
except Exception:
log.exception("Error fetching user for impersonation")
return trans.response.send_redirect(web.url_for(controller='admin',
action='users',
message="Invalid user selected", status="error"))
def check_for_tool_dependencies(self, trans, migration_stage):
# Get the 000x_tools.xml file associated with migration_stage.
-58
View File
@@ -1,58 +0,0 @@
<%inherit file="/base.mako"/>
<%namespace file="/message.mako" import="render_msg" />
%if message:
${render_msg( message, status )}
%endif
%if show_emails:
<div class="toolForm">
<div class="toolFormTitle">Impersonate another user</div>
<div class="toolFormBody">
<form name="impersonate" id="impersonate" action="${h.url_for( controller='admin', action='impersonate' )}" method="post" >
<div class="form-row">
<label>
User to impersonate:
</label>
<input type="hidden" id="email_select" name="email">
</input>
</div>
<div class="form-row">
<input type="submit" name="impersonate_button" value="Impersonate"/>
</div>
</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",
width: "33%",
ajax: {
url: "${h.url_for(controller="/api/users", action="index")}",
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.username + " : " + item.email
});
});
return {
results: results
};
}
}
});
</script>
%endif
+1 -6
View File
@@ -30,7 +30,7 @@ Please visit <a href="https://galaxyproject.org/admin" target="_blank">the Galax
<h4>User Management</h4>
<ul>
<li>
<strong>Users</strong> - A view of all users and all groups and non-private roles associated with each user.
<strong>Users</strong> - The primary user management interface, displaying information associated with each user and providing operations for resetting passwords, updating user information, impersonating a user, and more.
</li>
%if trans.app.config.enable_quotas:
<li>
@@ -50,11 +50,6 @@ Please visit <a href="https://galaxyproject.org/admin" target="_blank">the Galax
<li>
<strong>API keys</strong> - A view of all generated API keys with an option to re-generate.
</li>
%if trans.app.config.allow_user_impersonation:
<li>
<strong>Impersonate a user</strong> - Allows to view Galaxy as another user in order to help troubleshoot issues.
</li>
%endif
</ul>
<h4>Tool Management</h4>